2
votes

I am try to create an additional step in the Magento onepage checkout process. I am following the tutorial located at http://www.excellencemagentoblog.com/magento-onestep-checkout-add-step but specifically adding a step at the end before the review.

My folder / file structure is as follows. (Ignore widget.xml) Folder structure

I have uploaded the code in it's current state to this gist: https://gist.github.com/Relequestual/5263498

I have the theme set to 'new'.

I am var_dumping the $this->getSteps() which shows that the 'testcheck' returns null. In config.xml, if I change under gobal, blocks, checkout, rewrite, onepage to the same class with '_TestCheck' on the end, the checkout doesn't display at all, but 'Test Check' appears in the progress section on the right. When I revert this change, it then shows as not being null in the var dump like so... testcheck vardump But, I still don't see the step actually added to the page.

I've not done any magento before, so feel a bit in over my head. I expect there is some problem with the xml configuration files, but I've been working on this for 2 days now, and am somewhat lost as to what else I can try.

I know this question may sound similar to others, which it is, however I can't find a question where the OP has the same symptoms as what I am seeing.

1
The current solution I'm investigating is using this plugin aitoc.com/en/magentomods_checkoutfieldsmanager.html and then show/hide a the radio buttons based on the country and postcode the user selects / enters - Relequestual
Sorry to be the bearer of bad news but this is a fairly complex task, and the fact that you haven't touched Magento before fills me with great fear. Try your question at magento.stackexchange.com, you may have more luck there, or find someone who can guide you through it. Good luck. - Matt Humphrey
Glad I no longer have anythng to do with Magento =] - Relequestual

1 Answers

0
votes

By default magento gives some checkout steps. But Sometime you need to add extra information from the customer for future reference. A common requested customization is to add the Custom Form in default checkout process. This is not good practice to touch core files. You can do this via overriding Modules. In this example Comapnyname is Ipragmatech and Module name is Checkoutstep.

Step1: Add Custom step in the checkout process

Open the Ipragmatech > Checkoutstep > Block > Onepage> Checkoutstep.php file and write the following code

    class Ipragmatech_Checkoutstep_Block_Onepage_Checkoutstep extends Mage_Checkout_Block_Onepage_Abstract
    {
       protected function _construct()
       {     
          $this->getCheckout()->setStepData('checkoutstep', array(
          'label'     => Mage::helper('checkout')->__('Invitation to participation'),
          'is_show'   => true
        ));
        parent::_construct();
       }
     }

Step2: Add steps which and where you want in the checkout process

Open the Ipragmatech > Checkoutstep > Block > Onepage> Checkoutstep.php file and write the following code

    class Ipragmatech_Checkoutstep_Block_Onepage extends Mage_Checkout_Block_Onepage
    {
      public function getSteps()
      {
             $steps = array();

             if (!$this->isCustomerLoggedIn()) {
                $steps['login'] = $this->getCheckout()->getStepData('login');
             }

            $stepCodes = array('billing', 'shipping', 'shipping_method', 'payment', 'checkoutstep', 'review');
         foreach ($stepCodes as $step) {
             $steps[$step] = $this->getCheckout()->getStepData($step);
          }

    return $steps;
   }
}

Step3: Grab the submitted value of custom form and set the values of Custom form

Open the ipragmatech > Checkoutstep > controllers > OnepageController.php and write the following fucntion

    public function saveCheckoutstepAction()
    {
      $this->_expireAjax();
      if ($this->getRequest()->isPost()) {

     //Grab the submited value 
     $_entrant_name = $this->getRequest()->getPost('entrant_name',"");
     $_entrant_phone = $this->getRequest()->getPost('entrant_phone',"");
     $_entrant_email = $this->getRequest()->getPost('entrant_email',"");
     $_permanent_address = $this->getRequest() ->getPost('permanent_address',"");
     $_address = $this->getRequest()->getPost('local_address',"");

     Mage::getSingleton('core/session') ->setIpragmatechCheckoutstep(serialize(array(
    'entrant_name' =>$_entrant_name,
    'entrant_phone' =>$_entrant_phone,
    'entrant_email' =>$_entrant_email,
    'permanent_address' =>$_permanent_address,
    'address' =>$_address
     )));

    $result = array();
    $redirectUrl = $this->getOnePage()->getQuote()->getPayment() ->getCheckoutRedirectUrl();
        if (!$redirectUrl) {
            $this->loadLayout('checkout_onepage_review');
            $result['goto_section'] = 'review';
            $result['update_section'] = array(
                'name' => 'review',
                'html' => $this->_getReviewHtml()
            );

        }

        if ($redirectUrl) {
            $result['redirect'] = $redirectUrl;
        }

        $this->getResponse()->setBody(Zend_Json::encode($result));
    }
}

Step4: Save Custom Form information

When checkout_onepage_controller_success_action event hook is called. Open the Ipragmatech > Checkoutstep > Model >Observer.php and write the following

    class Ipragmatech_Checkoutstep_Model_Observer {
      const ORDER_ATTRIBUTE_FHC_ID = 'checkoutstep';
      public function hookToOrderSaveEvent() {
      if (Mage::helper('checkoutstep')->isEnabled()) {
         $order = new Mage_Sales_Model_Order ();
         $incrementId = Mage::getSingleton ( 'checkout/session' )->getLastRealOrderId ();
         $order->loadByIncrementId ( $incrementId );

       // Fetch the data 
       $_checkoutstep_data = null;
       $_checkoutstep_data = Mage::getSingleton ( 'core/session' )->getIpragmatechCheckoutstep ();
       $model = Mage::getModel ( 'checkoutstep/customerdata' )->setData ( unserialize ( $_checkoutstep_data ) );
       $model->setData ( "order_id",$order["entity_id"] );
       try {
           $insertId = $model->save ()->getId ();
             Mage::log ( "Data successfully inserted. Insert ID: " . $insertId, null, 'mylog.log');
        } catch ( Exception $e ) {
            Mage::log ( "EXCEPTION " . $e->getMessage (), null, 'mylog.log' );
          }
        }
    }

}

Magento – Add Custom Form in Checkout Extension is a complete solution to add extra step in Checkout process for your ecommerce website. It allow admin to export data from custom table in CSV format.

Visit the link to get this free extension http://www.magentocommerce.com/magento-connect/custom-form-in-checkout.html