ÈËÉú¾ÍÊDz©¡¤(Öйú)×ðÁúAGÆì½¢Ìü

ÈËÉú¾ÍÊDz©¡¤(Öйú)×ðÁúAGÆì½¢Ìü(LianLian Global)¹ÙÍøÊ×Ò³

shopifyÔÚ²úÆ·Ò³ÃæÉÏÏÔʾʣÓàµÄ¶àÊôÐÔ¿â´æ°ì·¨

shopify²úÆ·Ò³Ãæ¿â´æÏÔʾ
2022/03/07
×Ô½¨Õ¾

ÔÚ²úÆ·Ò³ÃæÉÏÏÔʾʣÓàµÄ¶àÊôÐÔ¿â´æ

±¸×¢

ÈôÊÇÄúʹÓàShopify µÄÃâ·ÑÄ£°å£¬£¬£¬£¬£¬£¬Äú¿ÉÒÔÁªÏµ Shopify Ö§³ÖÍŶӻñµÃ¹ØÓڴ˽̵̳Ä×ÊÖú¡£¡£¡£¡£¡£¡£ ¡£¡£´Ë½Ì³ÌÐèÒª 15 ·ÖÖÓµÄÉè¼ÆÊ±¼ä¡£¡£¡£¡£¡£¡£ ¡£¡£ÈôÒªÏàʶÏêÇ飬£¬£¬£¬£¬£¬Çë²ÎÔÄ Support for themes¡£¡£¡£¡£¡£¡£ ¡£¡£

±¸×¢

´Ë×Ô½ç˵ÓÃÓÚ¸´¹Å Shopify Ä£°å£¬£¬£¬£¬£¬£¬²»ÊÊÓÃÓÚ¡°Online Store 2.0¡±Ä£°å¡£¡£¡£¡£¡£¡£ ¡£¡£

  • ÕÒµ½ÄúµÄÄ£°å¼Ü¹¹°æ±¾

  • ̽Ë÷¡°Online Store 2.0¡±Ä£°å×Ô½ç˵


Äú¿ÉÒÔÔÚ²úÆ·Ò³Ãæ»òÌØÉ«²úÆ··ÖÇøÖÐÌí¼ÓÒ»ÌõÐÂÎÅ£¬£¬£¬£¬£¬£¬ÓÃÓÚÔÚ²úÆ·¶àÊôÐÔ¿â´æ½ÏµÍʱÏÔʾ¿â´æÖеÄÉÌÆ·ÊýÄ¿¡£¡£¡£¡£¡£¡£ ¡£¡£ÈôÒªÏÔʾ´ËÐÂÎÅ£¬£¬£¬£¬£¬£¬ÄúÐèҪΪ²úÆ·ÆôÓÃ¿â´æ¸ú×Ù¡£¡£¡£¡£¡£¡£ ¡£¡£

´Ë×Ô½ç˵ÉèÖõİ취ÒòÄúµÄÄ£°å¶øÒì¡£¡£¡£¡£¡£¡£ ¡£¡£µã»÷Ä£°åµÄ°´Å¥£¬£¬£¬£¬£¬£¬È»ºóƾÌý˵Ã÷²Ù×÷¡£¡£¡£¡£¡£¡£ ¡£¡£

ÌáÐÑ£ºShopify µÄ Supply Ä£°åÖÐÒѰüÀ¨ÏÔʾʣÓàÊýÄ¿ÐÂÎÅÉèÖᣡ£¡£¡£¡£¡£ ¡£¡£Äú¿ÉÒÔÔÚÄ£°å¼­Æ÷ÖÐÆôÓôËÉèÖᣡ£¡£¡£¡£¡£ ¡£¡£

  • Debut

  • Venture / Brooklyn / Simple / Minimal

  • Boundless

  • Narrative

Õë¶Ô Debut µÄ°ì·¨

±à¼­ theme.liquid

  1. ÔÚ Shopify ºǫ́ÖУ¬£¬£¬£¬£¬£¬×ªµ½ÔÚÏßÊÐËÁ > Ä£°å¡£¡£¡£¡£¡£¡£ ¡£¡£

  2. ÕÒµ½Òª±à¼­µÄÄ£°å£¬£¬£¬£¬£¬£¬È»ºóµã»÷²Ù×÷ > ±à¼­´úÂë¡£¡£¡£¡£¡£¡£ ¡£¡£

  3. ÔÚ Layout Ä¿Â¼ÖУ¬£¬£¬£¬£¬£¬·­¿ª theme.liquid¡£¡£¡£¡£¡£¡£ ¡£¡£

  4. ²éÕÒ´úÂëÖеĿ¢Ê </head> ±ê¼Ç¡£¡£¡£¡£¡£¡£ ¡£¡£ÔÚ¿¢Ê </head> ±ê¼ÇÉÏ·½µÄÐÂÐÐÖУ¬£¬£¬£¬£¬£¬Õ³ÌùÒÔÏ´úÂ룺

<script>   var variantStock = {}; </script>
  1. µã»÷ÉúÑÄ¡£¡£¡£¡£¡£¡£ ¡£¡£

±à¼­ product-template.liquid »ò featured-product.liquid

  1. ÔÚ Sections Ä¿Â¼ÖУ¬£¬£¬£¬£¬£¬·­¿ª product-template.liquid »ò featured-product.liquid£º

    • ·­¿ª product-template.liquid ÒÔ½«´Ë¹¦Ð§Ìí¼Óµ½²úÆ·Ò³Ãæ¡£¡£¡£¡£¡£¡£ ¡£¡£

    • ·­¿ª featured-product.liquid ÒÔ½«´Ë¹¦Ð§Ìí¼Óµ½Ö÷Ò³ÉϵÄÌØÉ«²úÆ··ÖÇø¡£¡£¡£¡£¡£¡£ ¡£¡£

  2. ²éÕÒ {% form 'product'¡£¡£¡£¡£¡£¡£ ¡£¡£Ôڴ˱ê¼ÇÉÏ·½Ìí¼ÓÒÔÏ´úÂ룺

<div>   {% if current_variant.inventory_quantity > 0 and current_variant.inventory_management == 'shopify' %}     <p>Stock: {{ current_variant.inventory_quantity }}</p>   {% endif %} </div>

ÉÏÊö´úÂë»áÊä³ö Stock: x¡£¡£¡£¡£¡£¡£ ¡£¡£Äú¿ÉÒÔͨ¹ýµ÷½â <p> ±ê¼ÇÖеÄÄÚÈÝÀ´¸ü¸ÄÓïÑÔ¡£¡£¡£¡£¡£¡£ ¡£¡£ÇëÈ·±£ÔÚ <p> ±ê¼ÇÖаüÀ¨ {{ current_variant.inventory_quantity }}¡£¡£¡£¡£¡£¡£ ¡£¡£

  1. ÔÚÎļþµ×²¿£¬£¬£¬£¬£¬£¬Ìí¼ÓÒÔÏ´úÂ룺

<script>   {% for variant in product.variants %}     variantStock[{{- variant.id -}}] = {{ variant.inventory_quantity }};   {% endfor %} </script>
  1. µã»÷ÉúÑÄ¡£¡£¡£¡£¡£¡£ ¡£¡£

±à¼­ theme.js.liquid »ò theme.js

ÄúÐèÒª¶ÔÕâЩÎļþËù×öµÄ¸ü¸ÄÈ¡¾öÓÚÄúʹÓÃµÄ Debut °æ±¾¡£¡£¡£¡£¡£¡£ ¡£¡£

°æ±¾ 17.8.0 ¼°ÒÔÏÂ

  1. ·­¿ª theme.js.liquid »ò theme.js¡£¡£¡£¡£¡£¡£ ¡£¡£

  2. ²éÕÒ theme.Product = (function()¡£¡£¡£¡£¡£¡£ ¡£¡£ÔÚ this.selectors = { Ï·½Ìí¼ÓÒÔÏ´úÂ룺

inventoryHtml: '.inventoryWrapper',
  1. ÔÚͳһÎļþÖУ¬£¬£¬£¬£¬£¬²éÕÒ _updateAddToCart: function(evt) {¡£¡£¡£¡£¡£¡£ ¡£¡£ÔÚÕýÏ·½Ìí¼ÓÒÔÏ´úÂ룺

var inventoryWrapper = this.container.querySelector(this.selectors.inventoryHtml);
  1. ²éÕÒ if (variant.available) {¡£¡£¡£¡£¡£¡£ ¡£¡£ÔÚ } else { Óï¾äǰÌí¼ÓÒÔÏ´úÂ룺js if (variantStock[variant.id] > 0 && variant.inventory_management == 'shopify' && inventoryWrapper !== null) { const inventoryHtml =

    Stock: ${variantStock[variant.id]}

    ; inventoryWrapper.innerHTML = inventoryHtml; } else { inventoryWrapper.innerHTML = ''; }

    ÉÏÊö´úÂë»áÊä³ö Stock: x¡£¡£¡£¡£¡£¡£ ¡£¡£Äú¿ÉÒÔͨ¹ýµ÷½â <p> ±ê¼ÇÖеÄÄÚÈÝÀ´¸ü¸ÄÓïÑÔ¡£¡£¡£¡£¡£¡£ ¡£¡£ÇëÈ·±£ÔÚ <p> ±ê¼ÇÖаüÀ¨ ${variantStock[variant.id]}¡£¡£¡£¡£¡£¡£ ¡£¡£

  2. µã»÷ÉúÑÄ¡£¡£¡£¡£¡£¡£ ¡£¡£

°æ±¾ 17.9.0 ¼°ÒÔÉÏ

  1. ·­¿ª theme.js.liquid »ò theme.js¡£¡£¡£¡£¡£¡£ ¡£¡£

  2. ²éÕÒ theme.Product = (function()¡£¡£¡£¡£¡£¡£ ¡£¡£ÔÚ this.selectors = { Ï·½Ìí¼ÓÒÔÏ´úÂ룺

inventoryHtml: '.inventoryWrapper',
  1. ÔÚͳһÎļþÖУ¬£¬£¬£¬£¬£¬²éÕÒ _setProductState: function(evt) {¡£¡£¡£¡£¡£¡£ ¡£¡£ÔÚÕýÏ·½Ìí¼ÓÒÔÏ´úÂ룺

var inventoryWrapper = this.container.querySelector(this.selectors.inventoryHtml);
  1. ÔÚͳһº¯ÊýÖУ¬£¬£¬£¬£¬£¬²éÕÒ if (!variant) {¡£¡£¡£¡£¡£¡£ ¡£¡£ÔÚÓÒ } À¨ºÅºó£¬£¬£¬£¬£¬£¬Ìí¼ÓÒÔÏ´úÂ룺

else {   if (variantStock[variant.id] > 0 && variant.inventory_management == 'shopify' && inventoryWrapper !== null) {     const inventoryHtml = `<p>Stock: ${variantStock[variant.id]}</p>`;     inventoryWrapper.innerHTML = inventoryHtml;   } else {     inventoryWrapper.innerHTML = '';   } }

ÉÏÊö´úÂë»áÊä³ö Stock: x¡£¡£¡£¡£¡£¡£ ¡£¡£Äú¿ÉÒÔͨ¹ýµ÷½â <p> ±ê¼ÇÖеÄÄÚÈÝÀ´¸ü¸ÄÓïÑÔ¡£¡£¡£¡£¡£¡£ ¡£¡£ÇëÈ·±£ÔÚ <p> ±ê¼ÇÖаüÀ¨ ${variantStock[variant.id]}¡£¡£¡£¡£¡£¡£ ¡£¡£

  1. µã»÷ÉúÑÄ¡£¡£¡£¡£¡£¡£ ¡£¡£

ShopifyÉÌ»§¹ÙÍøÔ­ÎÄÏêÇ飺

Show the remaining inventory of a variant on product pages


Note

If you use a free theme from Shopify, then you might be able to contact Shopify Support for help with this tutorial. It requires 15 minutes of design time. To learn more, refer to Support for themes.

Note

This customization is for vintage Shopify themes, and doesn't apply to Online Store 2.0 themes.

  • Find out your theme's architecture version

  • Explore Online Store 2.0 theme customizations


You can add a message on the product page or featured product section that shows the number of items you have in stock when inventory runs low on a product variant. For this message to show, you need to enable inventory tracking for the product.

The steps for this customization vary depending on your theme. Click the button for your theme and follow the instructions.


Tip

Shopify¡¯s Supply theme already includes a Show remaining quantity message setting. You can enable this setting from the theme editor.


  • Debut

  • Venture / Brooklyn / Simple / Minimal

  • Boundless

  • Narrative

Steps for Debut

Edit theme.liquid

  1. From your Shopify admin, go to Online Store > Themes.

  2. Find the theme you want to edit, and then click Actions > Edit code.

  3. From the Layout directory, open theme.liquid.

  4. Find the closing </head> tag in the code. On a new line above the closing </head> tag, paste the following code:

    <script>   var variantStock = {}; </script>
  5. Click Save.

Edit product-template.liquid or featured-product.liquid

  1. From the Sections directory, open product-template.liquid or featured-product.liquid:

    • Open product-template.liquid to add this feature to product pages.

    • Open featured-product.liquid to add this feature to the featured product section on the home page.

  2. Find {% form 'product'. Above this tag, add the following code:

    <div>   {% if current_variant.inventory_quantity > 0 and current_variant.inventory_management == 'shopify' %}     <p>Stock: {{ current_variant.inventory_quantity }}</p>   {% endif %} </div>

    The code above outputs Stock: x. You can change the wording by adjusting the content in the <p> tags. Make sure to include {{ current_variant.inventory_quantity }} in your <p> tags.

  3. At the bottom of the file, add the following code:

    <script>   {% for variant in product.variants %}     variantStock[{{- variant.id -}}] = {{ variant.inventory_quantity }};   {% endfor %} </script>
  4. Click Save.

Edit theme.js.liquid or theme.js

The changes that you need to make to these files depend on the version of Debut that you're using.

Versions 17.8.0 and below

  1. Open theme.js.liquid or theme.js.

  2. Find theme.Product = (function(). Below this.selectors = {, add the following code:

    inventoryHtml: '.inventoryWrapper',
  3. In the same file, find _updateAddToCart: function(evt) {. Directly below, add the following code:

    var inventoryWrapper = this.container.querySelector(this.selectors.inventoryHtml);
  4. Find if (variant.available) {. Before the } else { statement, add the following code: js if (variantStock[variant.id] > 0 && variant.inventory_management == 'shopify' && inventoryWrapper !== null) {   const inventoryHtml = `<p>Stock: ${variantStock[variant.id]}</p>`;   inventoryWrapper.innerHTML = inventoryHtml; } else {   inventoryWrapper.innerHTML = ''; }

    The code above outputs Stock: x. You can change the wording by adjusting the content in the <p> tags. Make sure to include ${variantStock[variant.id]} in your <p> tags.

  5. Click Save.

Versions 17.9.0 and above

  1. Open theme.js.liquid or theme.js.

  2. Find theme.Product = (function(). Below this.selectors = {, add the following code:

    inventoryHtml: '.inventoryWrapper',
  3. In the same file, find _setProductState: function(evt) {. Directly below, add the following code:

    var inventoryWrapper = this.container.querySelector(this.selectors.inventoryHtml);
  4. In the same function, find if (!variant) {. After the closing } bracket, add the following code:

    else {   if (variantStock[variant.id] > 0 && variant.inventory_management == 'shopify' && inventoryWrapper !== null) {     const inventoryHtml = `<p>Stock: ${variantStock[variant.id]}</p>`;     inventoryWrapper.innerHTML = inventoryHtml;   } else {     inventoryWrapper.innerHTML = '';   } }

    The code above outputs Stock: x. You can change the wording by adjusting the content in the <p> tags. Make sure to include ${variantStock[variant.id]} in your <p> tags.

  5. Click Save.

ÎÄÕÂÄÚÈÝȪԴ£ºShopifyÉÌ»§¹Ù·½ÍøÕ¾


¸ü¶à
¡¾ÍøÕ¾µØÍ¼¡¿¡¾sitemap¡¿