Magento自定义结账模块删除发货地址和方法


Magento Custom Checkout Module to Remove Shipping Address and Method

我正在尝试为MAGENTO CHECKOUT创建一个自定义模块,我想在其中删除SHIPPING ADDRESS AND SHIPPING METHOD步骤。

所以我的代码如下:

app/etc/Mona_Test.xml

<?xml version="1.0"?>
<config>
  <modules>
    <Mona_Test>
      <active>true</active>
      <codePool>local</codePool>
    </Mona_Test>
   </modules>
</config>

app/code/local/Mona/Test/etc/config.xml

<?xml version="1.0"?>
<config>
  <modules>
    <Mona_Test>
        <version>1.0</version>
    </Mona_Test>
  </modules>
  <global>
    <frontend>
        <routers>
            <checkout>
                <args>
                    <modules>
                        <Mona_Test before="Mage_Checkout">Mona_Test</Mona_Test>    
                    </modules>    
                </args>
            </checkout>
        </routers>
    </frontend>
    <blocks>
        <test>
            <class>Mona_Test_Block</class>
        </test>
        <checkout>
            <rewrite>
                <onepage_abstract>Mona_Test_Block_Onepage_Abstract</onepage_abstract>
            </rewrite>
        </checkout>
    </blocks>
    <models>
        <test>
            <class>Mona_Test_Model</class>
        </test>
        <checkout>
            <rewrite>
                <type_onepage>Mona_Test_Model_Type_Onepage</type_onepage>
            </rewrite>
        </checkout>
    </models>
  </global>
</config>

app/code/local/Mona/Test/Blocks/Onepage/Abstract.php

 <?php  
 class Mona_Test_Block_Onepage_Abstract extends Mage_Checkout_Block_Onepage_Abstract {
protected function _getStepCodes()
{
    return array('login', 'billing', 'payment', 'review');
}
}  

?>

app/code/local/Mona/Test/controllers/OnepageController.php

<?php
 require_once 'Mage/Checkout/controllers/OnepageController.php';
  class Mona_Test_OnepageController extends Mage_Checkout_OnepageController
 {
    protected $_sectionUpdateFunctions = array(
      'payment-method' => '_getPaymentMethodsHtml',
      'review' => '_getReviewHtml',
    );
public function saveBillingAction()
{
    if ($this->_expireAjax()) {
        return;
    }
    $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()
            );
        } else {
            $result['goto_section'] = 'payment';
        }
    }
    $this->getResponse()->setBody(Mage::helper('core')->jsonEncode($result));
}
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->_getShippingMethodsHtml()
            );
        }
        $this->getResponse()->setBody(Mage::helper('core')->jsonEncode($result));
    }
}

}

app/code/local/Mona/Test/Model/Type/Onepage.php

<?php
class Mona_Test_Model_Type_Onepage extends Mage_Checkout_Model_Type_Onepage
{
    public function saveShippingMethod($shippingMethod)
    {
        if (empty($shippingMethod)) {
            $shippingMethod = 'freeshipping_freeshipping';
        }
        $rate = $this->getQuote()->getShippingAddress()->getShippingRateByCode($shippingMethod);
        if (!$rate) {
            return array('error' => -1, 'message' => Mage::helper('checkout')->__('Invalid shipping method.'));
        }
        $this->getQuote()->getShippingAddress()
            ->setShippingMethod($shippingMethod);
        $this->getCheckout()
            ->setStepData('shipping_method', 'complete', true)
            ->setStepData('payment', 'allow', true);
        return array();
    }
}

?>

它不起作用。我还应该做什么?任何解决方案都将是伟大的。

Go to:
**app'code'core'Mage'Checkout'Block 'Onepage.php**
Change the code :
public function getSteps(){
 $steps = array();
 if (!$this->isCustomerLoggedIn()) {
 $steps['login'] = $this->getCheckout()->getStepData('login');
 }
 //$stepCodes = array('billing', 'shipping', 'shipping_method', 'payment', 'review');
 $stepCodes = array('billing', 'payment', 'review');
 foreach ($stepCodes as $step) {
 $steps[$step] = $this->getCheckout()->getStepData($step);
 }
 return $steps;
 }

Go to:
app'code'core'Mage'Checkout'controllers' OnepageController.php
Edit:
protected $_sectionUpdateFunctions = array(
 'payment-method' => '_getPaymentMethodsHtml',
 // 'shipping-method' => '_getShippingMethodsHtml',
 'review' => '_getReviewHtml',
 );
 Also edit  saveBillingAction() function
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'] = 'shipping_method';
 $result['update_section'] = array(
 'name' => 'shipping-method',
 'html' => $this->_getShippingMethodsHtml()
 );
 $result['allow_sections'] = array('shipping');
 $result['duplicateBillingInfo'] = 'true';
 }*/
 //End of Comment by Amit Bera
 else {
 //$result['goto_section'] = 'shipping';
 $result['goto_section'] = 'payment';
 }
 }
 $this->getResponse()->setBody(Mage::helper('core')->jsonEncode($result));
 }
 }
 Go to:
'app'code'core'Mage'Sales'Model'Service' Quote.php
Edit:

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))
 //);
 //}
 // $method= $address->getShippingMethod();
 //$rate = $address->getShippingRateByCode($method);
 //if (!$this->getQuote()->isVirtual() && (!$method || !$rate)) {
 //Mage::throwException($helper->__('Please specify a shipping method.'));
 //}
 }

在账单信息选项卡中,您可以看到发货地址作为账单地址的单选按钮,只需隐藏或删除即可–app''design''frontend''default''yourtemplate''yourtemplate''persistent''checkout''onepage''billing,phtml或app''design''frontend''default''您的模板''template''checkout''onepage''billing.html

In  app'locale'en_US'template'email'sales' order_new.html
From
{{var order.getShippingAddress().format('html')}}
To
{{var order.getBillingAddress().format('html')}}
And
{{var order.getShippingDescription()}}
Remove it.  

你也可以参考下面的链接

http://www.bluehorse.in/blog/removed-shipping-address-and-shipping-method-from-onepage-checkout-in-magento.html