3

please anyone help me

<a href="#" data-post='<?php echo $this->helper('Magento\Wishlist\Helper\Data')->getAddParams($_product) ?>' class="action towishlist" data-action="add-to-wishlist" id="hasitem-wish"></a>
<!-- /ko -->

<!-- ko ifnot: wishlist().getProductUrl() -->
<a href="#" data-post='<?php echo $this->helper('Magento\Wishlist\Helper\Data')->getAddParams($_product) ?>' class="action towishlist" data-action="add-to-wishlist"></a>
<!-- /ko -->
1
  • Magneto Wishlist dosenot works for guest you have to buy extension like this : tinyurl.com/y4hxpwmc
    – Waqar Ali
    Commented Jul 20, 2020 at 11:54

1 Answer 1

2

it will help you to solve this issue.

$_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 and acknowledge you have read our privacy policy.

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