Как обновить <span> в jQuery (функция Shopify Quickview)

Я хочу добавить базовую цену к функции Quickview в Shopify, но я не могу все исправить с помощью jquery. Я хочу рассчитать basePase на основе productPrice. Проблема в том, что расчет не отображается в HTML. Кажется, что-то мне не хватает. все еще пусто. В другом контексте (Shopify Liquid Code) эта модификация была довольно простой. Здесь вроде бы сложнее. Есть ли у кого-нибудь идея / решение для этого? Спасибо за вашу помощь!

  Shopify.doNotTriggerClickOnThumb = false; 
                                       
  var selectCallbackQuickview = function(variant, selector) {
      var productItem = jQuery('.quick-view .product-item');
          addToCart = productItem.find('.add-to-cart-btn'),
          productPrice = productItem.find('.price'),
          comparePrice = productItem.find('.compare-price'),
          basePrice = productItem.find('.base-price'),
          totalPrice = productItem.find('.total-price span');           
      
    
        // Regardless of stock, update the product price
        productPrice.html(Shopify.formatMoney(variant.price, "{{ shop.money_format }}"));
    
        // Also update and show the product's compare price if necessary
        if ( variant.compare_at_price > variant.price ) {
          comparePrice
            .html(Shopify.formatMoney(variant.compare_at_price, "{{ shop.money_format }}"))
            .show();
          productPrice.addClass('on-sale');
        } else {
          comparePrice.hide();
          productPrice.removeClass('on-sale');
        }
       
       BASEPRICE IS CALCULATED HERE:
       if ( productPrice > 20 ){
        if ( productPrice > 90) {
        basePrice = productPrice / 75 / 12 * 100;
        }
        basePrice = productPrice / 75 / 6 * 100;
       else {
          basePrice = productPrice / 75 * 100;
        }
    
      /*recaculate total price*/
        //try pattern one before pattern 2
        var regex = /([0-9]+[.|,][0-9]+[.|,][0-9]+)/g;
        var unitPriceTextMatch = jQuery('.quick-view .price').text().match(regex);

        if (!unitPriceTextMatch) {
          regex = /([0-9]+[.|,][0-9]+)/g;
          unitPriceTextMatch = jQuery('.quick-view .price').text().match(regex);     
        }

        if (unitPriceTextMatch) {
          var unitPriceText = unitPriceTextMatch[0];     
          var unitPrice = unitPriceText.replace(/[.|,]/g,'');
          var quantity = parseInt(jQuery('.quick-view input[name=quantity]').val());
          var totalPrice = unitPrice * quantity;

          var totalPriceText = Shopify.formatMoney(totalPrice, window.money_format);
          regex = /([0-9]+[.|,][0-9]+[.|,][0-9]+)/g;     
          if (!totalPriceText.match(regex)) {
            regex = /([0-9]+[.|,][0-9]+)/g;
          } 
          totalPriceText = totalPriceText.match(regex)[0];

          var regInput = new RegExp(unitPriceText, "g"); 
          var totalPriceHtml = jQuery('.quick-view .price').html().replace(regInput ,totalPriceText);
          jQuery('.quick-view .total-price span').html(totalPriceHtml);     
        }
    /*end of price calculation*/

  };
            <div class = "prices">
              <span class = "compare-price"></span>
              <span class = "price"></span>
              <span class = "base-price">BASEPRICE SHOULD BE SEEN HERE</span>
</div>

какова базовая цена? Большинство магазинов придерживаются только цены и, возможно, сокращенного сравнения по цене, если они хотят создать иллюзию какой-то сделки.

David Lazar 05.09.2018 22:55

Если вы продаете бутылку вина (в ней часто бывает 0,75 л) - Базовая цена - это цена за 1 л - В ЕС вы должны предоставить покупателю возможность сравнить цены с «базовой ценой». Так что все виды бутылок 0,75, 0,5 л можно легко сравнить. Базовая цена = Стоимость 1 литра продукта. - Я реализовал его на всех сайтах, но теперь я также хочу использовать его в функции быстрого просмотра продуктов, где я не могу использовать Liquid Code :) Я новичок в jQuery: D

D.D. 05.09.2018 23:28
Как конвертировать HTML в PDF с помощью jsPDF
Как конвертировать HTML в PDF с помощью jsPDF
В этой статье мы рассмотрим, как конвертировать HTML в PDF с помощью jsPDF. Здесь мы узнаем, как конвертировать HTML в PDF с помощью javascript.
0
2
253
1

Ответы 1

Вы должны уметь:

$('.base-price').text(basePrice);

Это найдет элемент (ы) с именем класса 'base-price' и установит текст в значение basePrice.

Другие вопросы по теме