0

I am trying to use observers in Magento 1.7.0.2 to catch when a product is added to cart.

After that event has happened (I believe it is the event checkout_cart_add_product_complete) I would like to show a popup that gives an overview of the product that the customer has just bought, as it would be seen in an item line in the cart.

I have tried to build a module that would catch this event, but I can't find a way to test if I have the same event, what models I need to use or pretty much anything.

So far, I have this written

public function checkoutCartAddProductComplete (Varien_Event_Observer $observer)
{
    $product = $observer->getEvent()->getProduct();
    $session = Mage::getSingleton("checkout/session")->addSuccess($message);
    $message = $this->__('Changed! You added %s to your shopping cart.', Mage::helper('core')->escapeHtml($product->getName()));
    $session->addSuccess($message);
}

However I took that code from the Internet, and it doesn't seem to be working.

There is something in \app\code\core\Mage\Checkout\controllers\CartController.php (around line 205) that shows the eventDispatcher and then the code that displays a message - however I'm not sure how to actually transplant this to a module, short of copying the whole file and overwriting it.

I'm trying to do this as a module so I can take it across various projects, but it is turning out to be a project on it's own...

4

1 回答 1

0

您的 $session 变量设置如下:

$session = Mage::getSingleton("checkout/session")->addSuccess($message);

但与此同时,你$message还没有准备好。

因此,当您设置消息并尝试保存您实际上正在执行的消息时。

Mage::getSingleton("checkout/session")->addSuccess($message)->addSuccess($message);

从您的会话变量中删除->addSuccess($message);,您应该没问题。

于 2013-05-22T14:53:46.443 回答