I recently worked on a similar type of requirement. so follow my instructions: -
I ask you not to focus on the length of the answer, just focus on the results
step 1 : - if you want to set the driver prompt between sending and sending, first open
\ application \ code \ kernel \ Mage \ Checkout \ Block \ Onepage.php there is an array of $ stepCodes (line no: - 44). replace it with
$stepCodes = array('billing', 'shipping', 'excellence2','shipping_method', 'payment', 'review');
I use excellence2 , you can also use this name.
Step 2 : - now we need to create the Excellence2 class in the application \ code \ core \ Mage \ Checkout \ Block \ Onepage \ so create a new php file and paste this code into it and save it as Excellence2.php
class Mage_Checkout_Block_Onepage_Excellence2 extends Mage_Checkout_Block_Onepage_Abstract { protected function _construct() { $this->getCheckout()->setStepData('excellence2', array( 'label' => Mage::helper('checkout')->__('Tip Ammount'), 'is_show' => $this->isShow() )); parent::_construct(); } }
Note : - now you can put any name in the label of the _construct () function, so change the "Setup Tip" to the driver hint
Step 3 : - now open OnepageController.php , which is located in the application \ code \ core \ Mage \ Checkout \ controllers \ and find saveBillingAction () (line no: -296) and replace this code with
public function saveBillingAction() { if ($this->_expireAjax()) { return; } if ($this->getRequest()->isPost()) { // $postData = $this->getRequest()->getPost('billing', array()); // $data = $this->_filterPostData($postData); $data = $this->getRequest()->getPost('billing', array()); $customerAddressId = $this->getRequest()->getPost('billing_address_id', false); if (isset($data['email'])) { $data['email'] = trim($data['email']); } $result = $this->getOnepage()->saveBilling($data, $customerAddressId); if (!isset($result['error'])) { /* check quote for virtual */ if ($this->getOnepage()->getQuote()->isVirtual()) { $result['goto_section'] = 'payment'; $result['update_section'] = array( 'name' => 'payment-method', 'html' => $this->_getPaymentMethodsHtml() ); } elseif (isset($data['use_for_shipping']) && $data['use_for_shipping'] == 1) { $result['goto_section'] = 'excellence2'; //Goes to our step $result['allow_sections'] = array('shipping'); $result['duplicateBillingInfo'] = 'true'; } else { $result['goto_section'] = 'shipping'; } } $this->getResponse()->setBody(Mage::helper('core')->jsonEncode($result)); } }
Step 4 : - again in the same file OnepageController.php there is a function saveShippingAction () (line No. 331), change it to
public function saveShippingAction() { if ($this->_expireAjax()) { return; } if ($this->getRequest()->isPost()) { $data = $this->getRequest()->getPost('shipping', array()); $customerAddressId = $this->getRequest()->getPost('shipping_address_id', false); $result = $this->getOnepage()->saveShipping($data, $customerAddressId); if (!isset($result['error'])) { $result['goto_section'] = 'excellence2';
this code reports that when the user goes through the submit step, he will go to our driver prompt step .
Step 5 : - again in the same file ( OnepageController.php ) we need to indicate where the user will redirect after passing, although the driver hint > step .so create saveExcellence2Action () immediately after the saveShippingAction () function
public function saveExcellence2Action() { if ($this->_expireAjax()) { return; } if ($this->getRequest()->isPost()) { $data = $this->getRequest()->getPost('excellence2', array()); $result = $this->getOnepage()->saveExcellence2($data); if (!isset($result['error'])) { $result['goto_section'] = 'shipping_method'; $result['update_section'] = array( 'name' => 'shipping-method', 'html' => $this->_getShippingMethodsHtml() ); } $this->getResponse()->setBody(Mage::helper('core')->jsonEncode($result)); } }
Step 6 : - now we change the checkout.xml, which is located in
\ app \ design \ frontend \ default \ your template \ layout open it and find
<checkout_onepage_index translate="label">
and in this node there is a block (line 326)
<block type="checkout/onepage_shipping" name="checkout.onepage.shipping" as="shipping" template="checkout/onepage/shipping.phtml"/>
just add a new block after this line shown above
<block type="checkout/onepage_excellence2" name="checkout.onepage.excellence2" as="excellence2" template="checkout/onepage/excellence2.phtml"/>
Step 7 Now we need to create the excellence2.phtml file. \ app \ design \ frontend \ default \ your template \ template \ checkout \ onepage \
this file shows the content you want to show to the user
<form id="co-excellence2-form" action=""> <div class="wide"> <label for="excellence2:like" class="required"><em style="color:#F00;">*</em> Select the amount of tip ,You wish to give to the driver.</label> </div> <div style="margin-top:20px;"> <ul> <li> <input type="radio" name="excellence2[like]" id="excellence2:like" value="0" checked="checked" class="radio" onclick="savevalue(this.value);"/> No Tip/Pay driver at the door </li> <li> <input type="radio" name="excellence2[like]" id="excellence2:like" value="150" class="radio" onclick="savevalue(this.value);" /> 150$ </li> <li> <input type="radio" name="excellence2[like]" id="excellence2:like" value="250" class="radio" onclick="savevalue(this.value);"/> 250$ </li> <li> <input type="radio" name="excellence2[like]" id="excellence2:like" value="400" class="radio" onclick="savevalue(this.value);" /> 400$ </li> <li> <input type="radio" name="excellence2[like]" id="excellence2:like" value="500" class="radio" onclick="savevalue(this.value);"/> 500$ </li> <li> <input type="radio" name="excellence2[like]" id="excellence2:like" value="15% of total amount" class="radio" onclick="savevalue(this.value);" /> 15% of Total Amount </li> </ul> </div> <fieldset> <div class="buttons-set" id="excellence2-buttons-container"> <p class="required"><?php echo $this->__('* Required Fields') ?></p> <button type="button" title="<?php echo $this->__('Continue') ?>" class="button" onclick="excellence2.save()"><span><span><?php echo $this->__('Continue') ?></span></span> </button> <span class="please-wait" id="excellence2-please-wait" style="display:none;"> <img src="<?php echo $this->getSkinUrl('images/opc-ajax-loader.gif') ?>" alt="<?php echo $this->__('Loading next step...') ?>" title="<?php echo $this->__('Loading next step...') ?>" class="v-middle" /> <?php echo $this->__('Loading next step...') ?> </span> </div> </fieldset> </form> <script type="text/javascript"> //<![CDATA[ var excellence2 = new ExcellenceMethod2('co-excellence2-form','<?php echo $this->getUrl('checkout/onepage/saveExcellence2') ?>'); var excellenceForm2 = new VarienForm('co-excellence2-form'); //]]> </script>
Step 8 : - now we need to create the excellencecheckout.js file on \ skin \ frontend \ default \ your template \ js
var ExcellenceMethod2 = Class.create(); ExcellenceMethod2.prototype = { initialize: function(form, saveUrl){ this.form = form; if ($(this.form)) { $(this.form).observe('submit', function(event){this.save();Event.stop(event);}.bind(this)); } this.saveUrl = saveUrl; this.validator = new Validation(this.form); this.onSave = this.nextStep.bindAsEventListener(this); this.onComplete = this.resetLoadWaiting.bindAsEventListener(this); }, validate: function() { return true; }, save: function(){ //alert('hi'); if (checkout.loadWaiting!=false) return; if (this.validate()) { checkout.setLoadWaiting('excellence2'); var request = new Ajax.Request( this.saveUrl, { method:'post', onComplete: this.onComplete, onSuccess: this.onSave, onFailure: checkout.ajaxFailure.bind(checkout), parameters: Form.serialize(this.form) } ); } }, resetLoadWaiting: function(transport){ checkout.setLoadWaiting(false); }, nextStep: function(transport){ if (transport && transport.responseText){ try{ response = eval('(' + transport.responseText + ')'); } catch (e) { response = {}; } } if (response.error) { alert(response.message); return false; } if (response.update_section) { $('checkout-'+response.update_section.name+'-load').update(response.update_section.html); } if (response.goto_section) { //alert(response); checkout.gotoSection(response.goto_section); checkout.reloadProgressBlock(); return; } checkout.setPayment(); } }
Step 9 : - now we need to create a new function to save the data that was selected by the user. therefore, we create a new function whose name is saveExcellence2 () immediately after finalizing saveShipping ($ data, $ customerAddressId) in Onepage.php, which is located in \ app \ code \ core \ Mage \ Checkout \ Model \ Type \
public function saveExcellence2($data) { if (empty($data)) { return array('error' => -1, 'message' => $this->_helper->__('Invalid data.')); } $this->getQuote()->setExcellenceLike2($data['like']); $this->getQuote()->collectTotals(); $this->getQuote()->save(); $this->getCheckout() ->setStepData('excellence2', 'complete', true) ->setStepData('shipping_method', 'allow', true); return array(); }