markdown 特定集合必须使用购物车注释,其余集合可选

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了markdown 特定集合必须使用购物车注释,其余集合可选相关的知识,希望对你有一定的参考价值。

**Theme:** Debut

**Version(s) successfully tested on:**  1.4.1 and 11.3.0

**Recommended design time:** 15 mins



----

## What you have

Optional cart note for all the collections: 

![](https://screenshot.click/16-07-zhu91-n0tn4.jpg)

## What you want

Mandatory cart note for a particular collection (age-restricted collection) and optional for rest of the collections:

![](https://screenshot.click/17-59-y02tq-nh9xs.jpg)

![](https://screenshot.click/16-07-zhu91-n0tn4.jpg)

## How you get it

**Step 1:**

**1.** Open up **cart-template.liquid** Find this code ``` section.settings.cart_notes_enable ```.
Select the entire block of this code. It will look like this:
![](https://screenshot.click/16-24-ktc1y-wpy4n.jpg)


**2.** Replace the entire block with this code:
```
    {% assign my_variable = settings.collection_name %}
          {% for item in cart.items %}
       	{% for collection in item.product.collections %}
        {% if collection.title == my_variable %}
          {% assign preSaleBeerItem= true %}
        
        {% endif %}
         {% endfor %}
       {% endfor %}
          
         {% if preSaleBeerItem==true %}
          {% if section.settings.cart_notes_enable %}
            <div class="grid__item medium-up--one-half cart-note">
              <label for="CartSpecialInstructions1" class="cart-note__label small--text-center">{{settings.cart_note_heading_for_mandatory_collection}}</label>
              <textarea name="note" id="CartSpecialInstructions1" class="cart-note__input" required>{{ cart.note }}</textarea>
            </div>
          {% endif %}
          
          {% else %}
           
          	{% if section.settings.cart_notes_enable %}
             <div class="grid__item medium-up--one-half cart-note">
               <label for="CartSpecialInstructions" class="cart-note__label small--text-center">{{ settings.cart_note_heading_for_optional_collection}}</label>
                <textarea name="note" id="CartSpecialInstructions" class="cart-note__input">{{ cart.note }}</textarea>
             </div>
            {% endif %}
           {% endif %} 
```
**3.** It should look like this:
![](https://screenshot.click/17-08-luzxg-zg7f9.jpg)

**4.** At the bottom of this file add the below code and save it:
```
<script>
  var customMessage = "{{ settings.cart_note_msg }}" ;
</script>
```

**Step 2:**

**1.** Open up **theme.js** 
Add this code at the bottom of the file:
```
$(document).ready(function() {
    $('body').on('click', '[name="checkout"], [name="goto_pp"], [name="goto_gc"]', function() {
      if ($('#CartSpecialInstructions1').val().length > 0) {
        $(this).submit();
      }
      else {
        alert(customMessage);
        return false;
      }
    });
  });
```

**Step 3:**

**1.** Open settings_schema.json and below ```"theme_support_url": "https:\/\/support.shopify.com\/"
  },``` add this code:
```
{
    "name": "Cart page",
    "settings": [
      {
      "type": "text",
      "id": "collection_name",
      "label": "Mandatory collection name"

    },
	{
      "type": "text",
      "id": "cart_note_heading_for_mandatory_collection",
      "label": "Cart note heading for Mandatory collection"

    },
    {
      "type": "text",
      "id": "cart_note_heading_for_optional_collection",
      "label": "Cart note heading for optional collection"

    },
    {
      "type": "text",
      "id": "cart_note_msg",
      "label": "Mandatory cart note alert message"

    }
    ]
  },
  ```
  
**2.** Save the file and the code should look like this:
![](https://screenshot.click/17-13-7hp35-rwe0h.jpg)

**Step 4.** Done!The text can be configured in the theme customizer:
![](https://screenshot.click/17-15-yf6l9-r02f1.jpg)



以上是关于markdown 特定集合必须使用购物车注释,其余集合可选的主要内容,如果未能解决你的问题,请参考以下文章

房间错误:参数的类型必须是使用 @Entity 注释的类或其集合/数组。即使添加了 androidx.room:room-ktx

参数的类型必须是带有 @Entity 注释的类或其集合/数组

如何对循环内的按钮使用相同的功能?

点击集合视图单元以向地图添加注释

匹配java Regex中特定html标签的选定选项

markdown 调整购物车通知计时器