对于特定产品,我有一个购物车规则,它可以免费送货。不显示运输信息并绕过此类产品的运输方式选择是合乎逻辑的。有什么简单的方法可以做到这一点?
问问题
2792 次
1 回答
4
这可以通过扩展模块轻松完成。
/app/etc/modules/YourCompany_SkipShipping.xml
<?xml version="1.0"?>
<config>
<modules>
<YourCompany_SkipShipping>
<active>true</active>
<codePool>local</codePool>
<depends>
<Mage_Checkout />
</depends>
</YourCompany_SkipShipping>
</modules>
</config>
/app/code/local/YourCompany/SkipShipping/etc/config.xml
<?xml version="1.0"?>
<config>
<modules>
<YourCompany_SkipShipping>
<version>0.0.1</version>
</YourCompany_SkipShipping>
</modules>
<frontend>
<routers>
<checkout>
<modules before="Mage_Checkout">YourCompany_SkipShipping<modules>
</checkout>
</routers>
</frontend>
</config>
/app/code/local/YourCompany/SkipShipping/controllers/OnepageController.php
<?php
include "Mage/Checkout/controller/OnepageController.php"
class YourCompany_SkipShippingMethod_OnepageController
extends Mage_Checkout_OnepageController
{
public function saveBillingAction()
{
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) {
$method = $this->getAutoShippingMethod($data, $customerAddressId);
if (!empty($method)) {
$result = $this->getOnepage()->saveShippingMethod($method);
if(!$result) {
Mage::dispatchEvent('checkout_controller_onepage_save_shipping_method', array(
'request'=>$this->getRequest(),
'quote'=>$this->getOnepage()->getQuote()
));
$result['goto_section'] = 'payment';
$result['update_section'] = array(
'name' => 'payment-method',
'html' => $this->_getPaymentMethodsHtml()
);
}
} else {
$result['goto_section'] = 'shipping_method';
$result['update_section'] = array(
'name' => 'shipping-method',
'html' => $this->_getShippingMethodsHtml()
);
$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 ($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'])) {
$method = $this->getAutoShippingMethod($data, $customerAddressId);
if (!empty($method)) {
if(!$result) {
Mage::dispatchEvent('checkout_controller_onepage_save_shipping_method', array(
'request'=>$this->getRequest(),
'quote'=>$this->getOnepage()->getQuote()
));
$result['goto_section'] = 'payment';
$result['update_section'] = array(
'name' => 'payment-method',
'html' => $this->_getPaymentMethodsHtml()
);
}
} else {
$result['goto_section'] = 'shipping_method';
$result['update_section'] = array(
'name' => 'shipping-method',
'html' => $this->_getShippingMethodsHtml()
);
}
}
$this->getResponse()->setBody(Mage::helper('core')->jsonEncode($result));
}
}
public function getAutoShippingMethod($data, $customerAddressId)
{
// This is where you put your code to process the cart/order for orders that can auto-select shipping method
// For now, skip
return '';
}
}
我会将您如何检查运输方式的细节留给您,但如果您无法弄清楚,请发表评论,我也会添加。
注意:所有示例均基于 Magento 1.5
于 2011-09-02T23:04:11.993 回答