shopify±à¼JavaScript ÎļþºÍ¸ü¸ÄÌí¼Óµ½¹ºÎï³µ°´Å¥°ì·¨
Boundless °ì·¨
ƾ֤ÒÔϰ취½«×Ô½ç˵ÏîÓ¦ÓÃÓÚ Boundless£º
±à¼Ä£°åµÄ JavaScript Îļþ
ÈôÒª±à¼Ä£°åµÄ JavaScript Îļþ£¬£¬£¬£¬£¬ÇëÖ´ÐÐÒÔϲÙ×÷£º
PC£º
ÔÚ Shopify ºǫ́ÖУ¬£¬£¬£¬£¬×ªµ½ÔÚÏßÊÐËÁ > Ä£°å¡£¡£¡£¡£¡£
ÕÒµ½Òª±à¼µÄÄ£°å£¬£¬£¬£¬£¬È»ºóµã»÷²Ù×÷ > ±à¼´úÂë¡£¡£¡£¡£¡£
ÔÚ Assets Ŀ¼ÖУ¬£¬£¬£¬£¬µã»÷
theme.js»òtheme.js.liquid¡£¡£¡£¡£¡£²éÕÒ´úÂë
initVariantSelectors¡£¡£¡£¡£¡£ÔڸôúÂëÏ·½£¬£¬£¬£¬£¬²éÕÒÒÔÏ´úÂ룺
// Clean up variant labels if the Shopify-defined // defaults are the only ones left this.simplifyVariantLabels(this.productSingleObject, this.$container);
Æ»¹ûϵͳ£º
ÔÚ Shopify Ó¦ÓÃÖУ¬£¬£¬£¬£¬Çá´¥ÊÐËÁ¡£¡£¡£¡£¡£
ÔÚÏúÊÛÇþµÀ²¿·ÖÖУ¬£¬£¬£¬£¬Çá´¥ÔÚÏßÊÐËÁ¡£¡£¡£¡£¡£
Çá´¥ Manage themes£¨ÖÎÀíÄ£°å£©¡£¡£¡£¡£¡£
ÕÒµ½Òª±à¼µÄÄ£°å£¬£¬£¬£¬£¬È»ºóµã»÷²Ù×÷ > ±à¼´úÂë¡£¡£¡£¡£¡£
ÔÚ Assets Ŀ¼ÖУ¬£¬£¬£¬£¬µã»÷
theme.js»òtheme.js.liquid¡£¡£¡£¡£¡£²éÕÒ´úÂë
initVariantSelectors¡£¡£¡£¡£¡£ÔڸôúÂëÏ·½£¬£¬£¬£¬£¬²éÕÒÒÔÏ´úÂ룺
// Clean up variant labels if the Shopify-defined // defaults are the only ones left this.simplifyVariantLabels(this.productSingleObject, this.$container);
°²×¿ÏµÍ³£º
ÔÚ Shopify Ó¦ÓÃÖУ¬£¬£¬£¬£¬Çá´¥ÊÐËÁ¡£¡£¡£¡£¡£
ÔÚÏúÊÛÇþµÀ²¿·ÖÖУ¬£¬£¬£¬£¬Çá´¥ÔÚÏßÊÐËÁ¡£¡£¡£¡£¡£
Çá´¥ Manage themes£¨ÖÎÀíÄ£°å£©¡£¡£¡£¡£¡£
ÕÒµ½Òª±à¼µÄÄ£°å£¬£¬£¬£¬£¬È»ºóµã»÷²Ù×÷ > ±à¼´úÂë¡£¡£¡£¡£¡£
ÔÚ Assets Ŀ¼ÖУ¬£¬£¬£¬£¬µã»÷
theme.js»òtheme.js.liquid¡£¡£¡£¡£¡£²éÕÒ´úÂë
initVariantSelectors¡£¡£¡£¡£¡£ÔڸôúÂëÏ·½£¬£¬£¬£¬£¬²éÕÒÒÔÏ´úÂ룺
// Clean up variant labels if the Shopify-defined // defaults are the only ones left this.simplifyVariantLabels(this.productSingleObject, this.$container);
ÔÚÏÂÃæµÄÐÂÐÐÖÐÌí¼ÓÒÔÏ´úÂ룺
if (typeof(productOptions) != "undefined") { for (i = 0; i < productOptions.length; i++) { const vowels = ['a', 'e', 'i', 'o', 'u']; const firstOptionLetter = productOptions[i][i][0].toLowerCase(); let indef = 'a'; if (vowels.includes(firstOptionLetter)) { indef = 'an'; }; const select = document.querySelectorAll('.single-option-selector')[i]; const options = select.querySelectorAll('option'); if (options.length > 1) { let option = new Option('Pick ' + indef + ' ' + productOptions[i][i], ''); select.add(option, select.firstChild); select.selectedIndex = 0; } } }´úÂëÓ¦ÈçÏÂËùʾ£º
// Clean up variant labels if the Shopify-defined // defaults are the only ones left this.simplifyVariantLabels(this.productSingleObject, this.$container); if (typeof(productOptions) != "undefined") { for (i = 0; i < productOptions.length; i++) { const vowels = ['a', 'e', 'i', 'o', 'u']; const firstOptionLetter = productOptions[i][i][0].toLowerCase(); let indef = 'a'; if (vowels.includes(firstOptionLetter)) { indef = 'an'; }; const select = document.querySelectorAll('.single-option-selector')[i]; const options = select.querySelectorAll('option'); if (options.length > 1) { let option = new Option('Pick ' + indef + ' ' + productOptions[i][i], ''); select.add(option, select.firstChild); select.selectedIndex = 0; } } }²éÕÒÒÔÏ´úÂëÐУº
$(selectors.addToCartText).html(theme.strings.soldOut);
´Ë´úÂëÐÐÓÐÁ½¸öʵÀý£¬£¬£¬£¬£¬¾ù¿ÉÔÚ productVariantCallback º¯ÊýÖÐÕÒµ½¡£¡£¡£¡£¡£Çë½ö½«µÚ¶þ¸öʵÀýÌæ»»Îª£º
$(selectors.addToCartText).html('Make a Selection');±¸×¢£ºÄ³Ð©°æ±¾µÄ Boundless ²»°üÀ¨´Ë°ì·¨ÖÐÒªÌæ»»µÄ´úÂëÐС£¡£¡£¡£¡£ÈôÊÇÄúÎÞ·¨ÕÒµ½´úÂ룬£¬£¬£¬£¬ÔòÌøÖÁÏÂÒ»²½¡£¡£¡£¡£¡£
µã»÷ÉúÑÄ¡£¡£¡£¡£¡£
±à¼²úÆ·Ò³ÃæÄ£°å
ÈôÒª±à¼²úÆ·Ò³ÃæÄ£°å£¬£¬£¬£¬£¬ÇëÖ´ÐÐÒÔϲÙ×÷£º
ÔÚ Sections Ŀ¼ÖУ¬£¬£¬£¬£¬µã»÷
product-template.liquid¡£¡£¡£¡£¡£²éÕÒÒÔÏ´úÂ룺
liquid {% assign current_variant = product.selected_or_first_available_variant %}½«ÆäÌæ»»Îª£º
liquid {% assign current_variant = product.selected_variant %}²éÕÒÒÔÏ´úÂë²¢½«Æäɾ³ý£º
liquid {% if variant == product.selected_or_first_available_variant %} selected="selected" {% endif %}²éÕÒ´úÂë
{% schema %}¡£¡£¡£¡£¡£½«Ï·½´úÂëÕ³ÌùÔÚÆäÉÏ·½µÄÒ»ÐÐÖУº```liquid {% if current_variant == blank %} {% endif %} ``` ´úÂëÓ¦ÈçÏÂËùʾ£º ```liquid {% if current_variant == blank %} {% endif %}
{% schema %} ```
¸ü¸Ä Add to cart£¨Ìí¼Óµ½¹ºÎï³µ£©°´Å¥ÓïÑÔÉèÖÃ
Äú¿ÉÒÔ¸ü¸Ä Add to cart£¨Ìí¼Óµ½¹ºÎï³µ£©°´Å¥µÄÓïÑÔÉèÖ㬣¬£¬£¬£¬Ê¹ÔÚûÓоÙÐÐÈκÎÑ¡Ôñ֮ǰ²úÆ·²»»áÏÔʾΪ¡°²»¿ÉÓᱡ£¡£¡£¡£¡£
µã»÷ÉúÑÄ¡£¡£¡£¡£¡£
PC£º
ÔÚ Shopify ºǫ́ÖУ¬£¬£¬£¬£¬×ªµ½ÔÚÏßÊÐËÁ > Ä£°å¡£¡£¡£¡£¡£
ÕÒµ½Òª±à¼µÄÄ£°å£¬£¬£¬£¬£¬È»ºóµã»÷²Ù×÷ > ±à¼ÓïÑÔ¡£¡£¡£¡£¡£
ÔÚɸѡÌõ¼þ¿òÖУ¬£¬£¬£¬£¬×îÏȼüÈë
unavailableÒÔÏÔʾ¡°²»¿ÉÓá±·Òë¡£¡£¡£¡£¡£½«Îı¾²»¿ÉÓÃÌæ»»Îª
Make a selection£ºµã»÷ÉúÑÄ¡£¡£¡£¡£¡£
Æ»¹ûϵͳ£º
ÔÚ Shopify Ó¦ÓÃÖУ¬£¬£¬£¬£¬Çá´¥ÊÐËÁ¡£¡£¡£¡£¡£
ÔÚÏúÊÛÇþµÀ²¿·Ö£¬£¬£¬£¬£¬Çá´¥ÔÚÏßÊÐËÁ¡£¡£¡£¡£¡£
Çá´¥ÖÎÀíÄ£°å¡£¡£¡£¡£¡£
ÕÒµ½Òª±à¼µÄÄ£°å£¬£¬£¬£¬£¬È»ºóµã»÷²Ù×÷ > ±à¼ÓïÑÔ¡£¡£¡£¡£¡£
ÔÚɸѡÌõ¼þ¿òÖУ¬£¬£¬£¬£¬×îÏȼüÈë
unavailableÒÔÏÔʾ¡°²»¿ÉÓá±·Òë¡£¡£¡£¡£¡£½«Îı¾²»¿ÉÓÃÌæ»»Îª
Make a selection£ºµã»÷ÉúÑÄ¡£¡£¡£¡£¡£
°²×¿ÏµÍ³£º
ÔÚ Shopify Ó¦ÓÃÖУ¬£¬£¬£¬£¬Çá´¥ÊÐËÁ¡£¡£¡£¡£¡£
ÔÚÏúÊÛÇþµÀ²¿·Ö£¬£¬£¬£¬£¬Çá´¥ÔÚÏßÊÐËÁ¡£¡£¡£¡£¡£
Çá´¥ÖÎÀíÄ£°å¡£¡£¡£¡£¡£
ÕÒµ½Òª±à¼µÄÄ£°å£¬£¬£¬£¬£¬È»ºóµã»÷²Ù×÷ > ±à¼ÓïÑÔ¡£¡£¡£¡£¡£
ÔÚɸѡÌõ¼þ¿òÖУ¬£¬£¬£¬£¬×îÏȼüÈë
unavailableÒÔÏÔʾ¡°²»¿ÉÓá±·Òë¡£¡£¡£¡£¡£½«Îı¾²»¿ÉÓÃÌæ»»Îª
Make a selection£ºµã»÷ÉúÑÄ¡£¡£¡£¡£¡£
ShopifyÉÌ»§¹ÙÍøÔÎÄÏêÇ飺
Steps for Boundless
Follow these steps to apply the customization to Boundless:
Edit your theme's JavaScript file
To edit your theme's JavaScript file:
PC£º
From your Shopify admin, go to Online Store > Themes.
Find the theme you want to edit, and then click Actions > Edit code.
In the Assets directory, click
theme.jsortheme.js.liquid.Find the code
initVariantSelectors. Below that, find the following code:// Clean up variant labels if the Shopify-defined // defaults are the only ones left this.simplifyVariantLabels(this.productSingleObject, this.$container);iPhone£º
From the Shopify app, tap Store.
In the Sales channels section, tap Online Store.
Tap Manage themes.
Find the theme you want to edit, and then click Actions > Edit code.
In the Assets directory, click
theme.jsortheme.js.liquid.Find the code
initVariantSelectors. Below that, find the following code:// Clean up variant labels if the Shopify-defined // defaults are the only ones left this.simplifyVariantLabels(this.productSingleObject, this.$container);Android£º
From the Shopify app, tap Store.
In the Sales channels section, tap Online Store.
Tap Manage themes.
Find the theme you want to edit, and then click Actions > Edit code.
In the Assets directory, click
theme.jsortheme.js.liquid.Find the code
initVariantSelectors. Below that, find the following code:// Clean up variant labels if the Shopify-defined // defaults are the only ones left this.simplifyVariantLabels(this.productSingleObject, this.$container);
Add the following code on a new line below:
if (typeof(productOptions) != "undefined") { for (i = 0; i < productOptions.length; i++) { const vowels = ['a', 'e', 'i', 'o', 'u']; const firstOptionLetter = productOptions[i][i][0].toLowerCase(); let indef = 'a'; if (vowels.includes(firstOptionLetter)) { indef = 'an'; }; const select = document.querySelectorAll('.single-option-selector')[i]; const options = select.querySelectorAll('option'); if (options.length > 1) { let option = new Option('Pick ' + indef + ' ' + productOptions[i][i], ''); select.add(option, select.firstChild); select.selectedIndex = 0; } } }It should look something like this:
// Clean up variant labels if the Shopify-defined // defaults are the only ones left this.simplifyVariantLabels(this.productSingleObject, this.$container); if (typeof(productOptions) != "undefined") { for (i = 0; i < productOptions.length; i++) { const vowels = ['a', 'e', 'i', 'o', 'u']; const firstOptionLetter = productOptions[i][i][0].toLowerCase(); let indef = 'a'; if (vowels.includes(firstOptionLetter)) { indef = 'an'; }; const select = document.querySelectorAll('.single-option-selector')[i]; const options = select.querySelectorAll('option'); if (options.length > 1) { let option = new Option('Pick ' + indef + ' ' + productOptions[i][i], ''); select.add(option, select.firstChild); select.selectedIndex = 0; } } }Find the following line of code:
$(selectors.addToCartText).html(theme.strings.soldOut);There are two instances of this line of code, both found within the
productVariantCallbackfunction. Replace only the second instance with:$(selectors.addToCartText).html('Make a Selection');Note
Some versions of Boundless do not include the line of code to be replaced in this step. If you can't find the code, then skip to the next step.
Click Save.
Edit your product page template
To edit your product page template:
In the Sections directory, click
product-template.liquid.Find the following code:
{% assign current_variant = product.selected_or_first_available_variant %}Replace it with:
{% assign current_variant = product.selected_variant %}Find the following code and delete it:
{% if variant == product.selected_or_first_available_variant %} selected="selected" {% endif %}Find the code
{% schema %}. Paste the following code on its own line above that:{% if current_variant == blank %} <script> var productOptions = [];{% for option in product.options -%} var optionObj = {}; optionObj[ {{ forloop.index0 }} ] = "{{ product.options[forloop.index0] }}"; productOptions.push(optionObj); {%- endfor %} </script> {% endif %}It should look something like this:
{% if current_variant == blank %} <script> var productOptions = [];{% for option in product.options -%} var optionObj = {}; optionObj[ {{ forloop.index0 }} ] = "{{ product.options[forloop.index0] }}"; productOptions.push(optionObj); {%- endfor %} </script> {% endif %}{% schema %}Click Save.
Change the Add to cart button language settings
You can change the language settings for the Add to cart button so that products do not appear as "Unavailable" before a selection is made.
PC£º
From your Shopify admin, go to Online Store > Themes.
Find the theme that you want to edit, and then click Actions > Edit languages.
In the Filter box, start typing
unavailableto show the "Unavailable" translation.Replace the text Unavailable to
Make a selection.Click Save.
iPhone£º
From the Shopify app, tap Store.
In the Sales channels section, tap Online Store.
Tap Manage themes.
Find the theme that you want to edit, and then click Actions > Edit languages.
In the Filter box, start typing
unavailableto show the "Unavailable" translation.Replace the text Unavailable to
Make a selection.Click Save.
Android£º
From the Shopify app, tap Store.
In the Sales channels section, tap Online Store.
Tap Manage themes.
Find the theme that you want to edit, and then click Actions > Edit languages.
In the Filter box, start typing
unavailableto show the "Unavailable" translation.Replace the text Unavailable to
Make a selection.Click Save.
ÎÄÕÂÄÚÈÝȪԴ£ºShopifyÉÌ»§¹Ù·½ÍøÕ¾
- 1ÏàʶÍâÑóÍË»õ³ÌÐò£¬£¬£¬£¬£¬ÍË»õ²»ÔÙÊÇÄÑÌâ
- 2ÑÇÂíѷƽ̨ÔËÓª±ØÄîÊé¼®
- 3wishµêËÁÉóºËÇ·ºà¹ýµÄÔµ¹ÊÔÓɼ°½â¾öÕ½ÂÔ
- 4ËÙÂôͨÐÂÊÖ¿ªµêÐèÒªÉÏ´«¼¸¶à²úÆ·
- 5Coupangƽ̨ÉϺ«¹ú»§ÍâѡƷƫÏòµÄ½¨Òé
- 6Lazadaƽ̨ÔõÑù±£»£»£»£»£»¤Âô¼ÒºÍÂò¼ÒµÄÉúÒâÇå¾²£¿£¿£¿£¿£¿£¿£¿
- 7¹ú¼ÊÎïÁ÷µÄÊÕÖ§¿Ú¹ØÎñ
- 8ÍâóÂô¼Ò±ØÖªµÄ¹È¸èËÑË÷ÒýÇæÊ¹Óü¼ÇÉ
- 9¿ç¾³µçÉÌÖ±·¢Ä£Ê½£ºÊµÏÖÓëÖ÷¹ËÐèÇóÎÞ·ì¶Ô½Ó
- 10shopifyÖÎÀíºǫ́²å¼þÓÐÄÄЩ£¿£¿£¿£¿£¿£¿£¿