当客户将产品添加到购物车并将该产品从商店中删除时,有两条消息 enter image description here
调用第一条消息时,如何删除有关删除产品的第二条消息。
还有一些调用消息的功能:
protected function _getProduct($productInfo)
{
$product = null;
if ($productInfo instanceof Mage_Catalog_Model_Product) {
$product = $productInfo;
} elseif (is_int($productInfo) || is_string($productInfo)) {
$product = Mage::getModel('catalog/product')
->setStoreId(Mage::app()->getStore()->getId())
->load($productInfo);
}
$currentWebsiteId = Mage::app()->getStore()->getWebsiteId();
if (!$product
|| !$product->getId()
|| !is_array($product->getWebsiteIds())
|| !in_array($currentWebsiteId, $product->getWebsiteIds())
) {
Mage::getSingleton('checkout/session')->addSuccess(Mage::helper('checkout')->__('The product could not be found.'));
}
return $product;
}
和第二条额外消息
public function addItemRemoveNotification(Varien_Event_Observer $observer)
{
/* @var $quoteItem Advox_Sales_Model_Quote_Item */
$quoteItem = $observer->getQuoteItem();
if (true === boolval($quoteItem->getData('is_a_free_sample'))) {
return $this;
}
Mage::getSingleton('core/session')->addSuccess(
Mage::helper('checkout')->__("%s successfully removed from basket.", $quoteItem->getData('name'))
);
return $this;
}
答案 0 :(得分:0)
编辑addItemRemoveNotification
方法:
public function addItemRemoveNotification(Varien_Event_Observer $observer)
{
/* @var $quoteItem Advox_Sales_Model_Quote_Item */
$quoteItem = $observer->getQuoteItem();
if (true === boolval($quoteItem->getData('is_a_free_sample'))) {
return $this;
}
$smessages = Mage::getSingleton('checkout/session')->getMessages()->getItems();
$firstMessageExist = false;
foreach ($smessages as $smessage) {
$text = $message->getText();
if($text == 'The product could not be found.'){
$firstMessageExist = true;
}
}
if($firstMessageExist === false){
Mage::getSingleton('core/session')->addSuccess(
Mage::helper('checkout')->__("%s successfully removed from basket.", $quoteItem->getData('name'))
);
}
return $this;
}