Shopify temanıza adet kuralları ekleme

B2B kataloğuyla ilgili adet kuralları yalnızca ücretsiz Shopify temalarının 8.0.0 sürümünde veya sonraki sürümlerde desteklenir. Temanızı değiştirmek veya güncellemek istemiyorsanız adet kurallarını göstermek için temanıza aşağıdaki kodu ekleyebilirsiniz.

Ürün sepetindeki adet

Ürün varyasyonunun sepet adedi değeri, ürün sayfasında veya öne çıkan ürün bölümünde görüntülenebilir. Bu değer Liquid kullanılarak alınabilir.

Liquid ürün sepeti adet kodu ekleme

Sepet adedini desteklemek için temanızdaki aşağıdaki dosyalara kod ekleyebilirsiniz:

  • main-product.liquid veya eş değeri
  • featured-product.liquid veya eş değeri

Adımlar:

  1. Düzenlemek istediğiniz dosyayı açın.
  2. Dosyanın altında yeni bir satır oluşturun ve aşağıdaki kodu ekleyin:
{% comment %} Cart quantity {% endcomment %}
<span id="CartQuantity-{{ section.id }}" data-product-url="{{ product.url }}" data-section-id="{{ section.id }}" data-variant-id="{{ product.selected_or_first_available_variant.id }}">
    {%- assign cart_qty = cart | item_count_for_variant: product.selected_or_first_available_variant.id -%}
    {{- 'products.product.quantity.in_cart' | t: quantity: cart_qty -}}
</span>
  1. Kayıtyap ' a tıklayın.

Javascript sepet adedi kodu ekleme

Bir varyasyonun sepet adedi değiştiğinde ürün sayfasında gösterilen değer veya öne çıkarılan ürün bölümü güncellenmelidir. Güncellenen değer, Javascript kodu kullanılarak alınabilir.

theme.js veya eş değer bir dosyaya kodu ekleyebilirsiniz.

Adımlar:

  1. theme.js dosyasını açın.
  2. Dosyanın altında yeni bir satır oluşturun ve aşağıdaki kodu ekleyin:
let productUrl = document.querySelector('[data-product-url]').dataset.productUrl;
let sectionId = document.querySelector('[data-section-id]').dataset.sectionId;
let variantId = document.querySelector('[data-variant-id]').dataset.variantId;

// Fetch updated HTML from Section Rendering API
fetch(`${productUrl}?section_id=${sectionId}&variant=${variantId}`)
    .then((response) => response.text())
    .then((responseText) => {
        // Replace the current HTML in DOM with the updated HTML

        const updatedHtml = new DOMParser().parseFromString(responseText, 'text/html');

        // Update the cart quantity
        const currentCartQuantity = document.querySelector(`#CartQuantity-${sectionId}`);
        const updatedCartQuantity = updatedHtml.querySelector(`#CartQuantity-${sectionId}`);
        currentCartQuantity.innerHTML = updatedCartQuantity.innerHTML;
    });
  1. Kayıtyap ' a tıklayın.

Adet kuralları

Ürün varyasyonunun adet kuralları, ürün sayfasında veya öne çıkan ürün bölümünde görüntülenebilir. Kurallar Liquid kullanılarak alınabilir.

Liquid adet kuralları kodu ekleme

Ürün sepeti adedini desteklemek için temanızdaki aşağıdaki dosyalara kod ekleyebilirsiniz:

  • main-product.liquid veya eş değeri
  • featured-product.liquid veya eş değeri

Adımlar:

  1. Düzenlemek istediğiniz dosyayı açın.
  2. Dosyanın altında yeni bir satır oluşturun ve ardından aşağıdaki kodu ekleyin:
{% comment %} Quantity rules {% endcomment %}
<div id="QuantityRules-{{ section.id }}" data-product-url="{{ product.url }}" data-section-id="{{ section.id }}" data-variant-id="{{ product.selected_or_first_available_variant.id }}">
    {%- if product.selected_or_first_available_variant.quantity_rule.increment > 1 -%}
        <span>
        {{- 'products.product.quantity.multiples_of' | t: quantity: product.selected_or_first_available_variant.quantity_rule.increment -}}
        </span>
    {%- endif -%}
    {%- if product.selected_or_first_available_variant.quantity_rule.min > 1 -%}
        <span>
        &nbsp;-&nbsp;
        {{- 'products.product.quantity.minimum_of' | t: quantity: product.selected_or_first_available_variant.quantity_rule.min -}}
        </span>
    {%- endif -%}
    {%- if product.selected_or_first_available_variant.quantity_rule.max != null -%}
        <span>
        &nbsp;-&nbsp;
        {{- 'products.product.quantity.maximum_of' | t: quantity: product.selected_or_first_available_variant.quantity_rule.max -}}
        </span>
    {%- endif -%}
</div>
  1. Kayıtyap ' a tıklayın.

Javascript adet kuralları kodunu ekleme

Bir ürünün her varyasyonu kendi adet kurallarına sahip olabilir. Farklı bir varyasyon seçildikten sonra ürün sayfasında veya önerilen ürün bölümünde gösterilen adet kuralları güncellenmelidir. Güncellenen değer, Javascript kodu kullanılarak alınabilir.

  • theme.js veya eş değeri
  • en.default.json

Adımlar:

  1. theme.js dosyasını açın.
  2. Dosyanın altında yeni bir satır oluşturun ve ardından aşağıdaki kodu ekleyin:
let productUrl = document.querySelector('[data-product-url]').dataset.productUrl;
let sectionId = document.querySelector('[data-section-id]').dataset.sectionId;
let variantId = document.querySelector('[data-variant-id]').dataset.variantId;
// `variantId` is set to the current variant's id. Replace this value with the updated variant's id

// Fetch updated HTML from Section Rendering API
fetch(`${productUrl}?section_id=${sectionId}&variant=${variantId}`)
    .then((response) => response.text())
    .then((responseText) => {
        // Replace the current HTML in DOM with the updated HTML

        const updatedHtml = new DOMParser().parseFromString(responseText, 'text/html');

        // Update the quantity rules
        const currentQuantityRules = document.querySelector(`#QuantityRules-${sectionId}`);
        const updatedQuantityRules = updatedHtml.querySelector(`#QuantityRules-${sectionId}`);
        currentQuantityRules.innerHTML = updatedQuantityRules.innerHTML;
    });
  1. Kaydet'e tıklayın.

Yerel ayarlar ekleme

JSON çeviri dizeleri ekleme

Adımlar:

  1. en.default.json dosyasını açın.
  2. Dosyanın altında yeni bir satır oluşturun ve ardından aşağıdaki kodu ekleyin:
{
   "products":{
      "quantity":{
         "minimum_of":"Minimum of ",
         "maximum_of":"Maximum of ",
         "multiples_of":"Increments of ",
         "in_cart": " in cart"
      }
   }
}
  1. Kayıtyap ' a tıklayın.

Shopify ile satış yapmaya hazır mısınız?

Ücretsiz olarak dene