2

I would like to extract some information from a Mage_Sales_Model_Quote_Item object while adding a product to the cart with the sales_quote_item_save_after event.

When I add a configurable product to the cart (e.g.: a white XL shirt), the event is triggered four times :

  1. On Mage_Checkout_CartController->addAction() : it contains a Quote Item of the configurable product (e.g.: shirt) with prices and others data. It also contains the Quote Item associated to the simple product (white XL shirt) in a _children property
  2. On Mage_Checkout_CartController->addAction() : it contains the Quote Item of the simple product that was in the _children property above. This one doesn't contain prices information as these are only on configurable products
  3. On Mage_Checkout_CartController->indexAction() : it contains the Quote Item of the 1st step, with more information, like the weight and the row_weight
  4. On Mage_Checkout_CartController->indexAction() : it contains the Quote Item of the 2nd step, also with more information

So, my issue is that i would like to work only on the 1st or the 2nd step (as the indexAction should not be affected by the module i'm working on), but on these 2 steps, i can't get the weight and the row_weight data.

So i've reviewed the Magento Core to get how these information are loaded on the indexAction() and it appears that when the Mages_Sales_Model_Resource_Quote_Item_Collection is loaded, the _afterLoad() method executes _assignProducts() that load the weights and forwards them by a setProduct() method from the Mage_Sales_Model_Quote_Item class.

Then, i tried to do this on my observer :

$item = $observer->getEvent()->getItem();
$item->getQuote()->getItemsCollection()->clear()->load()

After that, it appears that i can get the weight inside the :

`$item->getQuote()->getItemsCollection()->getFirstItem()`

Does anyone have a better solution or idea ? Because i'm not really satisfied with that one.

Thanks all.

1 Answer 1

1

The problem you are facing is, that the informations you want only are part of Mage_Sales_Model_Quote_Item after \Mage_Sales_Model_Quote::collectTotals is called.

This happens on the cart page and on every checkout step.

Threfore what you want to do (not hook on the index action) is not possible.

Just hook into the after_save event, make sure to track what you have already processed and do your thing.

3

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.