我正在使用CE 1.9.1.0。
我正在尝试从一页结帐中删除“运送信息”和“运送方法”步骤,但没有成功。
也许有人可以帮助我或为我指明正确的方向?
我正在使用CE 1.9.1.0。
我正在尝试从一页结帐中删除“运送信息”和“运送方法”步骤,但没有成功。
也许有人可以帮助我或为我指明正确的方向?
Answers:
这是我所做的。
我删除了运送步骤,并使用了我知道总是可以使用的默认运送方法。
不知道这是否是您需要的,但是至少可以将其用作起点。
这是我的主意。
我使用enable/disable
发货步骤配置设置创建了一个新模块,因此您始终可以从此system->configuration
部分重新启用发货步骤。
因此,创建模块StackExchange_Checkout
。
您将需要以下文件。
app/etc/modules/StackExchange_Checkout.xml
-声明文件
<?xml version="1.0"?>
<config>
<modules>
<StackExchange_Checkout>
<active>true</active>
<codePool>local</codePool>
<depends>
<Mage_Checkout />
</depends>
</StackExchange_Checkout>
</modules>
</config>
app/code/local/StackExchange/Checkout/etc/config.xml
-在其中定义模型,块并重写一页校验块的配置文件。它还设置了默认的运输方式。
<?xml version="1.0"?>
<config>
<modules>
<StackExchange_Checkout>
<version>0.0.1</version>
</StackExchange_Checkout>
</modules>
<global>
<blocks>
<checkout>
<rewrite>
<onepage>StackExchange_Checkout_Block_Onepage</onepage><!-- rewrite the onepage chackout block -->
</rewrite>
</checkout>
</blocks>
<helpers>
<stackexchange_checkout>
<class>StackExchange_Checkout_Helper</class>
</stackexchange_checkout>
</helpers>
<models>
<stackexchange_checkout>
<class>StackExchange_Checkout_Model</class>
</stackexchange_checkout>
</models>
</global>
<default>
<checkout>
<options>
<hide_shipping>1</hide_shipping>
<default_shipping>tablerate_bestway</default_shipping><!-- set the default shipping method code -->
</options>
</checkout>
</default>
<frontend>
<routers>
<checkout>
<args>
<modules>
<StackExchange_Checkout before="Mage_Checkout">StackExchange_Checkout</StackExchange_Checkout>
</modules>
</args>
</checkout>
</routers>
<translate>
<modules>
<StackExchange_Checkout>
<files>
<default>StackExchange_Checkout.csv</default>
</files>
</StackExchange_Checkout>
</modules>
</translate>
</frontend>
</config>
app/code/local/StackExchange/Checkout/etc/system.xml
-放置用于装运步骤的启用/禁用标志的系统文件
<?xml version="1.0"?>
<config>
<sections>
<checkout>
<groups>
<options>
<fields>
<hide_shipping translate="label" module="stackexchange_checkout">
<label>Hide shipping method step</label>
<frontend_type>select</frontend_type>
<source_model>adminhtml/system_config_source_yesno</source_model>
<sort_order>100</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
</hide_shipping>
<default_shipping translate="label" module="stackexchange_checkout">
<label>Default shipping method code</label>
<frontend_type>text</frontend_type>
<sort_order>110</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
</default_shipping>
</fields>
</options>
</groups>
</checkout>
</sections>
</config>
app/code/local/StackExchange/Checkout/Helper/Data.php
-检查是否应禁用运送步骤的助手
<?php
class StackExchange_Checkout_Helper_Data extends Mage_Core_Helper_Abstract
{
const XML_HIDE_SHIPPING_PATH = 'checkout/options/hide_shipping';
const XML_DEFAULT_SHIPPING_PATH = 'checkout/options/default_shipping';
public function getHideShipping()
{
if (!Mage::getStoreConfigFlag(self::XML_HIDE_SHIPPING_PATH)){
return false;
}
if (!$this->getDefaultShippingMethod()){
return false;
}
return true;
}
public function getDefaultShippingMethod()
{
return Mage::getStoreConfig(self::XML_DEFAULT_SHIPPING_PATH);
}
}
app/code/local/StackExchange/Checkout/Block/Onepage.php
-覆盖的结帐块
<?php
class StackExchange_Checkout_Block_Onepage extends Mage_Checkout_Block_Onepage
{
protected function _getStepCodes()
{
if (!Mage::helper('stackexchange_checkout')->getHideShipping()){
return parent::_getStepCodes();
}
return array_diff(parent::_getStepCodes(), array('shipping_method'));
}
}
app/code/local/StackExchange/Checkout/controllers/OnepageController.php
-覆盖onepage控制器以自动设置默认的运输方式。
<?php
require 'Mage/Checkout/controllers/OnepageController.php';
class StackExchange_Checkout_OnepageController extends Mage_Checkout_OnepageController
{
public function saveBillingAction()
{
if (!Mage::helper('stackexchange_checkout')->getHideShipping()){
parent::saveBillingAction();
return;
}
if ($this->_expireAjax()) {
return;
}
if ($this->getRequest()->isPost()) {
$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) {
//add default shipping method
$data = Mage::helper('stackexchange_checkout')->getDefaultShippingMethod();
$result = $this->getOnepage()->saveShippingMethod($data);
$this->getOnepage()->getQuote()->save();
/*
$result will have erro data if shipping method is empty
*/
if(!$result) {
Mage::dispatchEvent('checkout_controller_onepage_save_shipping_method',
array('request'=>$this->getRequest(),
'quote'=>$this->getOnepage()->getQuote()));
$this->getOnepage()->getQuote()->collectTotals();
$this->getResponse()->setBody(Mage::helper('core')->jsonEncode($result));
$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));
}
}
public function saveShippingAction()
{
if (!Mage::helper('stackexchange_checkout')->getHideShipping()){
parent::saveShippingAction();
return;
}
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);
$data = Mage::helper('stackexchange_checkout')->getDefaultShippingMethod();
$result = $this->getOnepage()->saveShippingMethod($data);
$this->getOnepage()->getQuote()->save();
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));
}
}
}
清除缓存即可。
将您的产品设置为虚拟产品,它将自动删除。
我有一个比@marius更好的解决方案,它不需要任何重写。
您仍然需要创建自己的模块,其中有大量的教程,因此在此不再赘述。您必须创建一个观察者并通过触发它config.xml
。您可能需要调整模板app/design/frontend/base/default/template/checkout/onepage.phtml
在您的config.xml
:
<?xml version="1.0"?>
<config>
<modules>
<Namepace_Module>
<version>1.0.0</version>
</Namepace_Module>
</modules>
....
<frontend>
<events>
<controller_action_postdispatch_checkout_onepage_saveBilling>
<observers>
<namespace_module_skip_shipping_method>
<type>singleton</type>
<class>namespace_module/observer</class>
<method>controllerActionPostdispatchCheckoutOnepageSaveBilling</method>
</namespace_module_skip_shipping_method>
</observers>
</controller_action_postdispatch_checkout_onepage_saveBilling>
<controller_action_postdispatch_checkout_onepage_saveShipping>
<observers>
<namespace_module_skip_shipping_method>
<type>singleton</type>
<class>namespace_module/observer</class>
<method>controllerActionPostdispatchCheckoutOnepageSaveBilling</method>
</namespace_module_skip_shipping_method>
</observers>
</controller_action_postdispatch_checkout_onepage_saveShipping>
</events>
</frontend>
</config>
在你的 Model/Observer.php
class Namepsace_Module_Model_Observer {
/**
* @param Varien_Event_Observer $observer
*/
public function controllerActionPostdispatchCheckoutOnepageSaveBilling(Varien_Event_Observer $observer)
{
if (!Mage::helper('namespace_module')->skipShippingMethod()) {
return;
}
/* @var $controller Mage_Checkout_OnepageController */
$controller = $observer->getEvent()->getControllerAction();
$response = Mage::app()->getFrontController()->getResponse()->getBody(true);
if (!isset($response['default'])) {
return;
}
$response = Mage::helper('core')->jsonDecode($response['default']);
if ($response['goto_section'] == 'shipping_method') {
$response['goto_section'] = 'payment';
$response['update_section'] = array(
'name' => 'payment-method',
'html' => $this->_getPaymentMethodsHtml()
);
$controller->getResponse()->setBody(Mage::helper('core')->jsonEncode($response));
}
}
/**
* @return string
* @throws Mage_Core_Exception
*/
protected function _getPaymentMethodsHtml()
{
$layout = Mage::getModel('core/layout');
$update = $layout->getUpdate();
$update->load('checkout_onepage_paymentmethod');
$layout->generateXml();
$layout->generateBlocks();
return $layout->getOutput();
}
}
过去几天,我一直在寻找更简单的解决方案,因为我不想弄乱法师核心文件。因此,我想出了自己的解决方案。
检查运输方式的div并找到css文件。就我而言,文件位于
“ pub / static / frontend / myTheme / themeName / en_US / css / stye-m.css”
之后,我将覆盖当前的CSS,当然我对原始文件进行了备份。
CSS:
.step-title,.totals.shipping.incl {display:none!important;}#checkout-shipping-method-load {display:none!important;}
另外,我想知道此方法是否对任何文件有效。到目前为止,我还没有遇到任何问题。