问题
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>
回答1:
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.
来源:https://stackoverflow.com/questions/35620321/overriding-csmarketplace-account-controller-with-a-custom-controller