如何在magento单页结帐流程中添加驱动程序提示? [英] How can i add a driver tip in magento onepage checkout process?

查看:69
本文介绍了如何在magento单页结帐流程中添加驱动程序提示?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前,我需要在送货方法(步骤3)之后立即在magento单页结帐流程中添加自定义的驱动程序提示步骤,在该方法中,我希望用户从给定的某些方法中选择提示选项(我将制作单选按钮),其中将包含一定金额,假设用户选择了$ 150,那么这笔金额会添加到总付款中吗?我在Google上尝试了所有其他教程,但都没有为我工作,感谢您的帮助,

Currently i have an requirement of adding a custom Driver tip step in magento onepage checkout process, right after the shipping method(step-3), in which i want user to select tip from some given options(i will make radio buttons), that will contain certain amounts, suppose user selected $150 then this amount will be added into total payment ? i tried all other tutorials over google, none of them is working for me, any help is appreciated,

推荐答案

我最近致力于类似类型的需求. 因此,请按照我的指示进行:-

I recently work on similar type of requirement. so follow my instructions:-

我要求您不要仅仅关注答案的长度

第1步:-如果您要在运输方式和运输方式之间添加驱动程序提示,请先打开

step 1:-if you want to put Driver tip between shipping and shipping method then first open

\ app \ code \ core \ Mage \ Checkout \ Block \ Onepage.php 有一个数组$ stepCodes(行号:-44). 替换成这个

\app\code\core\Mage\Checkout\Block\Onepage.php there is an array $stepCodes (line no:- 44). replace that with this

$stepCodes = array('billing', 'shipping', 'excellence2','shipping_method', 'payment', 'review'); 

我正在使用 excellence2 ,您也可以使用此名称.

i am using excellence2 you can also use this name.

第2步:- 现在我们需要在app \ code \ core \ Mage \ Checkout \ Block \ Onepage \上创建Excellence2类 因此,请创建一个新的php文件,并将该代码放入其中,并另存为Excellence2.php

Step 2:- now we need to create Excellence2 class on app\code\core\Mage\Checkout\Block\Onepage\ so create a new php file and put that code into it and save 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();

}
}

注意:-现在您可以在_construct()函数的标签上放置任何名称,因此可以将'Tip Ammount'更改为 Driver tip

Note:- now you can put any name at label of _construct() function so change 'Tip Ammount' to Driver tip

第3步:-现在打开位于应用程序\ code \ core \ Mage \ Checkout \ controllers \中的 OnepageController.php 并找到 saveBillingAction() 函数(行号:-296)并用此代码替换该代码

Step 3:-now open OnepageController.php which is located in app\code\core\Mage\Checkout\controllers\ and find saveBillingAction() function (line no:-296) and replace that code by this

 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));
    }
}

第4步:-在同一文件 OnepageController.php 中,还有一个saveShippingAction()函数(第331行)将其更改为

Step 4:- again in same file OnepageController.php there is a saveShippingAction() function (line no 331) change this 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'; //Go to our step
        }
        $this->getResponse()->setBody(Mage::helper('core')->jsonEncode($result));
    }
  }

此代码告诉我们,当用户通过发货步骤时,他将转到我们的驾驶员提示步骤.

this code tells that when user pass though the shipping step then he will go to our Driver tip step.

第5步:-再次在同一文件( OnepageController.php )中,我们需要告知用户通过 Driver tip 后,用户将重定向到何处>步骤.so在saveShippingAction()函数之后立即创建一个saveExcellence2Action()

Step 5:-again in same file (OnepageController.php) we need to tell that where user will redirect after pass though Driver tip step .so create a saveExcellence2Action() just after 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));
    }
}

第6步:-现在我们更改了

\ app \ design \ frontend \ default \您的模板\布局打开它并找到

\app\design\frontend\default\your template\layout open it and find

<checkout_onepage_index translate="label">

并且在该特定节点中有块(第326行)

and in that particular node there is block (line no 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"/>

第7步:-现在,我们需要在以下位置创建一个 excellence2.phtml 文件 \ app \ design \ frontend \ default \您的模板\ template \ checkout \ onepage \

Step 7:- now we need to create a excellence2.phtml file at \app\design\frontend\default\your template\template\checkout\onepage\

此文件显示了要显示给用户的内容

this file show the content which you want to show to user

<form id="co-excellence2-form" action="">
<div class="wide"> <label for="excellence2:like" class="required"><em  style="color:#F00;">*</em>&nbsp;&nbsp;&nbsp;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);"/>&nbsp;&nbsp;&nbsp;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);" />&nbsp;&nbsp;&nbsp;150$
</li>
<li>
<input type="radio" name="excellence2[like]" id="excellence2:like" value="250" class="radio"  onclick="savevalue(this.value);"/>&nbsp;&nbsp;&nbsp;250$
</li>
<li>
<input type="radio" name="excellence2[like]" id="excellence2:like" value="400" class="radio" onclick="savevalue(this.value);" />&nbsp;&nbsp;&nbsp;400$
</li>
<li>
<input type="radio" name="excellence2[like]" id="excellence2:like" value="500" class="radio"  onclick="savevalue(this.value);"/>&nbsp;&nbsp;&nbsp;500$
</li>
<li>
<input type="radio" name="excellence2[like]" id="excellence2:like" value="15% of total amount" class="radio" onclick="savevalue(this.value);" />&nbsp;&nbsp;&nbsp;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>

第8步:-现在,我们需要在以下位置创建 excellencecheckout.js 文件 \ skin \ frontend \ default \您的模板\ js

Step 8:-now we need to create a excellencecheckout.js file at \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();
}
}

第9步:-现在我们需要创建一个新功能来保存所选用户的数据. 因此我们在Onepage.php中的saveShipping($ data,$ customerAddressId)函数之后创建一个名为 saveExcellence2()的新函数,该函数位于\ app \ code \ core \ Mage \ Checkout \型号\类型\

Step 9:- now we need to create a new function for save data which user was selected . so we are creating new function which name is saveExcellence2() just after the saveShipping($data, $customerAddressId) finction 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();
}

这篇关于如何在magento单页结帐流程中添加驱动程序提示?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆