【发布时间】:2014-07-02 11:12:53
【问题描述】:
当具有特定属性的产品在购物车中时,我使用下面的脚本设置标志。 我的问题是,因为我在结帐时使用它,所以我相信它与结帐中的其他变量/数组冲突,并且总数是应有的两倍。
我的问题是如何在不影响其余结帐的所有其他变量的情况下将标志从该脚本中传递出去。我试过 unset($cart);认为这会有所帮助,但没有成功!
(此代码位于我的 checkout.phtml 文件的顶部)
<?php
$collection = Mage::getModel('catalog/product')->getCollection();
$collection->addFieldToFilter(
array(
array('attribute'=> 'WWHAM','eq' => '1')
)
);
$exemptProducts = array();
$exemptProductFound = false;
foreach ($collection as $product) {
$exemptProducts[] = $product->getId();
}
// now let's check if any are in the basket
$cart = new Mage_Checkout_Model_Cart();
$cart->init();
foreach ($cart->getItems() as $item) {
if(in_array($item->getProductId(), $exemptProducts)) {
// to make it simple, just set a flag
$exemptProductFound = true;
}
}
unset($cart);
?>
【问题讨论】: