【问题标题】:Can't override Checkout in Magento 1.7.0.2无法覆盖 Magento 1.7.0.2 中的结帐
【发布时间】:2013-10-21 17:42:15
【问题描述】:

我似乎无法覆盖 Magento 中的 Checkout 控制器。 我复制了app/code/local/Checkout中的文件夹,但似乎不起作用。

其他人只是复制粘贴该文件夹似乎是正确的。 有什么需要做的吗?

【问题讨论】:

    标签: php magento magento-1.7 overriding checkout


    【解决方案1】:

    这不是扩展控制器的推荐方式。我假设您要扩展 Checkout OnepageController。

    这样做的正确方法是。

    1.) 识别正确的模块或为此创建一个新模块。

    app/code/local/Mel/Gallosa(记得在app/etc/modules中激活模块)

    添加文件 etc/config.xml 和 controllers/OnepageController.php

    您的文件内容将是

    <?xml version="1.0"?>
    <config>
        <modules>
            <Mel_Gallosa>
              <version>0.1.0</version>
            </Mel_Gallosa>
        </modules>
        <frontend>
            <routers>
                <checkout>
                    <use>standard</use>
                    <args>
                        <modules>
                            <Mel_Gallosa before="Mage_Checkout">Mel_Gallosa</Mel_Gallosa>
                        </modules>
                    </args>
                </checkout>
            </routers>
        </frontend>
    </config>
    

    然后是你的新控制器文件

    <?php
    require_once 'Mage/Checkout/controllers/OnepageController.php';
    class Mel_Gallosa_OnepageController extends Mage_Checkout_OnepageController
    {
        /*you can now overide any method here. Remember that you want to extend code in an Object Orientated fashion. Call the parent functions when appropriate and at the right time. Only replace methods that you are trying to overwrite. There is no need to dump all methods here. */
    
      //here is an example
    
      public function indexAction()
      {
          Mage::log('we have now overwritten the index action',null,'mel.log');
    
          parent::indexAction(); /* this means that if there are any core updates you will get them too :) */
      }
    }
    

    就是这样。我的建议不是简单地复制文件夹。清楚地考虑你正在尝试做什么,并确保你以后不要做“可能会射中你的脚”的事情。保持 OO 完好无损!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-08-28
      • 1970-01-01
      • 2012-08-25
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多