templates/bundles/MLDevCatalogBundle/templates/default.html.twig line 1

Open in your IDE?
  1. {% set _basket_storage = app.session.get('mldev-cart-storage', []) %}
  2. {% set _basket_amount = _basket_storage[product_item.id]|default(0) %}
  3. {% set product_name =  product_item.name|default(product.name) %}
  4. {% set default_image = product_item.getDefaultImage.uri|default() %}
  5. {% set default_image_id = product_item.getDefaultImage.id|default() %}
  6. {% if product_item.defaultImage %}
  7.     {% set image = asset(product_item.defaultImage.uri) %}
  8. {% elseif product_item.getAvailableImages()|length %}
  9.     {% set image = asset(product_item.defaultImage.uri) %}
  10. {% else %}
  11.     {% set image = asset('img/no_image.jpg') %}
  12. {% endif %}
  13. {% set product_id =  product_item.id %}
  14. {% set product_name =  product_item.name|default(product_item.product.name) %}
  15. {% set product_url = path('mldev-front-product-show', { 'id': product_item.id }) %}
  16. {% set product_price = product_item.price|number_format(0, '', ' ')  %}
  17. {% set product_price_old = product_item.priceOld|number_format(0, '', ' ')  %}
  18. {% set product_price_unit = '₽' %}
  19. {% set product_volume = product_item.volume %}
  20. {% set product_volume_unit = product_item.volumeUnit %}
  21. {% set product_info = {
  22.     id: product_id,
  23.     img: image,
  24.     imgAlt: product_name,
  25.     title: product_name,
  26.     cost: product_price,
  27.     costUnit: product_price_unit,
  28.     discount: product_price_old,
  29.     volume: product_volume,
  30.     volumeUnit: product_volume_unit,
  31.     link: product_url
  32. } %}
  33. <div class="hero">
  34.     <div class="container-fluid">
  35.         <div class="hero__content">
  36.             <div class="swiper info-slider hero-slider">
  37.                 <div class="swiper-wrapper info-slider__items">
  38.                     {% for image in product_item.availableImages %}
  39.                         {% if image.id != default_image_id %}
  40.                             <div class="swiper-slide info-slider__item" style="background: url('{{ image.uri }}') center / cover no-repeat">
  41.                                 <div class="info-slider__item-content">
  42.                                     <div class="info-slider__item-text"></div>
  43.                                 </div>
  44.                             </div>
  45.                         {% endif %}
  46.                     {% endfor %}
  47.                 </div>
  48.                 <div class="swiper-pagination info-slider-pagination hero-slider-pagination"></div>
  49.                 <div class="info-slider-button info-slider-button-prev hero-slider-button-prev">
  50.                     <span>
  51.                         <svg width="33" height="32" viewBox="0 0 33 32" fill="none" xmlns="http://www.w3.org/2000/svg">
  52.                             <path d="M31.2237 17.1053C24.1667 17.1053 17.1096 17.1053 10.0525 17.1053C6.91869 17.1053 6.00627 17.5853 2.89571 18C2.24727 18.0865 2.17738 17.4152 2.4914 16.9525C5.19614 12.9665 8.6107 10.6504 11.9999 7.36717C13.0795 6.32131 14.7537 4.67135 15.3453 3.34032C15.5417 2.89838 16.7804 1.21198 16.0437 2.43981C13.7359 6.28611 9.83728 9.15526 6.90991 12.4925C5.66984 13.9061 4.20773 15.4158 3.36299 17.1053C3.07614 17.679 2.79313 18.3157 2.29708 18.7409C0.888329 19.9484 6.22022 24.1894 7.05693 25.0261C8.59498 26.5642 10.2389 29.6276 12.3681 30.3373" stroke="#6d6c69" stroke-width="3" stroke-linecap="round"/>
  53.                         </svg>
  54.                     </span>
  55.                 </div>
  56.                 <div class="info-slider-button info-slider-button-next hero-slider-button-next">
  57.                     <span>
  58.                         <svg width="35" height="37" viewBox="0 0 35 37" fill="none" xmlns="http://www.w3.org/2000/svg">
  59.                             <path d="M2 15.4858C8.51235 15.4858 15.0247 15.4858 21.5371 15.4858C24.2584 15.4858 27.9971 15.2372 30.5689 16.1838C32.5478 16.9122 29.9738 14.5037 29.5 13.9456C27.7744 11.9132 24.4458 10.5163 22.8732 8.31664C22.5279 7.83367 21.429 6.97932 21.2698 6.32326C20.7737 4.27792 18.6932 4.113 17.2615 2.82609C12.823 -1.16349 26.4966 10.3462 30.4445 14.9962C33.0472 18.0618 34.5099 18.0355 30.593 20.242C27.301 22.0964 24.0961 26.2242 22.0418 29.7193C21.1819 31.1822 20.3328 34.2754 19.1024 35" stroke="#6d6c69" stroke-width="3" stroke-linecap="round"/>
  60.                         </svg>
  61.                     </span>
  62.                 </div>
  63.             </div>
  64.         </div>
  65.     </div>
  66. </div>
  67. {% include '@MLDevCatalog/templates/partials/breadcrumbs.html.twig' %}
  68. <div class="container site__product-container" itemscope itemtype="https://schema.org/Product">
  69.     <div class="site__product" data-product-id="{{ product_id }}" data-product-info="{{ product_info|json_encode }}">
  70.         <div class="site__product-info">
  71.             <h1 class="site__product-title">
  72.                 <div class="site__product-marks">
  73.                     {% if product_item.isNew %}
  74.                         <div class="product-item__new">
  75.                             <img src="/img/icons/new.svg" alt="">
  76.                         </div>
  77.                     {% endif %}
  78.                     {% if product_item.isSale %}
  79.                         <div class="product-item__sale">
  80.                             <img src="/img/icons/sale.svg" alt="">
  81.                         </div>
  82.                     {% endif %}
  83.                 </div>
  84.                 <span itemprop="name">{{ product_name|raw }}</span>
  85.             </h1>
  86.             {% if product_info.img %}
  87.                 <img src="{{ app.request.getSchemeAndHttpHost() }}{{ product_info.img }}" alt="{{ product_info.imgAlt }}" style="display: none;" itemprop="image">
  88.             {% endif %}
  89.             {% if product.ratingScore or product.reviewsCount %}
  90.                 <a href="#reviews" class="site__product-rating">
  91.                     <svg><use xlink:href="/img/sprite_new.svg#star" /></svg>
  92.                     <div class="rating-points">
  93.                         {% if product.ratingScore and product.reviewsCount %}
  94.                             {{ product.ratingScore }} <span>/ {{ product.reviewsCount }} отзывов</span>
  95.                         {% elseif product.ratingScore %}
  96.                             {{ product.ratingScore }}
  97.                         {% elseif product.reviewsCount %}
  98.                             {{ product.reviewsCount }}
  99.                         {% endif %}
  100.                     </div>
  101.                 </a>
  102.             {% endif %}
  103.             <div class="site__product-description">
  104.                 <div class="description-text content" itemprop="description">
  105.                     {{ product.annotation|raw }}
  106.                 </div>
  107.                 <div class="site__product-cart site__product-cart_mobile" itemprop="offers" itemscope itemtype="https://schema.org/Offer">
  108.                     <div class="product-cart__header">
  109.                         <div class="product-cart__pirce">
  110.                             {% if product_item.price > 0 %}
  111.                                 <meta itemprop="price" content="{{ product_price }}">
  112.                                 <meta itemprop="priceCurrency" content="RUB">
  113.                                 {% if product_item.priceOld > 0 %}<span class="product-cart__pirce-old"><price>{{ product_price_old }}</price><s class="product-page__cost-unit"> ₽</s></span><span class="product-cart__volume"> / </span>{% endif %}
  114.                                 {{ product_price }} <span class="product-page__cost-unit">₽</span>{# <span class="product-cart__volume">/ {{ product_volume }} {{ product_volume_unit }}</span> #}
  115.                             {% endif %}
  116.                         </div>
  117.                         <button class="btn-control btn-control-fav" data-favorite type="button">
  118.                             <span class="btn-control__icon">
  119.                                 <svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
  120.                                     <path d="M11.4769 20.0849C10.673 19.0023 9.62237 17.787 8.59332 16.9473C8.25868 16.6742 7.8048 16.0156 7.56804 15.6399C7.29524 15.207 6.62317 14.4126 6.15828 14.2018C5.63801 13.966 5.14534 12.9968 4.87668 12.5096C4.54878 11.9149 3.99567 11.4029 3.58796 10.8681C2.99986 10.0968 2.31606 9.43 2.12836 8.37693C1.95576 7.40857 1.8957 6.57773 2.34908 5.70416C2.83386 4.77007 3.53159 4.40876 4.42812 3.97557C5.91505 3.25709 8.66497 2.88765 10.1953 3.7141C10.5313 3.89555 10.859 4.15402 11.1565 4.39682C11.3678 4.56928 11.7155 5.24141 11.9326 5.30469C12.115 5.35786 12.6796 4.72702 12.9508 4.66555C13.3374 4.57791 13.7216 4.3088 14.1042 4.13535C16.0454 3.25525 19.7732 2.06428 21.4022 4.20072C21.9168 4.87563 21.986 6.29744 21.986 7.11317C21.986 8.26121 22.0956 9.42618 21.7012 10.5123C21.4479 11.21 20.9329 12.0078 20.4196 12.5314C19.1496 13.8269 17.7324 14.9821 16.4467 16.2645C15.213 17.495 13.6926 18.412 12.374 19.5329C11.8811 19.9519 11.2545 20.7212 10.708 21" stroke="currentColor" stroke-width="2.5" stroke-linecap="round"></path>
  121.                                 </svg>
  122.                             </span>
  123.                         </button>
  124.                     </div>
  125.                     {% if product_item.amount > 0 %}
  126.                         <link itemprop="availability" href="http://schema.org/InStock">
  127.                         <div class="product-page__header-controls active-counter" data-product-counter data-product-id="{{ product_id }}">
  128.                             <div class="product-page__header-btns {% if _basket_amount > 0 %}withCounter{% endif %}">
  129.                                 <div class="product-counter-wrapper">
  130.                                     <div class="product-counter product-page__counter product-counter_leafe">
  131.                                         <button class="product-counter__control btn-control btn-control-minus-small" data-product-minus type="button">
  132.                                             <span class="btn-control__icon">
  133.                                                 -
  134.                                             </span>
  135.                                         </button>
  136.                                         <div class="product-counter__info">
  137.                                             <span class="product-counter__num">{{ _basket_amount }}</span>
  138.                                         </div>
  139.                                         <button class="product-counter__control btn-control btn-control-plus-small" data-product-plus type="button">
  140.                                             <span class="btn-control__icon">
  141.                                                 +
  142.                                             </span>
  143.                                         </button>
  144.                                         <input type="hidden" value="{{ _basket_amount }}" data-product-input />
  145.                                     </div>
  146.                                 </div>
  147.                                 <button class="btn btn-action product-page__add-btn btn-action_leafe" type="button" data-product-send data-increase-amount>{% if _basket_amount > 0 %}перейти в корзину{% else %}добавить в корзину{% endif %}</button>
  148.                             </div>
  149.                         </div>
  150.                     {% else %}
  151.                         <link itemprop="availability" href="http://schema.org/OutOfStock">
  152.                         <div class="btn btn-action product-page__add-btn product-page__add-btn-out-of-stock">скоро в продаже</div>
  153.                     {% endif %}
  154.                     <div class="product-cart__block">
  155.                         <div class="product-cart__block-heading">доставка</div>
  156.                         <div class="product-cart__block-description">
  157.                             <p>бесплатная доставка по&nbsp;всей&nbsp;России</p>
  158.                             <p>при&nbsp;заказе от&nbsp;7000&nbsp;рублей</p>
  159.                             {#бесплатная доставка при заказе<br>от 3000 рублей в Москве и Санкт-Петербурге,<br>от 6000 рублей в остальных городах России.#}
  160.                         </div>
  161.                     </div>
  162.                     <div class="product-cart__block">
  163.                         <div class="product-cart__block-heading">варианты объема</div>
  164.                         <div class="product-cart__block-list">
  165.                             {% for variant in product.items|filter(v => v.isActive) %}
  166.                                 <a href="{{ path('mldev-front-product-show', { id: variant.id }) }}" class="item {{ variant.id == product_item.id ? 'current' }}">{{ variant.alterName|default(variant.name) }}</a>
  167.                             {% endfor %}
  168.                         </div>
  169.                     </div>
  170.                     {% if product_item.marketplaceLinkOzon or product_item.marketplaceLinkWildberries or product_item.marketplaceLinkYandexMarket  %}
  171.                         <div class="product-cart__block">
  172.                             <div class="product-cart__block-heading">где еще можно купить</div>
  173.                             <div class="product-cart__block-list">
  174.                                 {% if product_item.marketplaceLinkOzon %}
  175.                                     <a href="{{ product_item.marketplaceLinkOzon }}" target="_blank" class="item">ozon</a>
  176.                                 {% endif %}
  177.                                 {% if product_item.marketplaceLinkWildberries %}
  178.                                     <a href="{{ product_item.marketplaceLinkWildberries }}" target="_blank" class="item">wildberries</a>
  179.                                 {% endif %}
  180.                                 {% if product_item.marketplaceLinkYandexMarket %}
  181.                                     <a href="{{product_item.marketplaceLinkYandexMarket }}" target="_blank" class="item">яндекс.маркет</a>
  182.                                 {% endif %}
  183.                             </div>
  184.                         </div>
  185.                     {% endif %}
  186.                 </div>
  187.                 <div class="description-blocks">
  188.                     {% if product.skin|length %}
  189.                         <div class="item">
  190.                             <div class="item__heading">тип кожи</div>
  191.                             <div class="item__text">{{ product.skin|join(', ')|lower}}</div>
  192.                         </div>
  193.                     {% endif %}
  194.                     {% if product.skinCondition|length %}
  195.                         <div class="item">
  196.                             <div class="item__heading">состояние кожи</div>
  197.                             <div class="item__text">{{ product.skinCondition|join(', ')|lower }}</div>
  198.                         </div>
  199.                     {% endif %}
  200.                     {% if product.aroma|length %}
  201.                         <div class="item">
  202.                             <div class="item__heading">аромат</div>
  203.                             <div class="item__text">{{ product.aroma|join(', ')|lower }}</div>
  204.                         </div>
  205.                     {% endif %}
  206.                     {% if product.effect|length %}
  207.                         <div class="item">
  208.                             <div class="item__heading">результат</div>
  209.                             <div class="item__text">{{ product.effect|join(', ')|lower }}</div>
  210.                         </div>
  211.                     {% endif %}
  212.                     {% if product.hairState|length %}
  213.                         <div class="item">
  214.                             <div class="item__heading">состояние волос</div>
  215.                             <div class="item__text">{{ product.hairState|join(', ')|lower }}</div>
  216.                         </div>
  217.                     {% endif %}
  218.                     {% if product.hairType|length %}
  219.                         <div class="item">
  220.                             <div class="item__heading">тип волос</div>
  221.                             <div class="item__text">{{ product.hairType|join(', ')|lower }}</div>
  222.                         </div>
  223.                     {% endif %}
  224.                 </div>
  225.             </div>
  226.             <div class="site__product-widgets">
  227.                 {% for widget in product.getWidgets() %}
  228.                     {{ mldev_catalog_widget(widget, { product: product, product_item: product_item }) }}
  229.                 {% endfor %}
  230.             </div>
  231.         </div>
  232.         <div class="site__product-cart site__product-cart_desctop">
  233.             <div class="product-cart__heading">{{ product_name|raw }}</div>
  234.             <div class="product-cart__header">
  235.                 <div class="product-cart__pirce">
  236.                     {% if product_item.price > 0 %}
  237.                         {% if product_item.priceOld > 0 %}<span class="product-cart__pirce-old"><price>{{ product_price_old }}</price><s class="product-page__cost-unit"> ₽</s></span><span class="product-cart__volume"> / </span>{% endif %}
  238.                         {{ product_price }} <span class="product-page__cost-unit">₽</span>{# <span class="product-cart__volume">/ {{ product_volume }} {{ product_volume_unit }}</span> #}
  239.                     {% endif %}
  240.                 </div>
  241.                         
  242.                 <button class="btn-control btn-control-fav" data-favorite type="button">
  243.                     <span class="btn-control__icon">
  244.                         <svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
  245.                             <path d="M11.4769 20.0849C10.673 19.0023 9.62237 17.787 8.59332 16.9473C8.25868 16.6742 7.8048 16.0156 7.56804 15.6399C7.29524 15.207 6.62317 14.4126 6.15828 14.2018C5.63801 13.966 5.14534 12.9968 4.87668 12.5096C4.54878 11.9149 3.99567 11.4029 3.58796 10.8681C2.99986 10.0968 2.31606 9.43 2.12836 8.37693C1.95576 7.40857 1.8957 6.57773 2.34908 5.70416C2.83386 4.77007 3.53159 4.40876 4.42812 3.97557C5.91505 3.25709 8.66497 2.88765 10.1953 3.7141C10.5313 3.89555 10.859 4.15402 11.1565 4.39682C11.3678 4.56928 11.7155 5.24141 11.9326 5.30469C12.115 5.35786 12.6796 4.72702 12.9508 4.66555C13.3374 4.57791 13.7216 4.3088 14.1042 4.13535C16.0454 3.25525 19.7732 2.06428 21.4022 4.20072C21.9168 4.87563 21.986 6.29744 21.986 7.11317C21.986 8.26121 22.0956 9.42618 21.7012 10.5123C21.4479 11.21 20.9329 12.0078 20.4196 12.5314C19.1496 13.8269 17.7324 14.9821 16.4467 16.2645C15.213 17.495 13.6926 18.412 12.374 19.5329C11.8811 19.9519 11.2545 20.7212 10.708 21" stroke="currentColor" stroke-width="2.5" stroke-linecap="round"></path>
  246.                         </svg>
  247.                     </span>
  248.                 </button>
  249.             </div>
  250.             {% if product_item.amount > 0 %}
  251.                 <div class="product-page__header-controls active-counter" data-product-counter data-product-id="{{ product_id }}">
  252.                     <div class="product-page__header-btns {% if _basket_amount > 0 %}withCounter{% endif %}">
  253.                         <div class="product-counter-wrapper">
  254.                             <div class="product-counter product-page__counter product-counter_leafe">
  255.                                 <button class="product-counter__control btn-control btn-control-minus-small" data-product-minus type="button">
  256.                                     <span class="btn-control__icon">
  257.                                         -
  258.                                     </span>
  259.                                 </button>
  260.                                 <div class="product-counter__info">
  261.                                     <span class="product-counter__num">{{ _basket_amount }}</span>
  262.                                 </div>
  263.                                 <button class="product-counter__control btn-control btn-control-plus-small" data-product-plus type="button">
  264.                                     <span class="btn-control__icon">
  265.                                         +
  266.                                     </span>
  267.                                 </button>
  268.                                 <input type="hidden" value="{{ _basket_amount }}" data-product-input />
  269.                             </div>
  270.                         </div>
  271.                         <button class="btn btn-action product-page__add-btn btn-action_leafe" type="button" data-product-send data-increase-amount>{% if _basket_amount > 0 %}перейти в корзину{% else %}добавить в корзину{% endif %}</button>
  272.                     </div>
  273.                 </div>
  274.             {% else %}
  275.                 <div class="btn btn-action product-page__add-btn product-page__add-btn-out-of-stock">скоро в продаже</div>
  276.             {% endif %}
  277.             <div class="product-cart__block">
  278.                 <div class="product-cart__block-heading">доставка</div>
  279.                 <div class="product-cart__block-description">
  280.                     <p>бесплатная доставка по&nbsp;всей&nbsp;России</p>
  281.                     <p>при&nbsp;заказе от&nbsp;7000&nbsp;рублей</p>
  282.                     {#бесплатная доставка при заказе<br>от 3000 рублей в Москве и Санкт-Петербурге,<br>от 6000 рублей в остальных городах России.#}
  283.                 </div>
  284.             </div>
  285.             <div class="product-cart__block">
  286.                 <div class="product-cart__block-heading">варианты объема</div>
  287.                 <div class="product-cart__block-list">
  288.                     {% for variant in product.items|filter(v => v.isActive) %}
  289.                         <a href="{{ path('mldev-front-product-show', { id: variant.id }) }}" class="item {{ variant.id == product_item.id ? 'current' }}">{{ variant.alterName|default(variant.name) }}</a>
  290.                     {% endfor %}
  291.                 </div>
  292.             </div>
  293.             {% if product_item.marketplaceLinkOzon or product_item.marketplaceLinkWildberries or product_item.marketplaceLinkYandexMarket  %}
  294.                 <div class="product-cart__block">
  295.                     <div class="product-cart__block-heading">где еще можно купить</div>
  296.                     <div class="product-cart__block-list">
  297.                         {% if product_item.marketplaceLinkOzon %}
  298.                             <a href="{{ product_item.marketplaceLinkOzon }}" target="_blank" class="item">ozon</a>
  299.                         {% endif %}
  300.                         {% if product_item.marketplaceLinkWildberries %}
  301.                             <a href="{{ product_item.marketplaceLinkWildberries }}" target="_blank" class="item">wildberries</a>
  302.                         {% endif %}
  303.                         {% if product_item.marketplaceLinkYandexMarket %}
  304.                             <a href="{{product_item.marketplaceLinkYandexMarket }}" target="_blank" class="item">яндекс.маркет</a>
  305.                         {% endif %}
  306.                     </div>
  307.                 </div>
  308.             {% endif %}
  309.         </div>
  310.         {% if product_item.amount > 0 %}
  311.             <div class="product-page__add-to-cart">
  312.                 <span>{{ product_name|raw }}<br>{{ product_price }} <span class="product-page__cost-unit">₽</span> <span>/ {{ product_volume }} {{ product_volume_unit }}</span></span>
  313.                 <div class="product-page__add-to-cart-button" data-product-send data-increase-amount>{% if _basket_amount > 0 %}перейти в корзину{% else %}добавить в корзину{% endif %}</div>
  314.             </div>
  315.         {% endif %}
  316.     </div>
  317. </div>
  318. {% include 'widget/promocode/default.html.twig' with { title: 'получите скидку 5%', subtitle: 'за подписку на нашу рассылку'} %}
  319. <script>
  320.     document.body.classList.add('product-page')
  321.     const productTitle = document.querySelector('.site__product-title')
  322.     const productCartTitle = document.querySelector('.product-cart__heading')
  323.     window.onscroll = (e) => {
  324.         const productTitleOffset = productTitle.getBoundingClientRect().top
  325.         if(productTitleOffset < 0) productCartTitle.classList.add('visible')
  326.         else productCartTitle.classList.remove('visible')
  327.     }
  328.     setTimeout(() => {
  329.         dataLayer.push({ ecommerce: null })
  330.         dataLayer.push({
  331.           event: "view_item",
  332.           ecommerce: {
  333.             items: [{
  334.               item_name: "{{ product_name }}",
  335.               item_id: "{{ product_id }}",
  336.               price: {{ product_item.price|number_format(0, '', '') }},
  337.               index: 1,
  338.               quantity: 1
  339.             }]
  340.           }
  341.         });
  342.     }, 2000)
  343. </script>
  344. <script>
  345.     async function getProductCount(id) {
  346.         try {
  347.             const cart = await window.mldev.cartAction.getCartDetails().then((data) => data.items[id])
  348.             return cart;
  349.         } catch (err) {
  350.             console.log(err);
  351.         }
  352.     }
  353.     const productCounter = document.querySelector('[data-product-counter]');
  354.     const inputCounter = document.querySelectorAll('[data-product-input]');
  355.     const controlPlus = document.querySelectorAll('[data-product-plus]')
  356.     const controlMinus = document.querySelectorAll('[data-product-minus]')
  357.     const productAddBtn = document.querySelectorAll('[data-product-send]')
  358.     const numEl = document.querySelectorAll('.product-counter__num');
  359.     const productId = productCounter.dataset.productId
  360.     getProductCount(productId).then(res => {
  361.         console.log(res?.count?.value)
  362.         if(res?.count?.value > 0){
  363.             document.querySelectorAll('.product-page__header-btns').forEach(w => {
  364.                 w.classList.add('withCounter')
  365.             })
  366.             productAddBtn.forEach(b => {
  367.                 if(b.innerText != 'перейти в корзину') return
  368.                 b.innerText = 'перейти в корзину'
  369.                 b.addEventListener('click', e => {
  370.                     e.preventDefault
  371.                     window.location.href = '/cart'
  372.                 })
  373.             })
  374.         }
  375.     })
  376.     function resetValue(val) {
  377.         inputCounter.forEach(el => el.value = 1)
  378.         numEl.forEach(el => el.textContent = 1)
  379.     }
  380.     async function addToCart(newValue = null) {
  381.         const inCartValue = await getProductCount(productId).then(res => res?.count?.value)
  382.         const inputCounterCurrent = document.querySelectorAll('[data-product-input]')
  383.         if(!newValue) newValue = inCartValue ? (Number(inCartValue) + Number(inputCounterCurrent[0].value)) : inputCounterCurrent[0].value
  384.         window.mldev.cartAction.setToCart(productId, newValue)
  385.     }
  386.     function changeValue(val) {
  387.         let currentValue
  388.         inputCounter.forEach(el => {
  389.             if (+el.value <= 1 && val === -1) return
  390.             currentValue = +el.value + val
  391.             el.value = currentValue
  392.             numEl.forEach(el => el.textContent = currentValue)
  393.         })
  394.         addToCart(currentValue)
  395.     }
  396.     controlPlus.forEach(el => el.addEventListener('click', () => changeValue(1)))
  397.     controlMinus.forEach(el => el.addEventListener('click', () => changeValue(-1)))
  398.     productAddBtn.forEach(el => {
  399.         el.addEventListener('click', () => {
  400.             if(el.innerText != 'перейти в корзину'){
  401.                 changeValue(1)
  402.                 productAddBtn.forEach(b => b.innerText = 'перейти в корзину')
  403.                 document.querySelectorAll('.product-page__header-btns').forEach(w => {
  404.                     w.classList.add('withCounter')
  405.                 })
  406.             }
  407.             else window.location.href = '/cart'
  408.         })
  409.     })
  410.     r46("track", "view", {
  411.         id: "{{ product_id }}",
  412.         stock: {% if product_item.amount > 0 %}true{% else %}false{% endif %}
  413.     });
  414. </script>