【问题标题】:Magento skip shipping method on checkout pageMagento 在结帐页面上跳过送货方式
【发布时间】:2014-10-12 11:14:15
【问题描述】:

我有两种送货方式,免费送货和统一运费,其中免费送货的最低运费为 1500,统一运费的固定金额为 135。

我必须跳过一步结帐页面上的送货方式选项,但它应该应用于购物车中的总金额。

我在结帐页面上跳过了送货方式,但在付款结束时,它给了我错误,即 请指定送货方式

【问题讨论】:

    标签: php magento


    【解决方案1】:

    您需要覆盖 onepage 控制器和 onepage 块

    请参考以下代码。

    **Magento: Skip Shipping Method from onepage checkout**
    
    First override following files(i.e. in local directory) rather than changing the core:
    1) app/code/core/Mage/Checkout/Block/Onepage/Onepage.php
    2) app/code/core/mage/checkout/controller/Onepagecontrollers.php
    3) app/code/core/Mage/Sales/Model/Service/Quote.php
    4) app/design/frontend/base/default/template/checkout/onepage/progress.phtml
    5) app/code/core/Mage/Sales/Model/Service/Quote.php
    
    Once done follow the below steps:
    
    **Step 1: app/code/local/Mage/Checkout/Block/Onepage.php**
    
    Change the line:
    $stepCodes = array('billing', 'shipping', 'shipping_method', 'payment', 'review');
    
    In Magento 1.7+ you will find $stepCodes in for each just replace with below code 
    with:
    $stepCodes = array('billing', 'shipping', 'payment', 'review');
    
    
    **Step 2: app/code/local/Mage/Checkout/controller/Onepagecontrollers.php**
    
    Change the line:
    protected $_sectionUpdateFunctions = array(
    'payment-method' => '_getPaymentMethodsHtml',
    'shpping-method' => '_getShippingMeghtoHtml',
    'review' => '_getReviewHtml',
    );
    
    with:
    protected $_sectionUpdateFunctions = array(
    'payment-method' => '_getPaymentMethodsHtml',
    'review' => '_getReviewHtml',
    );
    
    
    **Step 3: app/code/local/Mage/Checkout/controller/Onepagecontrollers.php**
    
    Change saveBillingAction() function 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'] = 'payment';
    $result['update_section'] = array(
    'name' => 'payment-method',
    'html' => $this->_getPaymentMethodsHtml()
    );
    
    $result['allow_sections'] = array('shipping');
    $result['duplicateBillingInfo'] = 'true';
    } else {
    $result['goto_section'] = 'shipping';
    }
    }
    
    $this->getResponse()->setBody(Mage::helper('core')->jsonEncode($result));
    }
    }
    
    Change saveShippingAction() function with:
    
    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'] = 'payment';
    $result['update_section'] = array(
    'name' => 'payment-method',
    'html' => $this->_getPaymentMethodsHtml()
    );
    }
    $this->getResponse()->setBody(Mage::helper('core')->jsonEncode($result));
    }
    }
    
    **Step 4: app/code/local/Mage/Sales/Model/Service/Quote.php**
    
    Change _validate() function with:
    
    protected function _validate()
    {
    $helper = Mage::helper('sales');
    if (!$this->getQuote()->isVirtual()) {
    $address = $this->getQuote()->getShippingAddress();
    $addressValidation = $address->validate();
    if ($addressValidation !== true) {
    Mage::throwException(
    $helper->__('Please check shipping address information. %s', implode(' ', $addressValidation))
    );
    }
    }
    
    $addressValidation = $this->getQuote()->getBillingAddress()->validate();
    if ($addressValidation !== true) {
    Mage::throwException(
    $helper->__('Please check billing address information. %s', implode(' ', $addressValidation))
    );
    }
    
    if (!($this->getQuote()->getPayment()->getMethod())) {
    Mage::throwException($helper->__('Please select a valid payment method.'));
    }
    
    return $this;
    }
    
    
    **Step 5: app/design/frontend/default/default/template/checkout/onepage/progress.phtml**
    
    Remove the shipping method block.
    
    **Step 6: app/locale/en_US/template/email/sales/order_new.html**
    
    Remove the shipping method block(i.e. {{var order.getShippingDescription()}}).
    

    【讨论】:

    • 它确实隐藏了运输方式,但现在没有进入下一步。
    • 它正在与其他项目一起工作它可能与其他一些模块发生冲突
    • @无法从配送部分转到付款部分。卡住了,就像 Atif 提到的那样。
    猜你喜欢
    • 1970-01-01
    • 2012-09-27
    • 2014-10-25
    • 2015-09-13
    • 2021-05-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-07-06
    相关资源
    最近更新 更多