使用自定义控制器覆盖CsMarketplace帐户控制器 [英] Overriding CsMarketplace account controller with a custom controller

查看:105
本文介绍了使用自定义控制器覆盖CsMarketplace帐户控制器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

阅读&研究很多,我今天问这个问题,很多代码可以覆盖核心magento文件,但不是magento插件文件。



我已经安装CsMarketplace插件到我的网站供应商管理。



我想要覆盖供应商 - 注册函数来写我需要在供应商成功注册后才能工作的自定义代码。



需要覆盖:function createPostAction();
在文件mypoject / app / code / local / Ced / CsMarketplace / controllers / AccountController.php



文件1:mypoject / app / code / local / Core /Ced/CsMarketplace/controllers/AccountController.php

  require_once'app / code / local / Ced / CsMarketplace / controllers / AccountController。 php'; 

类Core_Ced_CsMarketplace_AccountController extends Ced_CsMarketplace_Controller_AbstractController {

/ **
*创建客户帐户操作
* /
public function createPostAction b $ b //我的自定义代码
}
}

文件2: mypoject / app / code / local / Core / Ced / CsMarketplace / etc / config.xml

 <?xml version = 1.0→> 
< config>
< modules>
< Core_Ced_CsMarketplace>
< version> 1.0< / version>
< / Core_Ced_CsMarketplace>
< / modules>
< frontend>
< routers>
< CsMarketplace>
< args>
< modules>
< Core_Ced_CsMarketplace before =Ced_CsMarketplace> Core_Ced_CsMarketplace< / Core_Ced_CsMarketplace>
< / modules>
< / args>
< / CsMarketplace>
< / routers>
< / frontend>
< / config>

档案3:mypoject / app / etc / modules / Core_All.xml

 <?xml version =1.0?> 
< config>
< modules>
< Core_Customer>
< active> true< / active>
< codePool> local< / codePool>
< / Core_Customer>
< Core_Ced_CsMarketplace>
< active> true< / active>
< codePool> local< / codePool>
< / Core_Ced_CsMarketplace>
< / modules>
< / config>


解决方案

您的控制器放置在文件系统中。 Magento总是假定位于 controllers 目录下的控制器位于<$> 之下,该目录本身正好位于Namespace + Modulename文件夹中,例如

  app / code / [codepool] / [Namespace] / [Modulename] / controllers /#我以前错过了codepool,因为Magento 2 :-) 

您正试图让系统找到控制器在其设计位置找不到它们。 / p>

(根据OP注释编辑)



控制器需要 / strong>深度级别(命名空间+模块名称)。以下不工作:

  app / code / local / Namespace / controllers 
app / code / local /命名空间/模块名/ SomeOtherFolder / controllers

在您的情况下,您可以选择 CustomCed 作为您的命名空间,提供:

  app / code / local / CustomCsd / CsMarketplace / controllers / AccountController .php 

在这里你将覆盖 createPostAction()



此外,根据您的操作,您可以使用控制器动作调度周围存在的动态事件之一


After reading & researching a lot i am asking this question today, lot of code available to override core magento files but not magento plugin files.

I have installed CsMarketplace plugin to my website for vendor management.

I want to override the vendor - register function to write my custom code which needs to work just after vendor is successfully registered.

Need to override: function createPostAction(); in file mypoject/app/code/local/Ced/CsMarketplace/controllers/AccountController.php

File 1: mypoject/app/code/local/Core/Ced/CsMarketplace/controllers/AccountController.php

require_once 'app/code/local/Ced/CsMarketplace/controllers/AccountController.php';

class Core_Ced_CsMarketplace_AccountController extends Ced_CsMarketplace_Controller_AbstractController {

/**
 * Create customer account action
 */
  public function createPostAction() {
    //my custom code
  }
}

File 2: mypoject/app/code/local/Core/Ced/CsMarketplace/etc/config.xml

<?xml version="1.0"?>
<config>
<modules>
    <Core_Ced_CsMarketplace>
        <version>1.0</version>
    </Core_Ced_CsMarketplace>
</modules>
<frontend>
    <routers>
        <CsMarketplace>
            <args>
                <modules>
                    <Core_Ced_CsMarketplace before="Ced_CsMarketplace">Core_Ced_CsMarketplace</Core_Ced_CsMarketplace>
                </modules>
            </args>
        </CsMarketplace>
    </routers>
</frontend>
</config>

File 3: mypoject/app/etc/modules/Core_All.xml

<?xml version="1.0"?>
<config>
 <modules>
    <Core_Customer>
        <active>true</active>
        <codePool>local</codePool>
    </Core_Customer>
    <Core_Ced_CsMarketplace>
        <active>true</active>
        <codePool>local</codePool>
    </Core_Ced_CsMarketplace>
</modules>
</config>

解决方案

Your controller is incorrectly placed in the filesystem. Magento always assumes that controllers located somewhere under a controllers directory which is itself exactly inside just a Namespace + Modulename folder, e.g.

app/code/[codepool]/[Namespace]/[Modulename]/controllers/ # I previously missed the codepool, because Magento 2 :-)

You are trying to get the system to locate controllers in a location where it by design cannot locate them.

(edit based on OP comment)

Controllers need two levels of depth (namespace + module name). The following won't work:

app/code/local/Namespace/controllers
app/code/local/Namespace/Modulename/SomeOtherFolder/controllers

In your case, you may choose CustomCed as your namespace, giving:

app/code/local/CustomCsd/CsMarketplace/controllers/AccountController.php

In there you will override createPostAction().

Also, depending on what you are doing, you could possibly use one of the dynamic events which exist around controller action dispatching.

这篇关于使用自定义控制器覆盖CsMarketplace帐户控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆