0

我正在为客户编写一种新的运输方式;我的运输计算很顺利,它们出现在“运输方法”步骤中 - 但是,我想:

a) 在用户点击第一个(计费)选项卡中的继续按钮触发的 billing.save() 后,强制打开“运送信息”选项卡,即使他们选择运送到帐单地址;和

b) 在运输信息选项卡中添加“已收货”、“运输保证”和“尾卡车取货”选项 - 重新计算运输报价时将考虑这些选项。

在 b) 部分中,我假设我使用 /layout 中的 xml 配置文件覆盖 shipping.phtml 模板,然后在 collectRates() 方法中查找那些添加的帖子字段。

提前致谢!

4

1 回答 1

2

至于 a) 部分,您将需要覆盖控制器Mage_Checkout_OnepageController。为此,请创建您自己的模块(我假设您知道如何执行此操作),并且在 app/code/local/YourModule/etc/config.xml 中您应该有这部分:

<config>
...
    <frontend>
        <routers>
            <checkout>
                <args>
                    <modules>
                        <YourModule_Checkout before="Mage_Checkout">YourModule_Checkout</YourModule_Checkout>
                    </modules>
                </args>
            </checkout>
        </routers>
    </frontend>
</config>

然后在 app/code/local/YourModule/controllers/OnepageController.php 中您要覆盖该行为,因此当您单击保存计费按钮时,您将始终登陆运输页面。

include_once("Mage/Checkout/controllers/OnepageController.php");

class YourModule_Checkout_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()
                );
            } else { // Removed elseif block here which usually skips over shipping if you selected to use the same address as in billing
                $result['goto_section'] = 'shipping';
            }
        }

        $this->getResponse()->setBody(Mage::helper('core')->jsonEncode($result));
    }
  }
}

然后对于 b) 部分,您有两个选择。正如您所指出的,您使用 XML 布局系统为 shipping.phtml 设置不同的模板:

<checkout_onepage_index>
   <reference name="checkout.onepage.shipping">
      <action method="setTemplate">
         <new>my_shipping.phtml</new>
      </action>
   </reference>
</checkout_onepage_index>

甚至更简单,您可以使用自定义设计文件夹覆盖 shipping.phtml 模板。为了评估您的自定义数据,模型Mage_Checkout_Model_Type_Onepage会处理方法中的数据saveShipping(),所以我想这将是寻找实现您的自定义逻辑的好点。

于 2013-01-08T15:23:21.380 回答