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 aQuote Item
of the configurable product (e.g.: shirt) with prices and others data. It also contains theQuote Item
associated to the simple product (white XL shirt) in a_children
property - On
Mage_Checkout_CartController->addAction()
: it contains theQuote Item
of the simple product that was in the_children
property above. This one doesn't contain prices information as these are only onconfigurable products
- On
Mage_Checkout_CartController->indexAction()
: it contains theQuote Item
of the 1st step, with more information, like theweight
and therow_weight
- On
Mage_Checkout_CartController->indexAction()
: it contains theQuote 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.