首页>Magento>source

我想跳过 payment method   当 Grandtotal   是

任何帮助将不胜感激。

谢谢!!

最新回答
  • 2019-12-5
    1 #

    试试这个!

    <?php
    require_once(Mage::getModuleDir('controllers','Mage_Checkout').DS.'OnepageController.php');
    class SR_MagentoCommunity_OnepageController extends Mage_Checkout_OnepageController
    {
        /**
         * Save checkout billing address
         */
        public function saveBillingAction()
        {
            if ($this->_expireAjax()) {
                return;
            }
            if ($this->isFormkeyValidationOnCheckoutEnabled() && !$this->_validateFormKey()) {
                return;
            }
            if ($this->getRequest()->isPost()) {
                $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'])) {
                    if ($this->getOnepage()->getQuote()->isVirtual()) {
                        if ($this->getOnepage()->getQuote()->getGrandTotal() <= 0) {
                            $paymentData = array('method' => 'free');
                            $this->getOnepage()->savePayment($paymentData);
                            $this->loadLayout('checkout_onepage_review');
                            $result['goto_section'] = 'review';
                            $result['update_section'] = array(
                                'name' => 'review',
                                'html' => $this->_getReviewHtml()
                            );
                        } else {
                            $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'] = 'shipping_method';
                        $result['update_section'] = array(
                            'name' => 'shipping-method',
                            'html' => $this->_getShippingMethodsHtml()
                        );
                        $result['allow_sections'] = array('shipping');
                        $result['duplicateBillingInfo'] = 'true';
                    } else {
                        $result['goto_section'] = 'shipping';
                    }
                }
                $this->_prepareDataJSON($result);
            }
        }
        /**
         * Shipping method save action
         */
        public function saveShippingMethodAction()
        {
            if ($this->_expireAjax()) {
                return;
            }
            if ($this->isFormkeyValidationOnCheckoutEnabled() && !$this->_validateFormKey()) {
                return;
            }
            if ($this->getRequest()->isPost()) {
                $data = $this->getRequest()->getPost('shipping_method', '');
                $result = $this->getOnepage()->saveShippingMethod($data);
                // $result will contain error data if shipping method is empty
                if (!$result) {
                    Mage::dispatchEvent(
                        'checkout_controller_onepage_save_shipping_method',
                         array(
                              'request' => $this->getRequest(),
                              'quote'   => $this->getOnepage()->getQuote()));
                    $this->getOnepage()->getQuote()->collectTotals();
                    $this->_prepareDataJSON($result);
                    if ($this->getOnepage()->getQuote()->getGrandTotal() <= 0) {
                        $paymentData = array('method' => 'free');
                        $this->getOnepage()->savePayment($paymentData);
                        $this->loadLayout('checkout_onepage_review');
                        $result['goto_section'] = 'review';
                        $result['update_section'] = array(
                            'name' => 'review',
                            'html' => $this->_getReviewHtml()
                        );
                    } else {
                        $result['goto_section'] = 'payment';
                        $result['update_section'] = array(
                            'name' => 'payment-method',
                            'html' => $this->_getPaymentMethodsHtml()
                        );
                    }
                }
                $this->getOnepage()->getQuote()->collectTotals()->save();
                $this->_prepareDataJSON($result);
            }
        }
        /**
         * Create order action
         */
        public function saveOrderAction()
        {
            $this->getOnepage()->getQuote()->collectTotals()->save();
            return parent::saveOrderAction();
        }
    }
    

    Overwrite Mage_Checkout_Block_Onepage_Payment class:

    <blocks>
        <checkout>
            <rewrite>
                <onepage_payment>SR_MagentoCommunity_Block_Onepage_Payment</onepage_payment>
            </rewrite>
        </checkout>
    </blocks>
    

    app/code/local/SR/MagentoCommunity/Block/Onepage/Payment.php

    <?php
    class SR_MagentoCommunity_Block_Onepage_Payment extends Mage_Checkout_Block_Onepage_Payment
    {
        /**
         * Retrieve is allow and show block
         *
         * @return bool
         */
        public function isShow()
        {
            if ($this->getGrandTotal() <= 0) {
                return false;
            }
            return true;
        }
        private function getGrandTotal()
        {
            return Mage::getSingleton('checkout/type_onepage')->getQuote()->getGrandTotal();
        }
    }
    

    最后,覆盖

    skin/frontend/base/default/js/opcheckout.js

    ShippingMethod.prototype.nextStep = function(transport){
        var response = transport.responseJSON || transport.responseText.evalJSON(true) || {};
        if (response.error) {
            alert(response.message.stripTags().toString());
            return false;
        }
        if (response.update_section) {
            $('checkout-'+response.update_section.name+'-load').update(response.update_section.html);
        }
        if (response.goto_section) {
            checkout.gotoSection(response.goto_section, true);
            checkout.reloadProgressBlock();
            return;
        }
        payment.initWhatIsCvvListeners();
        if (response.payment_methods_html) {
            $('checkout-payment-method-load').update(response.payment_methods_html);
        }
        checkout.setShippingMethod();
    };
    Review.prototype.save = function(){
        if (checkout.loadWaiting!=false) return;
        checkout.setLoadWaiting('review');
        if (!$('#co-payment-form')) {
            var params = 'method=free';
        } else {
            var params = Form.serialize(payment.form);
        }
    
        if (this.agreementsForm) {
            params += '&'+Form.serialize(this.agreementsForm);
        }
        params.save = true;
        new Ajax.Request(
            this.saveUrl,
            {
                method:'post',
                parameters:params,
                onComplete: this.onComplete,
                onSuccess: this.onSave,
                onFailure: checkout.ajaxFailure.bind(checkout)
            }
        );
    };
    

    [Update]

    How you overwrite opcheckout.js?

    skin/frontend/base/default/js/rewriteopcheckout.js

    ShippingMethod.prototype.nextStep = function(transport){
        var response = transport.responseJSON || transport.responseText.evalJSON(true) || {};
        if (response.error) {
            alert(response.message.stripTags().toString());
            return false;
        }
        if (response.update_section) {
            $('checkout-'+response.update_section.name+'-load').update(response.update_section.html);
        }
        if (response.goto_section) {
            checkout.gotoSection(response.goto_section, true);
            checkout.reloadProgressBlock();
            return;
        }
        payment.initWhatIsCvvListeners();
        if (response.payment_methods_html) {
            $('checkout-payment-method-load').update(response.payment_methods_html);
        }
        checkout.setShippingMethod();
    };
    Review.prototype.save = function(){
        if (checkout.loadWaiting!=false) return;
        checkout.setLoadWaiting('review');
        if (!$('#co-payment-form')) {
            var params = 'method=free';
        } else {
            var params = Form.serialize(payment.form);
        }
    
        if (this.agreementsForm) {
            params += '&'+Form.serialize(this.agreementsForm);
        }
        params.save = true;
        new Ajax.Request(
            this.saveUrl,
            {
                method:'post',
                parameters:params,
                onComplete: this.onComplete,
                onSuccess: this.onSave,
                onFailure: checkout.ajaxFailure.bind(checkout)
            }
        );
    };
    

    现在打开 checkout/onepage.phtml   当前主题中的模板.防爆.我的情况是默认的 rwd/default

    app/design/frontend/rwd/default/template/checkout/onepage.phtml

    添加以下行:

    <script type="text/javascript" src="<?php echo $this->getSkinUrl('js/rewriteopcheckout.js') ?>"></script>
    

    我已经使用带有样本数据的全新安装测试了M1.9.4.1。

  • 2019-12-5
    2 #

    上述问题的受影响文件是

    {Magento-Root-Folder}/app/design/frontend/{YourTheme}/default/template/checkout/onepage/payment/methods.phtml

    请注意,如果模板文件夹中没有"checkout"文件夹,请务必从 {Magento-Root-Folder}/app/design/frontend/base/default/template/checkout复制它   到您的模板文件夹; 确保你保持结构相同

    在这个文件(methods.phtml)中我们实际查看了可用的付款(第45行),这是我们需要调整一点的地方。

    1)将此行放在文件顶部的任意位置以获取当前报价数据(我们将在步骤2中使用它)

    $quote_data = Mage::helper('checkout')->getQuote()->getData();
    

    它将包含 $quote_data[grand_total]

    2)搜索围绕第45行迭代的付款方式

    foreach ($methods as $_method):
        $_code = $_method->getCode();
    

    我们需要检查$ _code('free'表示zero Subtotal Checkout)并在同一个foreach中添加一个简单的if子句:

    if ($_code == "free" && $quote_data[grand_total] < 1) { // if payment method is free and grand total '0'
        // this is where your action should happen
        $class_show_pm = ""; // will be used to show/hide 'dt' tag
        $radio_checked = "checked"; // will be used to enable/disable radio button
        $radio_onclick = "payment.switchMethod(" .$_code .")"; // will be used to load js code
    } else {
        $class_show_pm = "none";
        $radio_checked = "";
        $radio_onclick = "";
    }
    

    如果总计0太

    ,您可以查看此跳过付款步骤

    我希望这会有所帮助

  • user:我如何获得具有高权限的帐户?
  • magento2:如果缓存已在magento 2中已被删除,是否需要清除缓存以进行布局更改