Adding a new tab under onepage checkout in Magento might seem as incredibly easy task. right?! Well, it’s not. If you want to do it properly, you gonna have to do some work. Took me few hours to get this one running. Attached are screenshots for you to see final result.
Here is the module itself Inchoo_Heared4us.
Few words about module. It uses built in Admin theme module from a coworker Ivan Weiler. If you have this Admin theme module installer already please disable it, since its built into this Heared4us module. There is only one thing you NEED TO DO in order for module to work: Once you added it to Magento, go to System > COnfiguration > Design and write down “custom” under Admin theme section. This admin theme section will appear as soon as you refresh Admin page once you copy-pasted module. If you get “Access denie” error, please logout and login into the admin.
That’s it. If you wish to edit the questions that appear under newely added tab, open the app/design/frontend/default/default/template/checkout/onepage/heared4us.phtml file and modify the array at the very top of the file.
DO A FULL DATABASE AND FILE BACKUP BEFORE ADDING A MODULE TO LIVE STORE.
You should always do a full backup when adding modules to live store. Although the module does not have any database dependencies and stuff, it uses overrides on checkout model, controller and block. Use on your own responsibility.
What you can learn from module? -You can learn how to override (extend) default controllers, Models, Blocks. You can learn how to modify existing JS files and reuse them (reused sample of JS for tab, saved it under heared4us.phtml file itself), you can learn how to set custom theme files on admin to avoid modifying default admin theme, learn how to extend order object (or any other, from sql setup file), learn how to “attach a hook” aka observer to event… Lot to learn on a small module like this. Hope it helps.
Cheers.




If people are still struggling with the way the goal posts have moved in regards to attributes then you can always create a new model to store the data. I think this would work across most versions.
So write an installer script / create a table hdyfu with hdyfu_id, order_id and hdyfu fields then…
/Heared4us/Model/Hdyfu.php
<?php class Inchoo_Heared4us_Model_Hdyfu extends Mage_Core_Model_Abstract { public function _construct() { parent::_construct(); $this->_init('heared4us/hdyfu'); } }/Heared4us/Model/Mysql4/Hdyfu.php
<?php class Inchoo_Heared4us_Model_Mysql4_Hdyfu extends Mage_Core_Model_Mysql4_Abstract { public function _construct() { $this->_init('heared4us/hdyfu', 'hdyfu_id'); } }/Heared4us/Model/Mysql4/Hdyfu/Collection.php
<?php class Inchoo_Heared4us_Model_Mysql4_Hdyfu_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract { public function _construct() { //parent::__construct(); $this->_init('heared4us/hdyfu'); } }Then in Observer.php
<?php class Inchoo_Heared4us_Model_Observer { const ORDER_ATTRIBUTE_FHC_ID = 'heared4us'; /** * Event Hook: checkout_type_onepage_save_order * * @author Branko Ajzele * @param $observer Varien_Event_Observer */ public function hookToOrderSaveEvent() { //Fetch the data from select $_heared4us = null; $_heared4us = Mage::getSingleton('core/session')->getInchooHeared4us(); //Attach it to the order $incrementId = Mage::getSingleton('checkout/session')->getLastRealOrderId(); $order = Mage::getModel('sales/order')->loadByIncrementId($incrementId)->getData(); $hdyfu = Mage::getModel('heared4us/hdyfu') ->setOrderId($order["entity_id"]) ->setHdyfu($_heared4us) ->save(); } }You can then join this to the order grid with a
->joinleft(array('hdyfu' => $_hdyfuTable), 'main_table.entity_id = hdyfu.order_id')in _prepareCollection
and a
$this->addColumn('hdyfu', array( 'header' => Mage::helper('ordertags')->__('Reffered By'), 'index' => 'hdyfu', 'width' => '70px', ));in _prepareColumns.
Worked great, although I don’t understand why you didn’t set it up to say “Where Did You Hear About Us” rather than “Heared For Us”….either way, nice job.
@Richie
Typo
-It was to late to fix it later when I noticed it, meaning I was sort of lazy
Hi Dear thanks for this module but i did not see on checkout page of modern theme in magento 1.5.1.0 plz help me how can i customized..
Array ( [login] => Array ( [label] => Checkout Method [allow] => 1 ) [billing] => Array ( [label] => Billing Information [is_show] => 1 ) [shipping] => Array ( [label] => Shipping Information [is_show] => 1 ) [shipping_method] => Array ( [label] => Shipping Method [is_show] => 1 ) [payment] => Array ( [label] => Payment Information [is_show] => 1 ) [heared4us] => Array ( [allow] => 1 ) [review] => Array ( [label] => Order Review [is_show] => 1 ) ) after print of steps it shows i think it is not calling hearedus.php file why any reason
This works as per instructions for Magento 1.5.1.
Same instructions here but much clearer.
http://www.atomicpages.net/blog/2011/06/23/how-did-you-hear-about-us-in-magento-15/
Remember to clear cache, log out, log back in, after uploading module to be able to see “Admin Theme” option.
Does not seem to work if using PayPal Standard as a payment option.
Any ideas on how to fix that?
Hello,
The module works great except that the filled in tab dose not get updated on the progress bar.
Do you maybe already have a fix for that?
This works as described if I use bank deposit as the payment method. Eg the checkout step shows up & works, and I can see the value on the admin panel.
But when using PayPal standard (which 95% of orders do), the value doesn’t show up in the admin panel, and there is no value written to the heared4us attribute in the sales_flat_order table.
Any ideas on why this is or how to troubleshoot would be appreciated!
@Jason:
Can you please be more specific of your steps you’re exactly doing?
Hello Branko, thank you so much for this post. Also, thank you Michael Terracide and nemo.
I followed your instruction as below but I couldn’t save the value.
1) System > Configuration > Design and write down “custom” under Admin theme section.
2) Follow Michael’s instructions above, by modifying the mysql4-install-01.0.php.
replace
$row = Mage::getSingleton(‘core/resource’)->getConnection(‘core_read’)->fetchRow($sql);
to
$row = Mage::getSingleton(‘core/resource’)->getConnection(‘core_read’)->addColumn(Mage::getSingleton(‘core/resource’)->getTableName(‘sales/order’), ‘giftaid’, ‘TEXT NULL’);
3) Add “heard4us” in the sales_flat_order table.
ALTER TABLE sales_flat_order ADD heared4us text;
heared4us in sales_flat_order table is empty after the order process was completed. So I put a value manually in heared4us and it was shown in admin.
So I think something wrong when the value is saved but I don’t know where I should fix.
Does anyone please give me some advice? My magento version is 1.4.2.0.
I’m sorry again, I have another question. I’d like to move the step before payment. I modified 2 files, app/code/local/Inchoo/Heared4us/Block/Onepage.php and app/code/local/Inchoo/Heared4us/controllers/OnepageController.php
After the modification, the onepage checkout step goes wrong. The process is turn back to shopping cart page. Obviously I did something wrong…. Are there other files I should change?
I’m sorry again, I did everything from the beginning and I could save the data.
Thanks again for your article.
I installed it on Magento 1.6v and it’s working fine
How can I add simple text when my customer selects OTHER from the drop down menu?
Hi
I have updated all the necessary option (but I guess I am missing something). The “How did you hear about us?” doesn’t even show on the main OnePage checkout. However I managed to display it in adminpanel. Help needed.
Thanks
I have installed this module for Magento 1.5.on frontend it’s working fine with all the options but on Backend along with order the details are not diaplying .
Hi,
I have followed the full process for adding the module, but it is not visible on my front end. Also I have my own theme please let me know that how could I do this process by putting the whole things in my own folder- let say fido.
Thanks
I have installed this module for Magento 1.6 on frontend it’s working fine with all the options but on Backend the option selected on frontend is not displayed, why??
Thanks
Hi,
How can I download this module?
Guys I am at my wits end. I did everything above and when I try to log in to admin area after clearing cache I get an error.
I’m using version 1.6.1
Please help