2
  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('Magento\Catalog\Helper\Output');
$_product = $block->getProduct();
?>

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

### /ko 
### ko if: wishlist().counter 
helper('Magento\Wishlist\Helper\Data')->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"
                }
            }
        }
    }
}


1

it will help you to solve this issue.

<?php
$_helper = $this->helper('Magento\Catalog\Helper\Output');
$_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('Magento\Wishlist\Helper\Data')->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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.