What is a magento quote? - model-view-controller

I can't understand what is a quote. Can someone give a detailed answer on what are magento quotes, what data they store, what's their lifetime and other relevant information?
Edit: Please notice the difference: Magento vs Magneto. Also the "magento" and "mvc" tags.

quote = cart contents in Magento. Theoretically the quote is an offer and if the user accepts it (by checking out) it converts to order. You can control the lifetime yourself and they store metadata about the store, totals information , shipping and billing relations, relations to payment method and shipping method (that is quoted separately) and items

A Cart is composed of a Quote so Cart Product is really a Quote Item
so when you deal with $cart->addProduct() it does some check and add it by $this->getQuote()->addProduct()
Don't use directly (when it's possible) quote function like Mage_Sales_Model_Quote::addProduct() because checks will not be done.

Quote is used for save cart items.when we add item to cart, reserved id given for your cart and after order placed all details fetch from that id of quote table.
quote table will not clear automatically.

Related

What exactly is the sales_flat_quote used for?

I am a newbie in magento. I understand that when a customer adds something into his cart, all the details regarding the product and customer gets stored into the quote. Why is it necessary to create a quote for an order?
Also I have a script for placing an order programmatically, in which I don't create a quote for the product ordered. Am I making a mistake here without creating a quote? What are the uses of doing so?
A quote in Magento is basically an order that hasn't been placed yet. It contains product items (shopping cart), addresses and payment/shipping methods. It is created as soon as you add an item to cart. During checkout, billing and shipping data is added to the quote. Finally, when the user clicks place order, the quote is converted to an order.
Source : Magento - Difference between Quote and Order

Get order_id before submiting order in Magento

I have added a custom field in checkout page at shipping method step in magento. I am able to insert data from this field to my custom table mg_cake_message(msg_id,customer_id,cake_msg). I need another attribute (order_id) to show data for respective orders in admin panel. How can i get order_id before submitting an order?
I have searched in google and some of people suggest to use quote_id instead of order_id. Is quote_id is same as order_id ?
If it's not possible to get order_id before submiting order then how can the two previous step(Billing Information, Shipping Information) is managed?
Please make me a response .....
A quote in Magento is basically an order that hasn't been placed yet. It contains product items (shopping cart), addresses and payment/shipping methods. It is created as soon as you add an item to cart and Magento creates a sales/quote object.. During checkout, billing and shipping data is added to the quote. Finally, when the user clicks place order, the quote object is converted to an order sales/order object.

Programmatically Apply Multiple Shopping Cart Price Rules Magento

I'm trying to figure out a way of applying multiple shopping cart price rules to a single cart in Magento. The rules would be 'one-off' rules applicable to a unique cart for one customer.
I have no problem creating the rules using Allan's post here, but I can only apply one coupon code at a time to a quote object:
Mage::getSingleton('checkout/cart')
->getQuote()
->setCouponCode('foobar')
->collectTotals()
->save();
I could merge all of my custom price rules in to one rule, but I'm still left with the issue of blocking the customer from entering their own code on the front end.
The table sales_flat_quote in the database has a field applied_rule_ids which I'm guessing holds shopping cart rules triggered that are not applied as a result of a coupon code entered on the front end. Is there a way piggy back on the this automatic process?
I'm trying to see if there's a way to do this gracefully without creating a custom totals collector and adding additional attributes to the quote and order objects.
Any ideas as to an attack route?

Magento: Add a "fake" product to cart/quote

I understand how to programmatically create a product and also add to cart. I know this might sound dumb but is it is possible to generate a product on the fly and add that to the cart/quote but never actually save it in the database.
We want to create a made to order interface and I was thinking at the end it could add a bundle product with all the selections but that bundle product wouldn't actually exist in the backend.
I figured as long as you can make sure the quote and order has what it needs in terms of the product it would be ok, but obviously there is probably a lot that is tied to looking up stuff in the db on a specific sku or ID. I know that if you delete a product and then look at an order in the admin that causes issues, at least it did for this one scenario I was dealing with.
I was thinking of creating a giant bundle product that had like 6 different bundle items and each item could potentially have like 500 products and then based on what the user selects I programmatically add the bundle to cart. But then I wasn't sure if there would be a negative affect with having a gigantic bundle product like that as well.
UPDATE:
I don't think this will work, obviously there are a lot of information tied to the product in the database and we setup a test and right away we get an error for $item->getProduct(). We are moving forward with creating a giant bundle product and also the generic product with adding custom options on the fly, which Anda pointed out below. Any other suggestions will be greatly appreciated.
I'm not sure that clockworkgeek's approach is going to work. On every page load, Magento loads the items from the cart to make sure that they are still valid (in-stock, prices correct, etc), and amends the cart to reflect those values. My understanding of the system in the past has been that a product in the cart needs to have a corresponding database value to survive this process.
The "giant bundle product" approach is a pain, but in the past has been the best approach I have found. Attempting to change the values of the product (such as price or attributes) will be overridden by the cart checks, so you need a product w/ maximal flexibility, such as an overly-customized bundle product or configurable product.
Hope that helps!
Thanks,
Joe
Why not create a generic product in db and then set the product customization as custom options (additional_options) on the fly depending on the user selection. You can add custom options to the product (actually to the quote item) without having to save them in the database. I did this once for a website that sells glasses with prescription. The prescription was added as an option.
You can programmatically create Mage_Sales_Model_Quote_Items and add them to the cart. You've noticed it needs a product to match it's product ID but it needn't be a useful one. It could be a blank, disabled product, also created in code. All that's needed is a stub.
The necessary stuff for the cart is stored in the quote item - fields like name, value and quantity. Those fields are then copied directly to the order without using a product.
Mage::getModel('catalog/product')
creates a new product. you can add it to a cart, by doing something like this:
$cart = Mage::getSingleton('checkout/cart');
$product = Mage::getModel('catalog/product')
->setStoreId($storeid)
->setTypeId($type_id)
->setQty($quantyty)
->setWhatAttributYouWant($attribute);
$cart->addProduct($product);
product attributes you can find in the DB in tables that start like catalog_product_... or take an already created product, and see what attributes it has in the _data array (with debugger or just print_r($product->getData))

What is the conceptual difference between a Product and a Quote Item

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
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 )
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
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.

Resources