草庐IT

php - 如何在 magento 单页结帐过程中添加驱动程序提示?

coder 2024-04-17 原文

目前我需要在 magento 单页结帐过程中添加自定义 Driver tip 步骤,紧接在送货方式(第 3 步)之后,我希望用户从一些给定的提示中选择提示选项(我会制作单选按钮),其中包含一定的金额,假设用户选择了 150 美元,那么这笔金额将被添加到总付款中?我通过谷歌尝试了所有其他教程,但没有一个对我有用,感谢任何帮助,

最佳答案

我最近在处理类似类型的需求。 所以按照我的指示:-

我要求你不要关注答案的长度,只关注结果

第 1 步:-如果您想在送货和送货方式之间添加司机提示,请先打开

\app\code\core\Mage\Checkout\Block\Onepage.php 有一个数组 $stepCodes(第 44 行)。 用这个替换它

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

我用的是excellence2 你也可以用这个名字。

第 2 步:- 现在我们需要在 app\code\core\Mage\Checkout\Block\Onepage\上创建 Excellence2 类 所以创建一个新的 php 文件并将该代码放入其中并另存为 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

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

 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 行)将其更改为

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

此代码告诉用户,当用户通过运送步骤时,他将转到我们的司机提示步骤。

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

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 步:- 现在我们更改位于

的 checkout.xml

\app\design\frontend\default\your template\layout 打开找到

<checkout_onepage_index translate="label">

并且在那个特定节点中有 block (第 326 行)

<block type="checkout/onepage_shipping" name="checkout.onepage.shipping" as="shipping" template="checkout/onepage/shipping.phtml"/>

只需在上面显示的这一行之后添加一个新 block

<block type="checkout/onepage_excellence2" name="checkout.onepage.excellence2" as="excellence2" template="checkout/onepage/excellence2.phtml"/>

第 7 步:- 现在我们需要创建一个 excellence2.phtml 文件 \app\design\frontend\default\your template\template\checkout\onepage\

这个文件展示了你想要展示给用户的内容

<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 文件 \皮肤\前端\默认\你的模板\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 步:- 现在我们需要创建一个新函数来保存选定用户的数据。 所以我们在位于\app\code\core\Mage\Checkout\型号\类型\

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

关于php - 如何在 magento 单页结帐过程中添加驱动程序提示?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16188758/

有关php - 如何在 magento 单页结帐过程中添加驱动程序提示?的更多相关文章

  1. ruby - 如何在 Ruby 中顺序创建 PI - 2

    出于纯粹的兴趣,我很好奇如何按顺序创建PI,而不是在过程结果之后生成数字,而是让数字在过程本身生成时显示。如果是这种情况,那么数字可以自行产生,我可以对以前看到的数字实现垃圾收集,从而创建一个无限系列。结果只是在Pi系列之后每秒生成一个数字。这是我通过互联网筛选的结果:这是流行的计算机友好算法,类机器算法:defarccot(x,unity)xpow=unity/xn=1sign=1sum=0loopdoterm=xpow/nbreakifterm==0sum+=sign*(xpow/n)xpow/=x*xn+=2sign=-signendsumenddefcalc_pi(digits

  2. ruby - 在 Ruby 程序执行时阻止 Windows 7 PC 进入休眠状态 - 2

    我需要在客户计算机上运行Ruby应用程序。通常需要几天才能完成(复制大备份文件)。问题是如果启用sleep,它会中断应用程序。否则,计算机将持续运行数周,直到我下次访问为止。有什么方法可以防止执行期间休眠并让Windows在执行后休眠吗?欢迎任何疯狂的想法;-) 最佳答案 Here建议使用SetThreadExecutionStateWinAPI函数,使应用程序能够通知系统它正在使用中,从而防止系统在应用程序运行时进入休眠状态或关闭显示。像这样的东西:require'Win32API'ES_AWAYMODE_REQUIRED=0x0

  3. ruby - 我需要将 Bundler 本身添加到 Gemfile 中吗? - 2

    当我使用Bundler时,是否需要在我的Gemfile中将其列为依赖项?毕竟,我的代码中有些地方需要它。例如,当我进行Bundler设置时:require"bundler/setup" 最佳答案 没有。您可以尝试,但首先您必须用鞋带将自己抬离地面。 关于ruby-我需要将Bundler本身添加到Gemfile中吗?,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.com/questions/4758609/

  4. ruby - 如何在 buildr 项目中使用 Ruby 代码? - 2

    如何在buildr项目中使用Ruby?我在很多不同的项目中使用过Ruby、JRuby、Java和Clojure。我目前正在使用我的标准Ruby开发一个模拟应用程序,我想尝试使用Clojure后端(我确实喜欢功能代码)以及JRubygui和测试套件。我还可以看到在未来的不同项目中使用Scala作为后端。我想我要为我的项目尝试一下buildr(http://buildr.apache.org/),但我注意到buildr似乎没有设置为在项目中使用JRuby代码本身!这看起来有点傻,因为该工具旨在统一通用的JVM语言并且是在ruby中构建的。除了将输出的jar包含在一个独特的、仅限ruby​​

  5. ruby - 什么是填充的 Base64 编码字符串以及如何在 ruby​​ 中生成它们? - 2

    我正在使用的第三方API的文档状态:"[O]urAPIonlyacceptspaddedBase64encodedstrings."什么是“填充的Base64编码字符串”以及如何在Ruby中生成它们。下面的代码是我第一次尝试创建转换为Base64的JSON格式数据。xa=Base64.encode64(a.to_json) 最佳答案 他们说的padding其实就是Base64本身的一部分。它是末尾的“=”和“==”。Base64将3个字节的数据包编码为4个编码字符。所以如果你的输入数据有长度n和n%3=1=>"=="末尾用于填充n%

  6. ruby - 如何指定 Rack 处理程序 - 2

    Rackup通过Rack的默认处理程序成功运行任何Rack应用程序。例如:classRackAppdefcall(environment)['200',{'Content-Type'=>'text/html'},["Helloworld"]]endendrunRackApp.new但是当最后一行更改为使用Rack的内置CGI处理程序时,rackup给出“NoMethodErrorat/undefinedmethod`call'fornil:NilClass”:Rack::Handler::CGI.runRackApp.newRack的其他内置处理程序也提出了同样的反对意见。例如Rack

  7. ruby - 在 Ruby 中编写命令行实用程序 - 2

    我想用ruby​​编写一个小的命令行实用程序并将其作为gem分发。我知道安装后,Guard、Sass和Thor等某些gem可以从命令行自行运行。为了让gem像二进制文件一样可用,我需要在我的gemspec中指定什么。 最佳答案 Gem::Specification.newdo|s|...s.executable='name_of_executable'...endhttp://docs.rubygems.org/read/chapter/20 关于ruby-在Ruby中编写命令行实用程序

  8. ruby - 将 Bootstrap Less 添加到 Sinatra - 2

    我有一个ModularSinatra应用程序,我正在尝试将Bootstrap添加到应用程序中。get'/bootstrap/application.css'doless:"bootstrap/bootstrap"end我在views/bootstrap中有所有less文件,包括bootstrap.less。我收到这个错误:Less::ParseErrorat/bootstrap/application.css'reset.less'wasn'tfound.Bootstrap.less的第一行是://CSSReset@import"reset.less";我尝试了所有不同的路径格式,但它

  9. ruby-on-rails - 如何在 ruby​​ 中使用两个参数异步运行 exe? - 2

    exe应该在我打开页面时运行。异步进程需要运行。有什么方法可以在ruby​​中使用两个参数异步运行exe吗?我已经尝试过ruby​​命令-system()、exec()但它正在等待过程完成。我需要用参数启动exe,无需等待进程完成是否有任何ruby​​gems会支持我的问题? 最佳答案 您可以使用Process.spawn和Process.wait2:pid=Process.spawn'your.exe','--option'#Later...pid,status=Process.wait2pid您的程序将作为解释器的子进程执行。除

  10. ruby-on-rails - Rails 应用程序之间的通信 - 2

    我构建了两个需要相互通信和发送文件的Rails应用程序。例如,一个Rails应用程序会发送请求以查看其他应用程序数据库中的表。然后另一个应用程序将呈现该表的json并将其发回。我还希望一个应用程序将存储在其公共(public)目录中的文本文件发送到另一个应用程序的公共(public)目录。我从来没有做过这样的事情,所以我什至不知道从哪里开始。任何帮助,将不胜感激。谢谢! 最佳答案 无论Rails是什么,几乎所有Web应用程序都有您的要求,大多数现代Web应用程序都需要相互通信。但是有一个小小的理解需要你坚持下去,网站不应直接访问彼此

随机推荐