我試圖延長:Mage_Catalog_Model_Product_Visibility擴展核心模式在Magento
我修改的Visibility.php文件中的以下內容:
public function getVisibleInSiteIds()
{
return array(self::VISIBILITY_IN_SEARCH, self::VISIBILITY_IN_CATALOG, self::VISIBILITY_BOTH);
}
分爲:
public function getVisibleInSiteIds()
{
return array(self::VISIBILITY_IN_SEARCH, self::VISIBILITY_IN_CATALOG, self::VISIBILITY_BOTH, self::VISIBILITY_NOT_VISIBLE);
}
過時被設置爲「不可見」的產品仍然會顯示其直接網址(默認情況下,Magento會顯示404)。
我通過修改核心文件測試了它,它工作。但我想創建一個小擴展,到目前爲止我無法實現它的工作。這是我迄今所做的:
應用程序的/ etc /模塊/ CustomCode_InvisibleProducts.xml
<?xml version="1.0"?>
<config>
<modules>
<CustomCode_InvisibleProducts>
<active>true</active>
<codePool>local</codePool>
</CustomCode_InvisibleProducts>
</modules>
</config>
應用程序/代碼/本地/ CustomCode/InvisibleProducts的/ etc/config.xml中
<?xml version="1.0"?>
<config>
<modules>
<CustomCode_InvisibleProducts>
<version>0.1.0</version>
</CustomCode_InvisibleProducts>
</modules>
<global>
<models>
<customcode_invisibleproducts>
<class>CustomCode_InvisibleProducts_Model</class>
</customcode_invisibleproducts>
<catalog>
<rewrite>
<product_visibility>CustomCode_InvisibleProducts_Model_Catalog_Product_Visibility</product_visibility>
</rewrite>
</catalog>
</models>
</global>
</config>
應用程序/代碼/本地/ CustomCode/InvisibleProducts /型號/目錄/產品/ Visibility.php
class CustomCode_InvisibleProducts_Model_Catalog_Product_Visibility extends Mage_Catalog_Model_Product_Visibility
{
.....
不知何故我沒有正確地擴展模型,因爲沒有任何事情發生/改變。
感謝您的幫助!
您確定模塊已加載嗎?您可以在「系統」 - >「配置」 - >「高級」 - >「禁用模塊輸出」中看到列表。如果它沒有出現,請刪除Magento緩存並重試。 – 2013-02-21 11:35:53
是的,我做了,它在那裏,它啓用。緩存關閉btw。 – 2013-02-21 11:44:29
重寫配置對我來說很合適。我的下一步是確定是否調用重寫的方法(使用調試器或在方法中調用'Mage :: log()') – 2013-02-21 12:12:54