我正在尝试为 MAGENTO CHECKOUT 创建一个自定义模块,其中我想删除运送地址和运输方法步骤。
所以我的代码如下所示:
应用程序的/ etc / Mona_Test.xml
<?xml version="1.0"?>
<config>
<modules>
<Mona_Test>
<active>true</active>
<codePool>local</codePool>
</Mona_Test>
</modules>
</config>
应用程序/代码/本地/莫纳/测试的/ 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>
应用程序/代码/本地/莫纳/测试/块/ 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');
}
}
&GT;
应用程序/代码/本地/莫纳/测试/控制器/ 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));
}
}
}
应用程序/代码/本地/莫纳/测试/型号/类型/ 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();
}
}
&GT;
它不起作用。我还应该怎么办?任何解决方案都会很棒。
答案 0 :(得分:2)
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 \ your template \ yourtemplate \ 持久\结账\ onepage \计费,PHTML 要么 app \ design \ frontend \ default \ your template \ template \ checkout \ onepage \ billing.phtml
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.
您也可以参考以下链接