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 -->
有帮助吗?

解决方案

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.

许可以下: CC-BY-SA归因
scroll top