是否可以覆蓋由magento系統生成的錯誤/成功消息?是否可以覆蓋由magento生成的錯誤或成功消息?
例如,如果我們添加成功消息 「筆記本電腦添加到您的購物車..!」一個產品,如果我想喜歡加入我的客戶的名字「喬希你又增加了筆記本電腦到您的購物車」
什麼感謝, 巴蘭
是否可以覆蓋由magento系統生成的錯誤/成功消息?是否可以覆蓋由magento生成的錯誤或成功消息?
例如,如果我們添加成功消息 「筆記本電腦添加到您的購物車..!」一個產品,如果我想喜歡加入我的客戶的名字「喬希你又增加了筆記本電腦到您的購物車」
什麼感謝, 巴蘭
這是很容易的添加自定義消息堆棧時添加的項目。添加事件偵聽器checkout_cart_add_product_complete
它做到這一點:
public function observeAddToCart($observer) {
$product = $observer->getEvent()->getProduct(); // you may need to play with this
$session = Mage::getSingleton("checkout/session")->addSuccess($message);
$message = Mage::helper("yourmodule")->__('%s, you added %s to your shopping cart.', Mage::helper('core')->htmlEscape($product->getName()));
$session->addSuccess($message);
}
這使得拆除舊消息的問題。我現在看到的最接近的是,您可以通過檢索命令來清除命令上的所有其他消息。所以,你可以事後收拾Magento的設置信息,像這樣:
Mage::getSingleton("checkout/session")->getMessages(true);
您需要被添加Magento的消息後,要做到這一點,但是。希望能給你一個開始!
謝謝, 喬
我已經寫了一個輔助功能,使您可以搜索特定的消息與一個選項,如果發現刪除。這是一個有點令人失望,這不是在提供的核心..
/**
* Searches messages for @param $string.
* Will remove the message if $remove is true.
*
* @param string $string
* @param boolean $remove: false
* @param string $which: core/session
* @return true|false, found|not found
* @access public
*/
public function message_search($string, $remove = false, $which = 'core/session') {
$found = false;
$messages = Mage::getSingleton($which)->getMessages();
foreach($messages->getItems() as $message)
if(stristr($message->getText(), $string)) {
$found = true;
if($remove) $message->setIdentifier('this_message_will_be_removed');
}
if($remove) $messages->deleteMessageByIdentifier('this_message_will_be_removed');
return $found;
}
感謝JM ..我會嘗試了這一點... – balanv 2011-04-14 07:20:06
@Joseph,我有相關的一類視頻集合,該類別不有任何產品,因此它會顯示一條消息「沒有與產品匹配的產品」。我怎麼能刪除這個? 我曾試過'法師:: getSingleton(「核心(&)目錄/會議」) - > getMessages(true);'但沒用。 – Haris 2014-09-09 07:06:29
@ user8009這是2011年的答案,你最好問一個新的問題:) – 2014-09-11 19:02:38