הצגת כללי כמות ותמחור לפי נפח בחנות שלך
באפשרותך להציג כללי כמות ותמחור לפי נפח עבור קטלוג B2B בחנות שלך על ידי עדכון ערכת הנושא של החנות שלך לגרסה העדכנית ביותר.
אם אינך רוצה לשנות או לעדכן את ערכת הנושא שלך, תוכל להוסיף את הקוד הבא לערכת הנושא כדי להציג כללי כמות ותמחור לפי נפח.
בדף זה
שיקולים להוספת כללי כמות ותמחור לפי נפח לקוד ערכת הנושא שלך
לפני הוספת כללי כמות ותמחור לפי נפח לקוד ערכת הנושא שלך, עיין בשיקולים הבאים:
- זהו מדריך למתקדמים. אם אינך חש בנוח עם קריאה ועריכה של קוד ערכת נושא, תוכל לעבוד עם מפתח או לשכור את שירותיו של שותף Shopify.
- לפני ביצוע עדכונים בקובצי ערכת הנושא, ודא שאתה משכפל את ערכת הנושא שלך כדי ליצור עותק גיבוי.
- כללי כמות עבור קטלוג B2B נתמכים בערכות נושא חינמיות של Shopify, גרסה 8.0.0 ומעלה. תמחור לפי נפח נתמך בגרסה 11.0.0 ומעלה.
כמות המוצר בסל
ניתן להציג את ערך הכמות בסל של וריאנט מוצר בדף המוצר או במקטע של מוצר נבחר. ניתן לשלוף את הערך באמצעות Liquid.
הוספת קוד Liquid לכמות המוצר בסל
באפשרותך להוסיף קוד לקבצים הבאים בערכת הנושא שלך כדי לתמוך בכמות בסל:
main-product.liquidאו קובץ מקבילfeatured-product.liquidאו קובץ מקביל
שלבים:
ממנהל Shopify שלך, עבור אל חנות מקוונת > ערכות נושא.
מצא את ערכת הנושא שברצונך לערוך, לחץ על הלחצן ... כדי לפתוח את תפריט הפעולות, ולאחר מכן לחץ על עריכת קוד.
פתח את הקובץ שברצונך לערוך.
צור שורה חדשה בתחתית הקובץ והוסף את הקוד הבא:
{% 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 }}">
{{ cart | line_items_for: product | sum: 'quantity' }}
{{- 'products.product.quantity.in_cart' | t: quantity: cart_qty -}}
</span>- לחץ על שמירה.
הוספת קוד Javascript לכמות בסל
כאשר הכמות בסל של וריאנט משתנה, יש לעדכן את הערך המוצג בדף המוצר או במקטע מוצר נבחר. ניתן לשלוף את הערך המעודכן באמצעות קוד Javascript.
באפשרותך להוסיף קוד לקובץ theme.js או לקובץ מקביל.
שלבים:
ממנהל Shopify שלך, עבור אל חנות מקוונת > ערכות נושא.
מצא את ערכת הנושא שברצונך לערוך, לחץ על הלחצן ... כדי לפתוח את תפריט הפעולות, ולאחר מכן לחץ על עריכת קוד.
פתח את הקובץ
theme.js.צור שורה חדשה בתחתית הקובץ והוסף את הקוד הבא:
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;
});- לחץ על שמירה.
כללי כמות
ניתן להציג את כללי הכמות של וריאנט מוצר בדף המוצר או במקטע של מוצר נבחר. ניתן לשלוף את הכללים באמצעות Liquid.
הוספת קוד Liquid לכללי כמות
באפשרותך להוסיף קוד לקבצים הבאים בערכת הנושא שלך כדי לתמוך בכללי כמות:
main-product.liquidאו קובץ מקבילfeatured-product.liquidאו קובץ מקביל
שלבים:
ממנהל Shopify שלך, עבור אל חנות מקוונת > ערכות נושא.
מצא את ערכת הנושא שברצונך לערוך, לחץ על הלחצן ... כדי לפתוח את תפריט הפעולות, ולאחר מכן לחץ על עריכת קוד.
פתח את הקובץ שברצונך לערוך.
צור שורה חדשה בתחתית הקובץ, ולאחר מכן הוסף את הקוד הבא:
{% 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>
-
{{- '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>
-
{{- 'products.product.quantity.maximum_of' | t: quantity: product.selected_or_first_available_variant.quantity_rule.max -}}
</span>
{%- endif -%}
</div>- לחץ על שמירה.
הוספת קוד Javascript של כללי כמות
לכל גרסה של מוצר יכול להיות סט משלה של כללי כמות. לאחר בחירת גרסה אחרת, יש לעדכן את כללי הכמות המוצגים בדף המוצר או במקטע המוצר הנבחר. ניתן לשלוף את הערך המעודכן באמצעות קוד Javascript.
theme.jsאו שווה ערךen.default.json
שלבים:
ממנהל Shopify שלך, עבור אל חנות מקוונת > ערכות נושא.
מצא את ערכת הנושא שברצונך לערוך, לחץ על הלחצן ... כדי לפתוח את תפריט הפעולות, ולאחר מכן לחץ על עריכת קוד.
פתח את הקובץ
theme.js.צור שורה חדשה בתחתית הקובץ, ולאחר מכן הוסף את הקוד הבא:
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;
});- לחץ על שמירה.
תמחור לפי נפח
הוספת קוד Liquid של תמחור לפי נפח
באפשרותך להוסיף קוד לקבצים הבאים בערכת הנושא שלך כדי להציג תמחור לפי נפח:
main-product.liquidאו קובץ מקבילfeatured-product.liquidאו קובץ מקביל
שלבים:
ממנהל Shopify שלך, עבור אל חנות מקוונת > ערכות נושא.
מצא את ערכת הנושא שברצונך לערוך, לחץ על הלחצן ... כדי לפתוח את תפריט הפעולות, ולאחר מכן לחץ על עריכת קוד.
פתח את הקובץ שברצונך לערוך.
צור שורה חדשה בתחתית הקובץ, ולאחר מכן הוסף את הקוד הבא:
{%- if product.quantity_price_breaks_configured? -%}
<div class="volume-pricing-note">
<span>{{ 'products.product.volume_pricing.note' | t }}</span>
</div>
<volume-pricing class="parent-display" id="Volume-{{ section.id }}">
{%- if product.selected_or_first_available_variant.quantity_price_breaks.size > 0 -%}
<span class="caption-large">{{ 'products.product.volume_pricing.title' | t }}</span>
<ul class="list-unstyled no-js-hidden">
<li>
<span>{{ product.selected_or_first_available_variant.quantity_rule.min }}+</span>
{%- assign price = product.selected_or_first_available_variant.price
| money_with_currency
-%}
<span data-text="{{ 'products.product.volume_pricing.price_at_each' | t: price: variant_price }}">
{{ 'sections.quick_order_list.each' | t: money: price -}}
</span>
</li>
{%- for price_break in product.selected_or_first_available_variant.quantity_price_breaks -%}
{%- assign price_break_price = price_break.price | money_with_currency -%}
<li class="{%- if forloop.index >= 3 -%}show-more-item hidden{%- endif -%}">
<span>
{{- price_break.minimum_quantity -}}
<span aria-hidden="true">+</span></span
>
{%- assign price = price_break.price | money_with_currency -%}
<span data-text="{{ 'products.product.volume_pricing.price_at_each' | t: price: price_break_price }}">
{{ 'sections.quick_order_list.each' | t: money: price -}}
</span>
</li>
{%- endfor -%}
</ul>
{%- if product.selected_or_first_available_variant.quantity_price_breaks.size >= 3 -%}
<show-more-button>
<button
class="button-show-more link underlined-link no-js-hidden"
id="Show-More-{{ section.id }}"
type="button"
>
<span class="label-show-more label-text"
><span aria-hidden="true">+ </span>{{ 'products.facets.show_more' | t }}
</span>
</button>
</show-more-button>
{%- endif -%}
{%- endif -%}
</volume-pricing>
{%- endif -%}- לחץ על שמירה.
הוספת קוד Javascript של תמחור לפי נפח
באפשרותך להוסיף קוד לקובץ הבא בערכת הנושא שלך כדי להציג תמחור לפי נפח:
theme.js
שלבים:
ממנהל Shopify שלך, עבור אל חנות מקוונת > ערכות נושא.
מצא את ערכת הנושא שברצונך לערוך, לחץ על הלחצן ... כדי לפתוח את תפריט הפעולות, ולאחר מכן לחץ על עריכת קוד.
פתח את הקובץ
theme.js.צור שורה חדשה בתחתית הקובץ, ולאחר מכן הוסף את הקוד הבא:
if (!customElements.get('show-more-button')) {
customElements.define(
'show-more-button',
class ShowMoreButton extends HTMLElement {
constructor() {
super();
const button = this.querySelector('button');
button.addEventListener('click', (event) => {
this.expandShowMore(event);
const nextElementToFocus = event.target
.closest('.parent-display')
.querySelector('.show-more-item');
if (
nextElementToFocus &&
!nextElementToFocus.classList.contains('hidden') &&
nextElementToFocus.querySelector('input')
) {
nextElementToFocus.querySelector('input').focus();
}
});
}
expandShowMore(event) {
const parentDisplay = event.target
.closest('[id^="Show-More-"]')
.closest('.parent-display');
const parentWrap = parentDisplay.querySelector('.parent-wrap');
this.querySelectorAll('.label-text').forEach((element) =>
element.classList.toggle('hidden'),
);
parentDisplay
.querySelectorAll('.show-more-item')
.forEach((item) => item.classList.toggle('hidden'));
if (!this.querySelector('.label-show-less')) {
this.classList.add('hidden');
}
}
},
);
}- לחץ על שמירה.
הוספת הגדרות אזוריות
כדי להבטיח שכללי הכמות והתמחור לפי נפח יוצגו בכל הגרסאות המתורגמות של החנות המקוונת שלך, באפשרותך להוסיף הגדרות אזוריות על ידי הוספת מחרוזות התרגום הבאות בפורמט JSON לקובץ en.default.json שלך.
שלבים:
ממנהל Shopify שלך, עבור אל חנות מקוונת > ערכות נושא.
מצא את ערכת הנושא שברצונך לערוך, לחץ על הלחצן ... כדי לפתוח את תפריט הפעולות, ולאחר מכן לחץ על עריכת קוד.
יש לפתוח את הקובץ
en.default.json.צור שורה חדשה בתחתית הקובץ, ולאחר מכן הוסף את הקוד הבא:
"products": {
"product": {
"volume_pricing": {
"title": "Volume Pricing",
"note": "Volume pricing available",
"price_at_each": "at /ea"
}
"facets": {
"show_more": "Show more"
}
}
}- לחץ על שמירה.