I need to extend the Magento shopping cart to include an extra step for a store locator. I understand that I need to overwrite the core OnePage controller (Mage_Checkout_OnepageController) and blocks (Mage_Checkout_Block_Onepage) but what needs to be done with regards to keeping track of the extra information (e.g. user’s selected options from my custom step).
I need to extend the Magento shopping cart to include an extra step for
Share
There are a number of steps required here to get the whole solution.
Firstly, create a new module. Use the ModuleCreator if you wish.
Then, write a setup script in your module to add the new fields to Magento’s attribute structure, e.g. :
Note the use of the
Mage_Sales_Model_Mysql4_Setupto add the fields to the relevantsales_flat_quoteandsales_flat_ordertables.Now, insert the following values in your module’s config.xml file:
That will instruct Magento to copy the values of your custom field from quote to order to invoice and credit_memo, etc.
Then in your custom block/controller code, you will be able to use Magento’s magic getters and setters to persist the values.
You should see the new column and value saved in
sales_flat_quote. Then once the customer completes checkout, the same value should be saved insales_flat_order.Note that the above code can be extended to work for
quote_itemandorder_itemby just changingquotetoquote_itemetc, however, if you wish to save attribute values that have been set on your products, then some extra work is required.Insert a new block of XML into your config.xml (again inside the global node):
Where
my_attributeis the attribute code on the product model. That will make the my_attribute available on the linked product, so you can access it viawithout needing to perform a full
Mage::getModel('catalog/product')->load($oQuoteItem->getProductId()). This is much more efficient.Then, you will need an observer to copy the values from the product object to the quote_item object. So, declare your observer in the config.xml:
and write code in your observer class like this: