cancel
Showing results for 
Search instead for 
Did you mean: 

How to get item's weight and row_weight on sales_quote_item_save_after

How to get item's weight and row_weight on sales_quote_item_save_after

Hello guys,

 

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 :

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
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
On Mage_Checkout_CartController->indexAction() : it contains the Quote Item of the 1st step, with more information, like the weight and the row_weight
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.