本文整理汇总了PHP中Mage_Core_Helper_Abstract::productGiftEnabled方法的典型用法代码示例。如果您正苦于以下问题:PHP Mage_Core_Helper_Abstract::productGiftEnabled方法的具体用法?PHP Mage_Core_Helper_Abstract::productGiftEnabled怎么用?PHP Mage_Core_Helper_Abstract::productGiftEnabled使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Mage_Core_Helper_Abstract
的用法示例。
在下文中一共展示了Mage_Core_Helper_Abstract::productGiftEnabled方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: deleteGift
/**
* Remove gift from cart after special product has been removed
*
* @param $observer
* @return $this
*/
public function deleteGift($observer)
{
if ($this->_helper->productGiftEnabled()) {
$quote_item = $observer->getEvent()->getQuoteItem();
$product = Mage::getModel('catalog/product')->load($quote_item->getProduct()->getId());
$child_items = $quote_item->getChildren();
if (!empty($child_items)) {
$id_delete = current($child_items)->getProduct()->getId();
} else {
$id_delete = $quote_item->getProduct()->getId();
}
$has_gift = $product->getData('is_product_gift_enabled');
if (!$has_gift) {
return $this;
}
$cart = Mage::getSingleton('checkout/cart');
$quote = $cart->getQuote();
foreach ($quote->getItemsCollection() as $it) {
$gift_attr = $it->getOptionByCode('gift_for_product_id');
if ($gift_attr) {
if ($gift_attr->getValue() == $id_delete) {
$cart->removeItem($it->getItemId());
$quote->save();
return $this;
}
}
}
return $this;
}
}