马根托·维尔。1.9.1.0 .
如果项目已经在当前客户的愿望列表中,隐藏wishlist按钮,或者将其更改为填充的心。
<?php if ($this->helper('wishlist')->isAllow()) : ?>
<div class="ajax-wishlist">
<a href="#"
onclick='ajaxWishlist("<?php echo $this->helper('wishlist')->getAddUrl($_product) ?>","<?php echo $_product->getId()?>");return false;' class="link-wishlist" title="Add to Wishlist">
<i class="fa fa-heart-o"></i>
</a>
</div>
<?php endif; ?>此外,我想动态更新wishlist按钮。一俟愿望表更新,即发心至发心..新来的马根托
参考Check whether a product is in the wishlist or not
我试过这个。
<?php $wishlist = Mage::getModel('wishlist/item')->load($_product->getId(),'product_id');
if($wishlist->getId())
//product is added
echo "Added! - Product is in the wishlist!";
else
//add product to wishlist
echo "<a href='".$this->helper('wishlist')->getAddUrl($_product) ."'>Add This?</a>";
;?>它显示了所有被任何客户添加到愿望列表中的产品。以及如何在主页产品中使用上述代码?ie新到达,查看最多等。它将error.call显示为非对象上的成员函数getId()。
发布于 2016-02-18 06:51:07
如果您需要检查某个产品是否在愿望列表中,并显示该信息,而不是默认的Magento“article”链接,那么本文是为您准备的。为了简化操作,我将解释如何检测产品是否在类别和产品页面上的愿望列表中,但是对于任何其他寻呼机或块,原则是相同的。您只需要确保您有可用的产品id。其他的一切都应该在任何页面上都能正常工作。
类别页
打开template/catalog/product/list.phtml,找到wishlist链接代码。如果您使用的是基本主题,它应该如下所示:
<?php if ($this->helper('wishlist')->isAllow()) : ?>
<li><a href="<?php echo $this->helper('wishlist')->getAddUrl($_product) ?>" class="link-wishlist"><?php echo $this->__('Add to Wishlist') ?></a></li>
<?php endif; ?>代之以:
<?php if ($this->helper('wishlist')->isAllow()) : ?>
<?php foreach (Mage::helper('wishlist')->getWishlistItemCollection() as $_wishlist_item): ?>
<?php $_in_wishlist = false; ?>
<?php if($_product->getId() == $_wishlist_item->getProduct()->getId()): ?>
<?php $_in_wishlist = true; break; ?>
<?php endif; ?>
<?php endforeach; ?>
<?php if(!empty($_in_wishlist) && $_in_wishlist): ?>
<li><span class="in-wishlist"><?php echo $this->__('Already in Wishlist') ?></span></li>
<?php else: ?>
<li><a href="<?php echo $this->helper('wishlist')->getAddUrl($_product) ?>" class="link-wishlist"><?php echo $this->__('Add to Wishlist') ?></a></li>
<?php endif; ?>
<?php endif; ?>产品页
打开template/catalog/product/view/addto.phtml,找到wishlist链接代码。如果您使用的是基本主题,它应该如下所示:
<?php if ($this->helper('wishlist')->isAllow()) : ?>
<li><a href="<?php echo $_wishlistSubmitUrl ?>" onclick="productAddToCartForm.submitLight(this, this.href); return false;" class="link-wishlist"><?php echo $this->__('Add to Wishlist') ?></a></li>
<?php endif; ?>代之以:
<?php if ($this->helper('wishlist')->isAllow()) : ?>
<?php foreach (Mage::helper('wishlist')->getWishlistItemCollection() as $_wishlist_item): ?>
<?php $_in_wishlist = false; ?>
<?php if($_product->getId() == $_wishlist_item->getProduct()->getId()): ?>
<?php $_in_wishlist = true; break; ?>
<?php endif; ?>
<?php endforeach; ?>
<?php if(!empty($_in_wishlist) && $_in_wishlist): ?>
<li><span class="is-wishlist"><?php echo $this->__('Already in Wishlist') ?></span></li>
<?php else: ?>
<li><a href="<?php echo $_wishlistSubmitUrl ?>" onclick="productAddToCartForm.submitLight(this, this.href); return false;" class="link-wishlist"><?php echo $this->__('Add to Wishlist') ?></a></li>
<?php endif; ?>
<?php endif; ?>就这样。如前所述,只要您有可用的产品id,就可以使用此方法检查产品是否在任何Magento页面或块上的愿望列表中。
https://stackoverflow.com/questions/35474444
复制相似问题