我想重載從核心saveAction方法/法師/ Adminhtml /控制器/目錄/ ProductController.php和它不會工作 - 現在我已搜查,並試圖爲一個完整的一天:(Magento:重載Adminhtml/Productcontroller的saveAction方法不起作用...?
背景:我想在產品保存之前更改自定義屬性的值,我發現_initProductSave設置了屬性,我認爲,在init_ProductSave之後更改它們會是一個好點(如果有人知道更好的地方請讓我知道)...
可能請人幫助我... :)
Magento的版本:社區版版本1.7.0.1 沒有擴展名的,沒有安裝的主題,我剛安裝了這個版本完全空白......
版本1:通過複製到本地/法師文件夾 Overwritting控制器
首先,我試圖將文件複製到應用程序/代碼/本地文件夾,在正確的結構內 - 但它不會工作(我已經爲Varient.php做了本地測試系統和商店.php糾正價格bug - 對於它的工作...)
版本2:與擴展Overwritting控制器
我的分機是這樣的:
文件結構:
code/local/MyOne/MyExtension/controllers/Catalog/ProductController.php
code/local/MyOne/MyExtension/etc/config.xml
etc/modules/MyOne_MyExtension.xml
的文件看起來如下: MyOne_MyExtension .xml:
<?xml version="1.0" encoding="UTF-8"?>
<config>
<modules>
<MyOne_MyExtension>
<active>true</active>
<codePool>local</codePool>
</MyOne_MyExtension>
</modules>
</config>
代碼/本地/ MyOne/MyExtension的/ etc/config.xml中:
<?xml version="1.0" encoding="UTF-8"?>
<config>
<modules>
<MyOne_MyExtension>
<version>1.0.0</version>
</MyOne_MyExtension>
</modules>
<admin>
<routers>
<adminhtml>
<args>
<modules>
<MyOne_MyExtension before="Mage_Adminhtml">MyOne_MyExtension_Catalog_ProductController</MyOne_MyExtension>
</modules>
</args>
</adminhtml>
</routers>
</admin>
</config>
和最後一個,代碼/本地/ MyOne/MyExtension /控制器/目錄/ ProductController.php:
<?php
require_once 'Mage/Adminhtml/controllers/Catalog/ProductController.php';
class MyOne_MyExtension_Catalog_ProductController extends Mage_Adminhtml_Catalog_ProductController
{
public function saveAction()
{
// do my stuff
die('reached method');
// after pressing on save, there should no be a white screen ...
}
}
?>
我用Google搜索和閱讀那麼多,我沒有看到一個錯誤......
任何幫助真的會很棒!
問候, 馬蒂亞斯
這一個也是正確的... :) 感謝! (救了我的一天;)) @benmarks:丹尼爾的解決方案也是你很好解釋的結果,不是嗎? – user617965
,當然我也會向觀察員瞭解最佳做法,明天我也會測試那個,:) – user617965