views:

237

answers:

3

Involved classes : Mage_Sales_Model_Quote_Item and Mage_Catalog_Model_Product.

I get both of them as a result of listening an event ( on cart add ). I am trying to update the quantity information for a product from an external source.

So far I based my code only on the product information and I am not sure if this is correct.

What is the purpose of Quote Items? How about an bundled of configurable product? Do you have any recommendation on how to get the individual items from a bundle product?

Thanks

+1  A: 

My first answer would be that a product and a quote for a product are two separate entities and therefore should not be modelled in a unified entity.

An example of why would be from the company I work for, and why we model these things separately:

In our e-procurement system you might have a "contract" between a specific buyer and a seller. The "quote" item models this when it comes to invoice entries. If there isn't a contract use the normal product price to create a Quote Item else adjust the price using the "contract" between supplier and buyer.

Hassan Syed
A: 

Magento drops quote items into the cart, specifically. Those quote items are retrieved by using $product->prepareForCart. These items also include different information, such as quantity and configurable product options (on a quote item).

From a backend perspective, data for products are stored in: catalog_product_entity_*, whereas quote items are stored in sales_flat_quote_item (at least in Enterprise. someone else might want to verify this on community).


EDIT: Attaching some code that we wrote to import product inventories a while back.

$product                 = Mage::getModel("catalog/product")->load($productId);
$product->seStockData(array(
    "qty"                         => (int)$yourQuantity,
    "is_in_stock"                 => ((int)$isTheProductInStock),
    "manage_stock"                => $manageStock,
    "is_qty_decimal"              => $isQtyDecimal,
    "use_config_manage_stock"     => $useConfigManageStock,
));

Mage::getModel('catalog/product_api')->update($sku,$product->getData());

For your purposes you may just need to call $product->save();, but I'm including the whole snippet as written because it works.

Hope that helps. Thanks, Joe

Joseph Mastey
I want to update the stock quantities not the cart quantity.
Elzo Valugi
I appreciate the effort but you are making a confusion. $item->qty is another concept than $product->qty
Elzo Valugi
$item->qty is the number of items of the $product type added to current cart
Elzo Valugi
Apologies, that was an unfortunate overlap between variable names. I've renamed it to be more clear (for posterity, since this apparently didn't answer your question).
Joseph Mastey
+1  A: 

I want to thank both responders so far for their effort but their responses are pretty far from my question. I'll try to respond myself based on the things that I've learned.

A quote is a concept related to the order, only that is previous to that in terms of work flow in Magento. A real world concept is something like a preorder, like a postIt on which you place your asked dishes in a restaurant without being an order or a bill.

I was monitoring an event (checkout_cart_product_add_after) that is sending me the $product and the $orderItem. I understand now that is sending both in order to get information about the product and information about billing and the representation of that product in the future order.

In the case of the grouped products for example where the $product is Tshirt with various associated sizes, the $product will contain the SKU of the main grouped product and the $orderItem will contain the instance of the Tshirt that was selected ( medium size SKU ).

FYI: So in order to update the information of a product at cart update you have is better to get the product info from the $item if is a complex type ( bundle, configurable or grouped )

Elzo Valugi