{
    "version": "https:\/\/jsonfeed.org\/version\/1",
    "title": "Блог Чуденкова Алексея, заметки с тегом: shopify",
    "home_page_url": "https:\/\/blog.chudenkov.ru\/tags\/shopify\/",
    "feed_url": "https:\/\/blog.chudenkov.ru\/tags\/shopify\/json\/",
    "icon": "https:\/\/blog.chudenkov.ru\/user\/userpic@2x.jpg",
    "author": {
        "name": "Чуденков Алексей",
        "url": "https:\/\/blog.chudenkov.ru\/",
        "avatar": "https:\/\/blog.chudenkov.ru\/user\/userpic@2x.jpg"
    },
    "items": [
        {
            "id": "71",
            "url": "https:\/\/blog.chudenkov.ru\/all\/shopify-add-quantity-button-to-cart\/",
            "title": "Shopify: add quantity button to cart",
            "content_html": "<p>Добавить в cart-template.liquid<\/p>\n<pre class=\"e2-text-code\"><code>&lt;input type='button' value='-' class='qtyminus' field='updates_{{ item.id }}' \/&gt;\r\n&lt;input type=&quot;number&quot; name=&quot;updates[]&quot; id=&quot;updates_{{ item.id }}&quot; class=&quot;quantity&quot; value=&quot;{{ item.quantity }}&quot; \/&gt;\r\n&lt;input type='button' value='+' class='qtyplus' field='updates_{{ item.id }}' \/&gt;<\/code><\/pre><p>Добавить в Assets cart.js и его содержание:<\/p>\n<pre class=\"e2-text-code\"><code>jQuery(document).ready(function(){\r\n    $('.qtyplus').click(function(e){\r\n        e.preventDefault();\r\n        fieldName = $(this).attr('field');\r\n        var currentVal = parseInt($('input[id='+fieldName+']').val());\r\n        if (!isNaN(currentVal)) {\r\n            $('input[id='+fieldName+']').val(currentVal + 1);\r\n        } else {\r\n            $('input[id='+fieldName+']').val(0);\r\n        }\r\n    });\r\n    $(&quot;.qtyminus&quot;).click(function(e) {\r\n        e.preventDefault();\r\n        fieldName = $(this).attr('field');\r\n        var currentVal = parseInt($('input[id='+fieldName+']').val());\r\n        if (!isNaN(currentVal) &amp;&amp; currentVal &gt; 0) {\r\n            $('input[id='+fieldName+']').val(currentVal - 1);\r\n        } else {\r\n            $('input[id='+fieldName+']').val(0);\r\n        }\r\n    });\r\n});<\/code><\/pre><p>Не забыть подключить JS с условием если вы находитесь на странице корзины, чтобы не перегружать сайт лишними скриптами.<\/p>\n",
            "date_published": "2020-02-01T13:35:31+03:00",
            "date_modified": "2020-02-01T13:35:26+03:00",
            "_date_published_rfc2822": "Sat, 01 Feb 2020 13:35:31 +0300",
            "_rss_guid_is_permalink": "false",
            "_rss_guid": "71",
            "_e2_data": {
                "is_favourite": false,
                "links_required": [
                    "system\/library\/highlight\/highlight.js",
                    "system\/library\/highlight\/highlight.css",
                    "system\/library\/highlight\/highlight.js",
                    "system\/library\/highlight\/highlight.css"
                ],
                "og_images": []
            }
        },
        {
            "id": "70",
            "url": "https:\/\/blog.chudenkov.ru\/all\/shopify-check-user-age-before-shopping\/",
            "title": "Shopify: check user age before shopping",
            "content_html": "<p>Есть продукты, которые можно продавать в США только лицам старше 21 года, да и то, не во всех штатах. Сам шопифай такого решения разумеется не имеет, поэтому появилось следующее решение, которое работает так: если нет соответствующей куки, то показываем пользователю предупреждение (предупреждение сами верстаем), а если кука есть, то не показываем пользователю предупреждение N-дней. Если пользователю нет 21 года, то отправляем его в магазин лего и куку не присваиваем.<\/p>\n<p>Я запихал текст предупреждения в переменные, чтобы их можно было просто отредактировать.<\/p>\n<pre class=\"e2-text-code\"><code>{% capture warning_header %}\r\nTHE SITE IS ONLY AVAILABLE TO PERSONS OVER 21 YEARS OF AGE.\r\n{% endcapture %}\r\n\r\n{% capture warning_question %}\r\nARE YOU'RE 21 YEARS OLD?\r\n{% endcapture %}<\/code><\/pre><p>Далее вёрстка самого предупреждения, который нужно запихать в theme.liquid сразу после body. Рекомендую подключить сниппетом, чтобы не засорять шаблон кучей строк.<\/p>\n<pre class=\"e2-text-code\"><code>&lt;div class=&quot;warning&quot; id=&quot;warning&quot;&gt;\r\n    &lt;div class=&quot;warning-popup&quot; id=&quot;popup&quot;&gt;\r\n        &lt;div class=&quot;logo&quot;&gt;\r\n            &lt;img src=&quot;https:\/\/cdn.shopify.com\/s\/files\/logo.svg&quot; alt=&quot;logo&quot;&gt;\r\n        &lt;\/div&gt;\r\n        &lt;div&gt;{{ warning_header }}&lt;\/div&gt;\r\n        &lt;div class=&quot;warning-question&quot;&gt;{{ warning_question }}&lt;\/div&gt;\r\n        &lt;div class=&quot;btns&quot;&gt;\r\n            &lt;a href=&quot;https:\/\/lego.com\/&quot;&gt;&lt;button class=&quot;btn&quot;&gt;No&lt;\/button&gt;&lt;\/a&gt;\r\n            &lt;button class=&quot;btn&quot; onclick=&quot;ageCheck()&quot;&gt;Yes&lt;\/button&gt;\r\n        &lt;\/div&gt;\r\n    &lt;\/div&gt;\r\n&lt;\/div&gt;<\/code><\/pre><p>Далее сам скрипт, логику работы описал выше.<\/p>\n<pre class=\"e2-text-code\"><code>&lt;script&gt;\r\n function ageCheck() {\r\n     var days = 14; \/\/количество дней, через которое спросим возраст снова\r\n     var date = new Date();\r\n     date.setTime(date.getTime()+(days*24*60*60*1000));\r\n     var expires = &quot;; expires=&quot;+date.toGMTString();\r\n     document.cookie = 'isAnAdult=true;'+expires+&quot;; path=\/&quot;;\r\n     location.reload();\r\n   };\r\n  function readCookie(name) {\r\n    var nameEQ = name + &quot;=&quot;;\r\n    var ca = document.cookie.split(';');\r\n    for(var i=0;i &lt; ca.length;i++) {\r\n      var c = ca[i];\r\n      while (c.charAt(0)==' ') c = c.substring(1,c.length);\r\n      if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);\r\n    }\r\n    return null;\r\n  };\r\n  var isAnAdult = readCookie('isAnAdult');\r\n  if (isAnAdult) {\r\n    document.write(&quot;&lt;style&gt; #warning { display: none; overflow:hidden; }&lt;\/style&gt;&quot;);\r\n  };\r\n&lt;\/script&gt;<\/code><\/pre>",
            "date_published": "2020-01-31T03:26:16+03:00",
            "date_modified": "2020-01-31T03:25:28+03:00",
            "_date_published_rfc2822": "Fri, 31 Jan 2020 03:26:16 +0300",
            "_rss_guid_is_permalink": "false",
            "_rss_guid": "70",
            "_e2_data": {
                "is_favourite": false,
                "links_required": [
                    "system\/library\/highlight\/highlight.js",
                    "system\/library\/highlight\/highlight.css",
                    "system\/library\/highlight\/highlight.js",
                    "system\/library\/highlight\/highlight.css",
                    "system\/library\/highlight\/highlight.js",
                    "system\/library\/highlight\/highlight.css"
                ],
                "og_images": []
            }
        }
    ],
    "_e2_version": 3365,
    "_e2_ua_string": "E2 (v3365; Aegea)"
}