Adding a new tab under one page checkout – full working module

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.

Frontend

Backend1

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.

You made it all the way down here so you must have enjoyed this post! You may also like:

Meet Magento Belarus features an Inchooer talking Magento 2 Checkout Ivona Namjesnik
Ivona Namjesnik, | 0

Meet Magento Belarus features an Inchooer talking Magento 2 Checkout

Tracking Onepage Checkout abandonment using Google Analytics Drazen Karacic-Soljic
, | 70

Tracking Onepage Checkout abandonment using Google Analytics

Magento EE, use reward points in X percent of total (subtotal) checkout value Branko Ajzele
Branko Ajzele, | 2

Magento EE, use reward points in X percent of total (subtotal) checkout value

168 comments

  1. Hi Guys,

    Thank you very much for the handy module. We have been using Magento 1.7.0.2, it looks like all working till the error messages appear from the customers returning at cardsave payment. I have the below error messagases.

    Fatal error: Call to undefined method Inchoo_Heared4us_Model_Type_Onepage::saveOrderAfterRedirectedPaymentAction() in /var/www/vhosts/5poundfashion.com/httpdocs/app/code/local/Cardsave/Cardsaveonlinepayments/controllers/PaymentController.php on line 233

    Any idea about the problem.

    Thanks

  2. Hi,

    I am new to magento.

    Can i add this module before “payment information” method. also can you explain clearly how i can add this magento module to create one more step in checkout. you can send the solution to my mail or you can post the details of creating module here.

    Thanks in Advance.

  3. Can’t get this to work, when i follow the steps and try loading my sales order page it comes up as a blank page and when i finish checkout after clicking place order it loads a blank page as well.

  4. How to change the order of steps ? I want to place “Where did you heared for us” step after login step and before billing step. How to change checkout steps in this extension ?

    Thanks in advance.

  5. Hi,
    this module works like charms but when i disable this module to check checkout process working fine by disabling this module then it shown me blank page on checkout page but when i enable it, checkout page working fine, that mean some thing going wrong when we disable this module.

    any one solve this issue previously ?

  6. Hai frnds,

    It didn’t work for me i am using 1.8.0.0 veraion any one help me…

    Thank you.,

  7. Hi

    This is great – got it working, using 1.7.0.2.

    Now I want to add this to e-mails going out after checkout – how do I do that? Any help? Please?

    Thank you

    1. My values are not storing in th database. Have you fixed it ? Any help would be appreciated.

  8. Hi Friends,

    I have found a solution for saving the heard4us data in the database in magento 1.7 . you need to add the following piece of code in the OnepageController file of heared4us module which is extending the default onepagecontroller.

    /**
    * Create order action
    */
    public function saveOrderAction()
    {

    if ($this->_expireAjax()) {
    return;
    }

    $result = array();
    try {
    if ($requiredAgreements = Mage::helper(‘checkout’)->getRequiredAgreementIds()) {
    $postedAgreements = array_keys($this->getRequest()->getPost(‘agreement’, array()));
    if ($diff = array_diff($requiredAgreements, $postedAgreements)) {
    $result[‘success’] = false;
    $result[‘error’] = true;
    $result[‘error_messages’] = $this->__(‘Please agree to all the terms and conditions before placing the order.’);
    $this->getResponse()->setBody(Mage::helper(‘core’)->jsonEncode($result));
    return;
    }
    }
    if ($data = $this->getRequest()->getPost(‘payment’, false)) {

    $this->getOnepage()->getQuote()->getPayment()->importData($data);
    }

    $this->getOnepage()->saveOrder();//print_r($rd->getOrderId);

    //——————–Save heared 4 us —————————————–//
    $order = new Mage_Sales_Model_Order();
    $incrementId = Mage::getSingleton(‘checkout/session’)->getLastRealOrderId();
    $order->loadByIncrementId($incrementId);

    //Fetch the data from select box and throw it here
    $_heared4us_data = null;
    $_heared4us_data = Mage::getSingleton(‘core/session’)->getInchooHeared4us();
    //Save fhc id to order obcject
    $order->setData(‘heared4us’, $_heared4us_data);
    $order->save();
    //———————Save heared 4 us ends————————————-//

    $redirectUrl = $this->getOnepage()->getCheckout()->getRedirectUrl();
    $result[‘success’] = true;
    $result[‘error’] = false;
    } catch (Mage_Payment_Model_Info_Exception $e) {
    $message = $e->getMessage();
    if( !empty($message) ) {
    $result[‘error_messages’] = $message;
    }
    $result[‘goto_section’] = ‘payment’;
    $result[‘update_section’] = array(
    ‘name’ => ‘payment-method’,
    ‘html’ => $this->_getPaymentMethodsHtml()
    );
    } catch (Mage_Core_Exception $e) {
    Mage::logException($e);
    Mage::helper(‘checkout’)->sendPaymentFailedEmail($this->getOnepage()->getQuote(), $e->getMessage());
    $result[‘success’] = false;
    $result[‘error’] = true;
    $result[‘error_messages’] = $e->getMessage();

    if ($gotoSection = $this->getOnepage()->getCheckout()->getGotoSection()) {
    $result[‘goto_section’] = $gotoSection;
    $this->getOnepage()->getCheckout()->setGotoSection(null);
    }

    if ($updateSection = $this->getOnepage()->getCheckout()->getUpdateSection()) {
    if (isset($this->_sectionUpdateFunctions[$updateSection])) {
    $updateSectionFunction = $this->_sectionUpdateFunctions[$updateSection];
    $result[‘update_section’] = array(
    ‘name’ => $updateSection,
    ‘html’ => $this->$updateSectionFunction()
    );
    }
    $this->getOnepage()->getCheckout()->setUpdateSection(null);
    }
    } catch (Exception $e) {
    Mage::logException($e);
    Mage::helper(‘checkout’)->sendPaymentFailedEmail($this->getOnepage()->getQuote(), $e->getMessage());
    $result[‘success’] = false;
    $result[‘error’] = true;
    $result[‘error_messages’] = $this->__(‘There was an error processing your order. Please contact us or try again later.’);
    }
    $this->getOnepage()->getQuote()->save();
    /**
    * when there is redirect to third party, we don’t want to save order yet.
    * we will save the order in return action.
    */
    if (isset($redirectUrl)) {
    $result[‘redirect’] = $redirectUrl;
    }

    $this->getResponse()->setBody(Mage::helper(‘core’)->jsonEncode($result));
    }

    .

  9. Hello,
    I have install your module but i can’t see this saved steps in sales order view page as like second image shown above.
    Can you explane why this thing happend ?

  10. I’m using magento 1.7 and everything is working except posting the info from the extra tab to the order info. I’ve done all the updates including the MySql update Umair suggested, but it’s still not working. I am checking out with “Check/Moneyorder” as an option, could this be the problem?

    Has anyone had success with this on 1.7?

  11. I uploaded it and got following error :

    CONNECT ERROR: Package file is invalid
    Invalid package name, allowed: [a-zA-Z0-9_-] chars
    Invalid version, should be like: x.x.x
    Invalid stability
    Invalid date, should be YYYY-DD-MM
    Invalid channel URL
    Empty authors section
    Empty package contents section

    any help ????/

  12. Is it possible to show extra tab and add that value in sales order mail?
    I have already tried extra tab.Now i want to know is it possible to show extra tab value in sales order mail?

  13. UPDATED……….!

    //START Add order attribute by Branko Ajzele
    $sql = “SELECT entity_type_id FROM “.$this->getTable(‘eav_entity_type’).” WHERE entity_type_code=’order'”;
    $row = Mage::getSingleton(‘core/resource’)->getConnection(‘core_read’)->addColumn(Mage::getSingleton(‘core/resource’)->getTableName(‘sales/order’), ‘giftaid’, ‘TEXT NULL’);

    $attribute = array(
    ‘type’ => ‘text’,
    ‘label’ => ‘heared4us’,
    ‘visible’ => false,
    ‘required’ => false,
    ‘user_defined’ => false,
    ‘searchable’ => false,
    ‘filterable’ => false,
    ‘comparable’ => false,
    );

    $installer->addAttribute($row[‘entity_type_id’], ‘heared4us’, $attribute);
    //END Add customer attribute Branko Ajzele

  14. Hi Guys,
    for i solved the problem.. 🙂 its quite easy than your thoughts 😀

    for display content in admin section just change this file:

    app\code\local\Inchoo\Heared4us\sql\heared4us_setup\mysql4-install-0.1.0.php

    //START Add order attribute by Branko Ajzele
    $sql = “SELECT entity_type_id FROM “.$this->getTable(‘eav_entity_type’).” WHERE entity_type_code=’order'”;
    $row = Mage::getSingleton(‘core/resource’)->getConnection(‘core_read’)->fetchRow($sql);

    $attribute = array(
    ‘type’ => ‘text’,
    ‘label’ => ‘Heared4us’,
    ‘visible’ => false,
    ‘required’ => false,
    ‘user_defined’ => false,
    ‘searchable’ => false,
    ‘filterable’ => false,
    ‘comparable’ => false,
    );

    $installer->addAttribute($row[‘entity_type_id’], ‘heared4us’, $attribute);
    //END Add customer attribute Branko Ajzele

    to this:

    //START Add order attribute by Branko Ajzele
    $sql = “SELECT entity_type_id FROM “.$this->getTable(‘eav_entity_type’).” WHERE entity_type_code=’order'”;
    $row = Mage::getSingleton(‘core/resource’)->getConnection(‘core_read’)->fetchRow($sql);

    $attribute = array(
    ‘type’ => ‘text’,
    ‘label’ => ‘heared4us’,
    ‘visible’ => false,
    ‘required’ => false,
    ‘user_defined’ => false,
    ‘searchable’ => false,
    ‘filterable’ => false,
    ‘comparable’ => false,
    );

    $installer->addAttribute($row[‘entity_type_id’], ‘heared4us’, $attribute);
    //END Add customer attribute Branko Ajzele

    what i did just check the ‘label’ capital H to lower h
    thats it 🙂 Enjoy and if you find it useful just let me know 🙂

    1. I am still not getting any value from database in magento 1.9 🙁

  15. Hi,

    i upload modules front end its working properly,but i can able to get the value in admin side sales ->order –
    Where did you heared about us (in this place field is empty),

    Advance thanks,i am using 1.7.0.2

  16. Hi guys,

    I hope some one can help.

    using magento 1.7.0.0 I have installed the module and i get an error as follows, this shows on the one page checkout with display errors on..

    Notice: Undefined index: heared4us in C:\zend\Apache\htdocs\magento\app\code\core\Mage\Checkout\Block\Onepage\Progress.php on line 93

    when we look at this line its obvious that the array $stepsRevertIndex is missing ‘hearded4us’

    Array
    (
    [login] => 0
    [billing] => 1
    [shipping] => 2
    [shipping_method] => 3
    [payment] => 4
    [review] => 5
    )

    any pointers here would be welcome,

    thanks,
    bam

  17. I’d like to add this. However it after uploading it doesn’t seem to add the Admin Theme option, nor do I see it in available modules under Advanced. Running 1.7.0.2.

  18. Hi,

    Cuurently i am using this modulke in the standard checkout. And this works very well.

    But i have bought a one page checkout module – without this functionality.

    Now i would like add this too.
    But when i just copy-past the code from the heared4us.phtml into the onepagecheckout it will not work. What piece of javascript must i keep, so i can use it correctly?

    1. I have same problem Ronny, have managed to fix it ? I need support. Thanks

  19. Hi,

    The module works fine but I want the extra tab to be shown in only one store I have 2 stores in the Site and I want to add the extra step in one store only how can I do that.

    Thanks & Regards,
    Srikanth thandra

  20. Hallo, thanks for this module, but not work..
    After placing the files in my shop, I get this error:
    Mage registry key “_singleton/Inchoo_Heared4us_Controller_Observer” already exists..
    Where is the problem?
    thanks
    regards luke

  21. Also works in 1.7 after adjusting the mysql.php and manually adding the field.

    First I thought it didnt worked because I didnt see the value in the admin and didnt got saved to database. Couldnt delete cache because it wasnt on but did delete old cache files which were in the map var/cache and the sessions in var/sessions and it worked.

    Also replaced the options with a textarea which worked fine as long as you kept the id=”getvoice” name=”getvoice”.

  22. hiiii this post is very useful for me, now what i want to do is, i want to combine two steps shipping method and payment information in one single steps an its procedure should remain as it is,but both value should get saved from one step. please send me the procedure with steps and files which need to be change ,if possible then pls pls send me code files for it if u have worked on like this earlier. thanks

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

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

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

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

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

  28. 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?

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

  30. 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!

  31. 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?

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

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

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

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <blockquote cite=""> <code> <del datetime=""> <em> <s> <strike> <strong>. You may use following syntax for source code: <pre><code>$current = "Inchoo";</code></pre>.

Tell us about your project

Drop us a line. We'd love to know more about your project.