我在删除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>
/Block/Onepage/Abstract.php
abstract class CompanyName_ExtensionName_Onepage_Abstract extends Mage_Checkout_Block_Onepage_Abstract
{
protected function _getStepCodes()
{
return array('login','billing', 'payment', 'review');
}
}
/controllers/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));
}
}
}
/Model/Type/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();
}
}
我将不胜感激任何帮助。
答案 0 :(得分:0)
您正在尝试覆盖阻止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
}
答案 1 :(得分:-1)
如果您的目的是删除Checkout页面:#3送货信息和#4送货方式,请按以下步骤操作:
设置:产品类型为:虚拟产品。这将关闭#3运输信息&amp; #4送货方式。
结帐流程将变为: 1.结账方法 2.账单信息 3.付款信息 4.订单审核
适用于1.7版 - 1.9 CE
阅读Magento知识库:了解产品类型: http://www.magentocommerce.com/knowledge-base/categories/category/product-types