custom/plugins/Confi/src/Resources/views/storefront/page/product-detail/index.html.twig line 1

Open in your IDE?
  1. {% sw_extends '@Storefront/storefront/page/product-detail/index.html.twig' %}
  2. {% block base_content %}
  3.     {% block page_product_detail %}
  4.         {% if page.confi is defined %}
  5. {#        <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/css/bootstrap.min.css"#}
  6. {#              integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u"#}
  7. {#              crossorigin="anonymous">#}
  8.         <style>
  9.             /*.cf .row {*/
  10.             /*    display: block;*/
  11.             /*}*/
  12.             /*.cf .hidden {*/
  13.             /*    display: none;*/
  14.             /*}*/
  15.             /*confiapp, .cf, .cf #cf-body {*/
  16.             /*    min-height: 2000px;*/
  17.             /*}*/
  18.             /*.cf #cf-preview {*/
  19.             /*    float: left;*/
  20.             /*}*/
  21.             .modal-backdrop.modal-backdrop-open{
  22.                 opacity: 0.6;
  23.             }
  24.             .fade {
  25.                 opacity: initial;
  26.             }
  27.         </style>
  28.         <div>
  29.             {{ page.confi.css|raw }}
  30.             {{ page.confi.js|raw }}
  31.             {{ page.confi.body|raw }}
  32.             <form
  33.                     id="productDetailPageBuyProductForm"
  34.                     action="{% block page_product_detail_buy_form_action %}{{ path('frontend.checkout.line-item.add') }}{% endblock %}"
  35.                     method="post"
  36.                     class="buy-widget"
  37.                     data-add-to-cart="true">
  38.                 {% block page_product_detail_buy_form_inner_csrf %}
  39.                     {{ sw_csrf('frontend.checkout.line-item.add') }}
  40.                 {% endblock %}
  41. {#                {% set buyable = product.available and product.childCount <= 0 and product.calculatedMaxPurchase > 0 %}#}
  42. {#                {% block page_product_detail_buy_container %}#}
  43. {#                    {% if buyable %}#}
  44. {#                        <div class="{{ formRowClass }} buy-widget-container">#}
  45. {#                            {% block page_product_detail_buy_quantity_container %}#}
  46. {#                                <div class="col-4">#}
  47. {#                                    {% block page_product_detail_buy_quantity %}#}
  48. {#                                        <select name="lineItems[{{ product.id }}][quantity]"#}
  49. {#                                                class="{{ formSelectClass }} product-detail-quantity-select">#}
  50. {#                                            {% for quantity in range(product.minPurchase, product.calculatedMaxPurchase, product.purchaseSteps) %}#}
  51. {#                                                <option value="{{ quantity }}">#}
  52. {#                                                    {{ quantity }}#}
  53. {#                                                    {% if quantity == 1 %}#}
  54. {#                                                        {% if product.translated.packUnit %} {{ product.translated.packUnit }}{% endif %}#}
  55. {#                                                    {% else %}#}
  56. {#                                                        {% if product.translated.packUnitPlural %}#}
  57. {#                                                            {{ product.translated.packUnitPlural }}#}
  58. {#                                                        {% elseif product.translated.packUnit %}#}
  59. {#                                                            {{ product.translated.packUnit }}#}
  60. {#                                                        {% endif %}#}
  61. {#                                                    {% endif %}#}
  62. {#                                                </option>#}
  63. {#                                            {% endfor %}#}
  64. {#                                        </select>#}
  65. {#                                    {% endblock %}#}
  66. {#                                </div>#}
  67. {#                            {% endblock %}#}
  68. {#                            {% block page_product_detail_buy_redirect_input %}#}
  69. {#                                #}{# fallback redirect back to detail page is deactivated via js #}
  70. {#                                <input type="hidden"#}
  71. {#                                       name="redirectTo"#}
  72. {#                                       value="frontend.detail.page">#}
  73. {#                                <input type="hidden"#}
  74. {#                                       name="redirectParameters"#}
  75. {#                                       data-redirect-parameters="true"#}
  76. {#                                       value='{"productId": "{{ product.id }}"}'>#}
  77. {#                            {% endblock %}#}
  78. {#                            {% block page_product_detail_buy_product_buy_info %}#}
  79. {#                                <input type="hidden"#}
  80. {#                                       name="lineItems[{{ product.id }}][id]"#}
  81. {#                                       value="{{ product.id }}">#}
  82. {#                                <input type="hidden"#}
  83. {#                                       name="lineItems[{{ product.id }}][type]"#}
  84. {#                                       value="product">#}
  85. {#                                <input type="hidden"#}
  86. {#                                       name="lineItems[{{ product.id }}][referencedId]"#}
  87. {#                                       value="{{ product.id }}">#}
  88. {#                                <input type="hidden"#}
  89. {#                                       name="lineItems[{{ product.id }}][stackable]"#}
  90. {#                                       value="1">#}
  91. {#                                <input type="hidden"#}
  92. {#                                       name="lineItems[{{ product.id }}][removable]"#}
  93. {#                                       value="1">#}
  94. {#                            {% endblock %}#}
  95. {#                            {% block page_product_detail_product_buy_meta %}#}
  96. {#                                <input type="hidden"#}
  97. {#                                       name="product-name"#}
  98. {#                                       value="{{ product.translated.name }}">#}
  99. {#                                <input type="hidden"#}
  100. {#                                       name="brand-name"#}
  101. {#                                       value="{{ product.manufacturer.getName() }}">#}
  102. {#                            {% endblock %}#}
  103. {#                            {% block page_product_detail_buy_button_container %}#}
  104. {#                                <div class="col-8">#}
  105. {#                                    {% block page_product_detail_buy_button %}#}
  106. {#                                        #}{# @deprecated tag:v6.5.0 - Bootstrap v5 removes `btn-block` class, use `d-grid` wrapper instead #}
  107. {#                                        {% if feature('v6.5.0.0') %}#}
  108. {#                                            <div class="d-grid">#}
  109. {#                                                <button class="btn btn-primary btn-buy"#}
  110. {#                                                        title="{{ "detail.addProduct"|trans|striptags }}"#}
  111. {#                                                        aria-label="{{ "detail.addProduct"|trans|striptags }}">#}
  112. {#                                                    {{ "detail.addProduct"|trans|sw_sanitize }}#}
  113. {#                                                </button>#}
  114. {#                                            </div>#}
  115. {#                                        {% else %}#}
  116. {#                                            <button class="btn btn-primary btn-block btn-buy"#}
  117. {#                                                    title="{{ "detail.addProduct"|trans|striptags }}"#}
  118. {#                                                    aria-label="{{ "detail.addProduct"|trans|striptags }}">#}
  119. {#                                                {{ "detail.addProduct"|trans|sw_sanitize }}#}
  120. {#                                            </button>#}
  121. {#                                        {% endif %}#}
  122. {#                                    {% endblock %}#}
  123. {#                                </div>#}
  124. {#                            {% endblock %}#}
  125. {#                        </div>#}
  126. {#                    {% endif %}#}
  127. {#                {% endblock %}#}
  128.             </form>
  129.         </div>
  130.         <script>
  131.             function is(className, object) {
  132.                 return Object.prototype.toString.call(object) === '[object '+ className +']';
  133.             }
  134.             const DataEncoder = function() {
  135.                 this.levels = [];
  136.                 this.actualKey = null;
  137.             }
  138.             DataEncoder.prototype.__dataEncoding = function(data) {
  139.                 let uriPart = '';
  140.                 const levelsSize = this.levels.length;
  141.                 if (levelsSize) {
  142.                     uriPart = this.levels[0];
  143.                     for(let c = 1; c < levelsSize; c++) {
  144.                         uriPart += '[' + this.levels[c] + ']';
  145.                     }
  146.                 }
  147.                 let finalString = '';
  148.                 if (is('Object', data)) {
  149.                     const keys = Object.keys(data);
  150.                     const l = keys.length;
  151.                     for(let a = 0; a < l; a++) {
  152.                         const key = keys[a];
  153.                         let value = data[key];
  154.                         this.actualKey = key;
  155.                         this.levels.push(this.actualKey);
  156.                         finalString += this.__dataEncoding(value);
  157.                     }
  158.                 } else if (is('Array', data)) {
  159.                     if (!this.actualKey) throw new Error("Directly passed array does not work")
  160.                     const aSize = data.length;
  161.                     for (let b = 0; b < aSize; b++) {
  162.                         let aVal = data[b];
  163.                         this.levels.push(b);
  164.                         finalString += this.__dataEncoding(aVal);
  165.                     }
  166.                 } else {
  167.                     finalString += uriPart + '=' + encodeURIComponent(data) + '&';
  168.                 }
  169.                 this.levels.pop();
  170.                 return finalString;
  171.             }
  172.             DataEncoder.prototype.encode = function(data) {
  173.                 if (!is('Object', data) || !Object.keys(data).length) return null;
  174.                 return this.__dataEncoding(data).slice(0, -1);
  175.             }
  176.             window.addEventListener('DOMContentLoaded', (event) => {
  177.                 confi = {
  178.                     addToCart: function (config, thumbnail) {
  179.                         // var loading = '<div id="loading" style="z-index: 999; position: absolute; top: 0; left: 0; right: 0; bottom: 0; background: rgba(255,255,255,0.7);"><img src="" style="position: fixed; width: 40px; height: 40px; margin-top: -20px; margin-left: -20px; top: 50%; left: 50%;"/></div>';
  180.                         // $('.content-main').append(loading);
  181.                         var configurated = JSON.parse(config);
  182.                         var quantity = configurated.configurator.qty;
  183.                         var myData = {
  184.                             '_csrf_token': '{{ sw_csrf('frontend.confi.addtocart.controller', {"mode": "token"}) }}',
  185.                             'config': configurated,
  186.                             'thumbnail': thumbnail,
  187.                             'id': '{{ page.product.id }}',
  188.                             'quantity': quantity
  189.                         };
  190.                         const encoder = new DataEncoder();
  191.                         var uri = encoder.encode(myData);
  192.                         var request = new XMLHttpRequest();
  193.                         request.open('POST', '/addtocart', true);
  194.                         request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded;');
  195.                         request.onload = function () {
  196.                             if (this.status >= 200 && this.status < 400) {
  197.                                 const plugin = window.PluginManager.getPluginInstanceFromElement(document.querySelector('[data-add-to-cart]'), 'AddToCart');
  198.                                 plugin._openOffCanvasCarts('/checkout/offcanvas', '');
  199.                                 plugin.$emitter.publish('openOffCanvasCart');
  200.                             } else {
  201.                                 console.log(this.response);
  202.                             }
  203.                         };
  204.                         request.onerror = function() {
  205.                             // Connection error
  206.                         };
  207.                         request.send(uri);
  208.                         {#$.ajax({#}
  209.                         {#    type: "POST",#}
  210.                         {#    cache: false,#}
  211.                         {#    url: '/addtocart',#}
  212.                         {#    async: true,#}
  213.                         {#    data: {#}
  214.                         {#        '_csrf_token': '{{ sw_csrf('frontend.confi.addtocart.controller', {"mode": "token"}) }}',#}
  215.                         {#        'config': configurated,#}
  216.                         {#        'thumbnail': thumbnail,#}
  217.                         {#        'id': '{{ page.product.id }}',#}
  218.                         {#        'quantity': quantity#}
  219.                         {#    },#}
  220.                         {#    success: function (data) {#}
  221.                         {#        console.log(document.querySelector('[data-add-to-cart]'));#}
  222.                         {#        const plugin = window.PluginManager.getPluginInstanceFromElement(document.querySelector('[data-add-to-cart]'), 'AddToCart');#}
  223.                         {#        plugin._openOffCanvasCarts('/checkout/offcanvas', '');#}
  224.                         {#        plugin.$emitter.publish('openOffCanvasCart');#}
  225.                         {#    }, error: function (xhr, ajaxOptions, thrownError) {#}
  226.                         {#        console.log(thrownError);#}
  227.                         {#    }#}
  228.                         {#});#}
  229.                     }
  230.                 };
  231.             });
  232.         </script>
  233.         {% endif %}
  234.         <div class="product-detail"
  235.              itemscope
  236.              itemtype="https://schema.org/Product">
  237.             {% block page_product_detail_inner %}
  238.                 {% block page_product_detail_content %}
  239.                     <div class="product-detail-content">
  240.                         {% block page_product_detail_headline %}
  241. {#                            {% if page.confi is not defined %}#}
  242.                             <div class="row align-items-center product-detail-headline">
  243.                                 {% sw_include '@Storefront/storefront/page/product-detail/headline.html.twig' %}
  244.                             </div>
  245. {#                            {% endif %}#}
  246.                         {% endblock %}
  247.                         {% set mediaItems = page.product.media.media %}
  248.                         {% block page_product_detail_main %}
  249.                             {% if page.confi is not defined %}
  250.                             <div class="row product-detail-main">
  251.                                 {% block page_product_detail_media %}
  252.                                     <div class="col-lg-7 product-detail-media">
  253.                                         {% if page.product.media %}
  254.                                             {% sw_include '@Storefront/storefront/element/cms-element-image-gallery.html.twig' with {
  255.                                                 'mediaItems': mediaItems,
  256.                                                 'zoom': true,
  257.                                                 'zoomModal': true,
  258.                                                 'displayMode': 'contain',
  259.                                                 'gutter': 5,
  260.                                                 'minHeight': '430px',
  261.                                                 'navigationArrows': 'inside',
  262.                                                 'navigationDots': 'inside',
  263.                                                 'galleryPosition': 'left',
  264.                                                 'isProduct': true,
  265.                                                 'fallbackImageTitle': page.product.translated.name,
  266.                                                 'startIndexThumbnails': 1,
  267.                                                 'startIndexSlider': 1,
  268.                                                 'keepAspectRatioOnZoom': false
  269.                                             } %}
  270.                                         {% endif %}
  271.                                     </div>
  272.                                 {% endblock %}
  273.                                 {% block page_product_detail_buy %}
  274.                                     <div class="col-lg-5 product-detail-buy">
  275.                                         {% sw_include '@Storefront/storefront/page/product-detail/buy-widget.html.twig' %}
  276.                                     </div>
  277.                                 {% endblock %}
  278.                             </div>
  279.                             {% endif %}
  280.                         {% endblock %}
  281.                     </div>
  282.                 {% endblock %}
  283.                 {% block page_product_detail_tabs %}
  284.                     <div class="product-detail-tabs">
  285.                         {% sw_include '@Storefront/storefront/page/product-detail/tabs.html.twig' %}
  286.                     </div>
  287.                 {% endblock %}
  288.                 {% block page_product_detail_cross_selling %}
  289.                     {% if page.crossSellings.elements is defined and page.crossSellings.elements|filter(item => item.total > 0)|length > 0 %}
  290.                         <div class="product-detail-tabs product-detail-cross-selling">
  291.                             {% sw_include '@Storefront/storefront/page/product-detail/cross-selling/tabs.html.twig' with {
  292.                                 crossSellings: page.crossSellings
  293.                             } %}
  294.                         </div>
  295.                     {% endif %}
  296.                 {% endblock %}
  297.             {% endblock %}
  298.         </div>
  299.     {% endblock %}
  300. {% endblock %}