3

我正在尝试扩展:Mage_Catalog_Model_Product_Visibility

我正在修改 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);
  }

设置为不可见的过时产品仍会从其直接 URL 显示(默认情况下,Magento 将显示 404)。

我通过修改核心文件对此进行了测试,它可以工作。但我想创建一个小扩展,到目前为止我无法让它工作。这是我到目前为止所做的:

应用程序/etc/modules/CustomCode_InvisibleProducts.xml

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

app/code/local/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>

app/code/local/CustomCode/InvisibleProducts/Model/Catalog/Product/Visibility.php

class CustomCode_InvisibleProducts_Model_Catalog_Product_Visibility extends Mage_Catalog_Model_Product_Visibility
{
     .....

不知何故,我没有正确扩展模型,因为似乎没有任何事情发生/改变。

谢谢您的帮助!

4

2 回答 2

3

我已将扩展名从 CustomCode_InvisibleProducts 更改为 CustomCode_Visible,因为我不知道还能做什么。

不知何故,扩展程序立即开始工作。

最终代码:

应用程序/etc/modules/CustomCode_Visible.xml

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

app/code/local/CustomCode/Visible/etc/config.xml

<?xml version="1.0"?>
<config>
    <modules>
        <CustomCode_Visible>
            <version>0.2.0</version>
        </CustomCode_Visible>
    </modules>
    <global>
        <models>
            <customcode_visible>
                <class>CustomCode_Visible_Model</class>
            </customcode_visible>
            <catalog>
                <rewrite>
                    <product_visibility>CustomCode_Visible_Model_Catalog_Product_Visibility</product_visibility>
                </rewrite>
            </catalog>
        </models>
    </global>
</config>

app/code/local/CustomCode/Model/Catalog/Product/Visibility.php

class CustomCode_Visible_Model_Catalog_Product_Visibility extends Mage_Catalog_Model_Product_Visibility
{

  ....

        public function getVisibleInSiteIds()
    {
        return array(self::VISIBILITY_IN_SEARCH, self::VISIBILITY_IN_CATALOG, self::VISIBILITY_BOTH, self::VISIBILITY_NOT_VISIBLE);
    }
于 2013-02-22T14:06:52.457 回答
0

您没有在 config.xml 中声明您的模块

<modules>
    <CustomCode_InvisibleProducts>
        <version>0.1.0</version>
    </CustomCode_InvisibleProducts>
</modules>

将其插入到您的全局节点之前。

于 2013-02-21T13:46:32.930 回答