我在magento中删除运输方法有一个问题。我读了一些教程,但它仍然不起作用。当我对核心文件进行更改时,一切都运行良好,但我想根据最佳实践覆盖这些文件。
我想可能是config.xml有问题。
我的扩展:
CompanyName/
ExtensionName/
Block/
Onepage/
Abstract.php
controllers/
OnepageController.php
etc/
config.xml
Model/
Type/
Onepage.php
等/config . xml
<?xml version="1.0"?> <config>
<modules>
<CompanyName_ExtensionName>
<version>1.0</version>
</CompanyName_ExtensionName>
</modules>
<global>
<blocks>
<checkout>
<rewrite>
<onepage>CompanyName_ExtensionName_Block_Onepage</onepage>
</rewrite>
</checkout>
</blocks>
<frontend>
<routers>
<checkout>
<use>standard</use>
<args>
<modules>
<CompanyName_ExtensionName before="Mage_Checkout">
CompanyName_ExtensionName
</CompanyName_ExtensionName>
</modules>
</args>
</checkout>
</routers>
</frontend>
<models>
<checkout>
<rewrite>
<type_onepage>CompanyName_ExtensionName_Model_Type_Onepage</type_onepage>
</rewrite>
</checkout>
</models>
</global>
</config>
/块/Onepage/Abstract.php
abstract class CompanyName_ExtensionName_Onepage_Abstract extends Mage_Checkout_Block_Onepage_Abstract
{
protected function _getStepCodes()
{
return array('login','billing', 'payment', 'review');
}
}
/控制器/OnepageController.php
require_once 'Mage/Checkout/controllers/OnepageController.php';
class CompanyName_ExtensionName_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
class CompanyName_ExtensionName_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();
}
}
您正在尝试覆盖块Mage_Checkout_Block_Onepage_Abstract
。对于这个块,重写config.xml
中的代码应该如下所示:
<blocks>
<checkout>
<rewrite>
<onepage_abstract>CompanyName_ExtensionName_Block_Onepage_Abstract</onepage_abstract>
</rewrite>
</checkout>
</blocks>
您应该在app/code/local/Namespace/Modulename/Block/Onepage/Abstract.php
<?php
class Namespace_Modulename_Block_Onepage_Abstract extends Mage_Checkout_Block_Onepage_Abstract {
//rewrite code here
}
如果您的目的是删除Checkout页面:#3 Shipping Information和#4 Shipping Method,那么请遵循以下步骤:
设置:产品类型为:虚拟产品。这将关闭#3运输信息运输方法。
Checkout Process将变成:1. 付款方法2. 的付款信息3.支付信息4. 订单评审
适用于Version 1.7 - 1.9 CE
阅读Magento知识库:了解产品类型http://www.magentocommerce.com/knowledge-base/categories/category/product-types