custom/plugins/PixupWishlistSW6/src/Resources/views/storefront/layout/header/header.html.twig line 1

Open in your IDE?
  1. {% sw_extends '@Storefront/storefront/layout/header/header.html.twig' %}
  2. {% block layout_header_actions_cart %}
  3.     {% block pixup_wishlist_header_actions_cart %}
  4.         <script>
  5.             window.pixupWishlistGlobalCookie = {{ page.header.pixup.requiredCookie ? 1 : 0 }};
  6.         </script>
  7.         <div class="col-auto">
  8.             <div class="header-cart">
  9.                 <a class="btn header-cart-btn header-actions-btn PixupWishlistPageIcon"
  10.                    href="{{ path('frontend.pixup.wishlist.overview') }}"
  11.                    title="{{  "pixup-wishlist.actions.name"|trans }}">
  12.                     <div class="PixupWishlistProductCount" id="wishlistProductCount">{{ page.header.pixup.antiCacheMode || page.header.pixup.fullAjaxMode ? 0 : page.header.pixup.wishlistProductCount }}</div>
  13.                     <span class="header-cart-icon">
  14.                         {% sw_icon 'heart' %}
  15.                     </span>
  16.                     {#{  "pixup-wishlist.actions.name"|trans }#}
  17.                 </a>
  18.             </div>
  19.         </div>
  20.     {% endblock %}
  21.     {#Content for: add-to-wishlist-button.html.twig #}
  22.     <!-- Modal -->
  23.     {% block pixup_wishlist_header_actions_part_modal %}
  24.         <div class="modal fade" id="pixupWishlist_chooseWishlistModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
  25.             <div class="modal-dialog" role="document">
  26.                 <div class="modal-content">
  27.                     <div class="modal-header">
  28.                         <h5 class="modal-title" style="margin-left:0.3em;"><span>{% sw_icon 'px-heart' style{"namespace":"PixupWishlistSW6","pack":"pixup","class":"PixupAddToWishlistRemoveIcon pixupBaseIcon pxOutlineWhite"} %} &thinsp;</span><span id="pixupWishlistSelect_title">{{  "pixup-wishlist.product-detail.modal.add.title"|trans }}</span></h5>
  29.                         <br>
  30.                         <button type="button" class="close" data-dismiss="modal" aria-label="Close">
  31.                             <span aria-hidden="true">&times;</span>
  32.                         </button>
  33.                     </div>
  34.                     <div class="modal-body" style="padding:0">
  35.                         <div class="modal-title PixupCechBoxGroupTitle" id="pixupWishlist_description">{{  "pixup-wishlist.product-detail.modal.add.description"|trans }}</div>
  36.                         <div id="pixupWishlist_chooseWishlistModal_body_select">
  37.                         </div>
  38.                     </div>
  39.                     <div class="modal-footer">
  40.                         <button type="button" class="btn btn-secondary" data-dismiss="modal">{{  "pixup-wishlist.product-detail.modal.close"|trans }}</button>
  41.                         <button id="pixupWishlist_save" type="button" class="btn btn-primary">{{  "pixup-wishlist.product-detail.modal.add.confirm"|trans }}</button>
  42.                     </div>
  43.                 </div>
  44.             </div>
  45.         </div>
  46.         <script>
  47.             {% if page.header.pixup.antiCacheMode || page.header.pixup.fullAjaxMode %}
  48.             function loadWishlistAsync() {
  49.                 pixupWishlist_ajaxCore("{{ url('frontend.pixup.wishlist.products') }}", function (xhttp) {
  50.                     let res = JSON.parse(xhttp.responseText);
  51.                     const data = res.data;
  52.                     if (res.error.success === true) {
  53.                         let wishlists = data.wishlists;
  54.                         let productCount = 0;
  55.                         for (let wishlist of wishlists) {
  56.                             for (let productId in wishlist.products) {
  57.                                 productCount++;
  58.                                 let productElemente = document.getElementsByClassName('Pixup-Wishlist-Product-' + productId);
  59.                                 for (let i = 0; i < productElemente.length; i++) {
  60.                                     productElemente[i].dataset.remove = true;
  61.                                     let collection = productElemente[i].getElementsByClassName('add');
  62.                                     for (let i = 0; i < collection.length; i++) {
  63.                                         collection[i].style.display = 'none';
  64.                                     }
  65.                                     collection = productElemente[i].getElementsByClassName('remove');
  66.                                     for (let i = 0; i < collection.length; i++) {
  67.                                         collection[i].style.display = 'block';
  68.                                     }
  69.                                 }
  70.                             }
  71.                         }
  72.                         document.getElementById('wishlistProductCount').innerHTML = productCount;
  73.                     } else {
  74.                         console.log('fehler Pixup WistlistProdcts');
  75.                     }
  76.                 });
  77.             }
  78.             loadWishlistAsync();
  79.             {% endif %}
  80.             function substrectOneFromWLHeader(){
  81.                 wishlistCount = document.getElementById("wishlistProductCount");
  82.                 currentCount = wishlistCount.innerHTML;
  83.                 wishlistCount.innerHTML = (parseInt(currentCount,0)-1).toString();
  84.             }
  85.             function addOneFromWLHeader(){
  86.                 wishlistCount = document.getElementById("wishlistProductCount");
  87.                 currentCount = wishlistCount.innerHTML;
  88.                 wishlistCount.innerHTML = (parseInt(currentCount,0)+1).toString();
  89.             }
  90.             function pixupWishlist_changeProductWishlistStateInit(elem,remove,productID,wishlistId=null,applyStyle=true){
  91.                 if(remove === 'true' || remove === true)
  92.                     baseUrl = "{{ url('frontend.pixup.wishlist.ajax.remove_product', {'productId': '--product-id--','wishlistId': '--wishListId--'})  }}";
  93.                 else
  94.                     baseUrl = "{{ url('frontend.pixup.wishlist.ajax.add_product', {'productId': '--product-id--','wishlistId': '--wishListId--'})  }}";
  95.                 baseUrl = baseUrl.replace(/--product-id--/, productID).replace(/--wishListId--/,wishlistId);
  96.                 pixupWishlist_ajaxCore(baseUrl,pixupWishlist_changeProductWishlistStateHandler,[elem,baseUrl,productID,remove,wishlistId,applyStyle]);
  97.             }
  98.             function pixupWishlist_changeProductWishlistStateHandler(xhttp,elem,baseUrl,productID,removeProduct,wishlistId=null,applyStyle=true){
  99.                 removeProductMsg = "{{ "pixup-wishlist.product-detail.deleteProduct"|trans }}";
  100.                 addProductMsg = "{{ "pixup-wishlist.product-detail.addProduct"|trans }}";
  101.                 data = JSON.parse(xhttp.responseText).data;
  102.                 if(data.productOnWishlist === false && data.success) { // product removed
  103.                     substrectOneFromWLHeader();
  104.                     if(applyStyle) {
  105.                         elem.title = addProductMsg;
  106.                         elem.children[0].style.display = "inline-block";
  107.                         elem.children[1].style.display = "none";
  108.                         elem.dataset.remove = false;
  109.                     }
  110.                 }else if(data.success){ // product added
  111.                     addOneFromWLHeader();
  112.                     if(applyStyle) {
  113.                         elem.title = removeProductMsg;
  114.                         elem.children[0].style.display = "none";
  115.                         elem.children[1].style.display = "inline-block";
  116.                         elem.dataset.remove = true;
  117.                     }
  118.                 }else if(!data.success && data.wishListIdRequired){ // cant perform action on product because multiple wishlists exsist
  119.                     //get all wishlists
  120.                     let url = "{{ url('frontend.pixup.wishlist.ajax.get_wishlists',{'productId': '--product-id--'})  }}";
  121.                     url = url.replace(/--product-id--/, "");
  122.                     pixupWishlist_ajaxCore(url,pixupWishlists_selectWishlist,[elem,productID])
  123.                 }
  124.             }
  125.             function pixupWishlists_selectWishlist(xhttp,elem,productID){
  126.                 var safeBtn = document.getElementById('pixupWishlist_save');
  127.                 var description = document.getElementById('pixupWishlist_description');
  128.                 var title = document.getElementById("pixupWishlistSelect_title");
  129.                 var select = document.getElementById("pixupWishlist_chooseWishlistModal_body_select");
  130.                 var data = JSON.parse(xhttp.responseText).data.wishlists;
  131.                 var addDescription = "{{  "pixup-wishlist.product-detail.modal.add.description"|trans }}";
  132.                 var addConfirm = "{{  "pixup-wishlist.product-detail.modal.add.confirm"|trans }}";
  133.                 var addTitle = "{{  "pixup-wishlist.product-detail.modal.add.title"|trans }}";
  134.                 var removeDescription = "{{  "pixup-wishlist.product-detail.modal.remove.description"|trans }}";
  135.                 var removeConfirm = "{{  "pixup-wishlist.product-detail.modal.remove.confirm"|trans }}";
  136.                 var removeTitle = "{{  "pixup-wishlist.product-detail.modal.remove.title"|trans }}";
  137.                 //clear old event Listener ( so only one function can listen on it )
  138.                 safeBtnClone = safeBtn.cloneNode(true);
  139.                 //set listener
  140.                 safeBtnClone.addEventListener("click", function(){
  141.                     //get all selected checkboxes and send the value to the changeState function
  142.                     var all_checkboxes = document.querySelectorAll('input[name="pixupWishlistCheckBoxWishlistSelector[]"]');
  143.                     productOnOneWishlist = false;
  144.                     for(var x = 0, l = all_checkboxes.length; x < l;  x++) {
  145.                         if(all_checkboxes[x].checked === true)
  146.                             productOnOneWishlist = true;
  147.                         if(all_checkboxes[x].dataset.isOnWishlist === "true" && all_checkboxes[x].checked === true && all_checkboxes[x].value !== "-1" ||
  148.                             all_checkboxes[x].dataset.isOnWishlist === "false"  && all_checkboxes[x].checked === false)
  149.                             continue;
  150.                         pixupWishlist_changeProductWishlistStateInit(
  151.                             elem,
  152.                             !all_checkboxes[x].checked,
  153.                             productID,
  154.                             all_checkboxes[x].value,
  155.                             false
  156.                         );
  157.                     }
  158.                     if(productOnOneWishlist === true){
  159.                         elem.title = removeProductMsg;
  160.                         elem.children[0].style.display = "none";
  161.                         elem.children[1].style.display = "inline-block";
  162.                         elem.dataset.remove = true;
  163.                     }else{
  164.                         elem.title = addProductMsg;
  165.                         elem.children[0].style.display = "inline-block";
  166.                         elem.children[1].style.display = "none";
  167.                         elem.dataset.remove = false;
  168.                     }
  169.                     $('#pixupWishlist_chooseWishlistModal').modal('hide')
  170.                 });
  171.                 safeBtn = safeBtn.parentNode.replaceChild(safeBtnClone, safeBtn);
  172.                 //delete options
  173.                 select.innerHTML = "";
  174.                 //set proper messages
  175.                 if(elem.dataset.remove === 'true'){
  176.                     safeBtn.innerHTML = removeConfirm;
  177.                     description.innerHTML = removeDescription;
  178.                     title.innerHTML = removeTitle;
  179.                 }else{
  180.                     safeBtn.innerHTML = addConfirm;
  181.                     description.innerHTML = addDescription;
  182.                     title.innerHTML = addTitle;
  183.                 }
  184.                 //create a checkbox for every recieved wishlist ( subscribed wishlists excluded )
  185.                 ownWishlistAdded = false;
  186.                 for(i=0;i<data.length;i++){
  187.                     if(data[i].subscribed === true)
  188.                         continue;
  189.                     ownWishlistAdded = true;
  190.                     select.appendChild(createCheckbox(data[i],productID));
  191.                 }
  192.                 //if no wishlist exsist
  193.                 if(ownWishlistAdded === false){
  194.                     customData = {name:"{{ "pixup-wishlist.product-detail.modal.createNewWishlist"|trans }}",id:-1,products:[-1]};
  195.                     select.appendChild(createCheckbox(customData,-1));
  196.                 }
  197.                 //add checkboxes for subcribed wishlists
  198.                 match = 0;
  199.                 for(i=0;i<data.length;i++){
  200.                     if(data[i].subscribed === false)
  201.                         continue;
  202.                     if(data[i].editable !== true)
  203.                         continue;
  204.                     match++;
  205.                     if(match === 1) {
  206.                         var hr = document.createElement("hr");
  207.                         var div = document.createElement("div");
  208.                         div.classList = "center PixupCechBoxGroupTitle";
  209.                         div.innerHTML = "{{ "pixup-wishlist.product-detail.modal.subscribedWishlists"|trans }}";
  210.                         select.appendChild(hr);
  211.                         select.appendChild(div);
  212.                     }
  213.                     select.appendChild(createCheckbox(data[i],productID,"PixupCheckBoxRow2"));
  214.                 }
  215.                 $('#pixupWishlist_chooseWishlistModal').modal()
  216.             }
  217.             function createCheckbox(data,productId,className = ""){
  218.                 var div = document.createElement("div");
  219.                 div.className = "custom-control custom-checkbox PixupCheckBoxRow "+className;
  220.                 var input = document.createElement("input");
  221.                 input.type = "checkbox";
  222.                 input.className = "custom-control-input";
  223.                 input.id = "pixupWishlist"+i;
  224.                 input.name = "pixupWishlistCheckBoxWishlistSelector[]";
  225.                 input.value = data.id;
  226.                 input.dataset.isOnWishlist = false;
  227.                 isOnWishlist = false;
  228.                 products = Object.values(data.products);
  229.                 for(let x = 0; products.length > x;x++){
  230.                     if(products[x] === productId) {
  231.                         isOnWishlist = true;
  232.                         break;
  233.                     }
  234.                 }
  235.                 if (isOnWishlist) {
  236.                     input.checked = true;
  237.                     input.dataset.isOnWishlist = true;
  238.                 }
  239.                 var label = document.createElement("label");
  240.                 label.className = "custom-control-label";
  241.                 label.htmlFor ="pixupWishlist"+i;
  242.                 label.innerHTML = data.name;
  243.                 div.appendChild(input);
  244.                 div.appendChild(label);
  245.                 return div
  246.             }
  247.             function pixupWishlist_ajaxCore(url,callback,options=null){
  248.                 var xhttp = new XMLHttpRequest();
  249.                 xhttp.onreadystatechange = function() {
  250.                     if (this.readyState == 4 && this.status == 200) {
  251.                         if(options !== null) {
  252.                             callback(this, ...options);
  253.                         }else
  254.                             callback(this);
  255.                     }
  256.                 };
  257.                 xhttp.open("GET", url, true);
  258.                 xhttp.send();
  259.             }
  260.         </script>
  261.     {% endblock %}
  262.     {#end of content for add-to.wishlist.button.html.twig#}
  263.     {{ parent() }}
  264. {% endblock%}