Question

I have implemented an observer for checkout_cart_product_add_after. I am retrieving the quote item by

$item = $observer->getEvent()->getQuoteItem();

However, I noticed, that any of the functions to retrieve the item's current price simply return NULL. I can't even access its ID!

On further inspection I see that the quote item only has the following data attributes set:

quote_id
store_id
product
product_id
product_type
sku
name
weight
tax_class_id
base_cost
is_recurring
is_qty_decimal
is_nominal
qty_to_add
qty
qty_options

Attributes like price, base_price, custom_price etc. are completely missing.

I am also observing the checkout_cart_update_items_after event, where I get the quote item in a different way:

$cart = $observer->getEvent()->getCart();
$data = $observer->getEvent()->getInfo();

foreach( $data as $itemId => $itemInfo )
{
    if( $item = $cart->getQuote()->getItemById( $itemId ) )
    {
        $item = $item->getParentItem() ?: $item;
        …
    }
}

In this case, all the relevant data is present.

Can anyone tell me, why the price data is missing for quote items in the checkout_cart_product_add_after event?

Was it helpful?

Solution

Ah, it seems this is the correct answer: https://magento.stackexchange.com/a/10670/37461

I have changed the event to checkout_cart_add_product_complete accordingly and changed the code in my observer to

$product = $observer->getEvent()->getProduct();
$quote = Mage::getModel('checkout/cart')->getQuote();
$item = $quote->getItemByProduct( $product );

to get the quote item with all details.

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top