TransWikia.com

Wishlist not working for login customer in magento2 with caching if once i add product then wishlist icon remove by KO wishlist().counter?

Magento Asked on December 7, 2021

  1. How can I set my wishlist for logged on customer and log gout customer with knockout JS
  2. if I logged on then I only add product once then wishlist icon remove because of knockout JS
  3. how to write knockout JS for wishlist i m unable to add multiple product if I logged on with caching website

helper('MagentoCatalogHelperOutput');
$_product = $block->getProduct();
?>

**** ko ifnot: wishlist().counter
helper('MagentoWishlistHelperData')->getAddParams($_product) ?>' title="Wishlist" class="action towishlist" data-action="add-to-wishlist">

### /ko 
### ko if: wishlist().counter 
helper('MagentoWishlistHelperData')->getAddParams($_product) ?>' title="Wishlist" id="hasitem-wish"  data-action="add-to-wishlist">

### /ko 


{
    "*": {
        "Magento_Ui/js/core/app": {
            "components": {
                "wishlist": {
                    "component": "Magento_Wishlist/js/view/wishlist"
                }
            }
        }
    }
}


One Answer

it will help you to solve this issue.

<?php
$_helper = $this->helper('MagentoCatalogHelperOutput');
$_product = $block->getProduct();
?>
<div class="link wishlist">    
<a href="#"  data-post='#' class="action towishlist wish-in-wish" id="hasitem-wish"></a>    
<a href="#" data-post='<?php echo $this->helper('MagentoWishlistHelperData')->getAddParams($_product) ?>' class="action towishlist wish-notin-wish"  data-action="add-to-wishlist"></a>
</div>
<script type="text/x-magento-init">
{
    "*": {
    "Magento_Ui/js/core/app": {
    "components": {
    "wishlist": {
    "component": "Magento_Wishlist/js/view/wishlist"
}
}
}
}
}
</script>
<script type="text/javascript">
sh(document).ready(function() 
{  
    sh('.wish-in-wish').hide(); 
    var title = sh('.catalog-product-view .product-info-main .product .page-title .base').text();        
    var md = localStorage.getItem('mage-cache-storage');           
    var myJSON = JSON.parse(md);   
    var wishlistdata = myJSON.wishlist.items;  
    wishlistdata.forEach(function(item) 
    {
        var wishlistpn = item.product_name; 
        if (wishlistpn == title)              
        {
            sh('.wish-in-wish').css("display","block");               
            sh('.wish-notin-wish').hide();                           
        }            
    });
    var guest_wishlistdata = myJSON.guest_wishlist.items;  
    guest_wishlistdata.forEach(function(item) 
    {
        var gstwishlistpn = item.product_name; 
        if (gstwishlistpn == title)              
        {
            sh('.wish-in-wish').css("display","block");               
            sh('.wish-notin-wish').hide();                           
        }            
    });
}); 
</script>

I solve this issue using this way. it will check checklist form localstorage without getting info from server side.

Answered by jykmhar123 on December 7, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP