php - 在 Magento 中扩展核心模型

标签 php magento model magento-1.5

我正在尝试扩展: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)。

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

app/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
{
     .....

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

感谢您的帮助!

最佳答案

我已将扩展名从 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);
    }

关于php - 在 Magento 中扩展核心模型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15001105/

相关文章:

mysql - 联结表中的复合主键 - Sequelize

ruby-on-rails - 生产 Rake 任务无法识别我的模型

php - 防止 SQL 注入(inject)

PHP:在命名空间中引用全局函数

php - 向 Magento 中的属性选项添加新值

magento - 更新产品的所有等级价格

cakephp - 调用$ this-> model-> create()在cakephp中的 Controller 中崩溃

php函数没有返回值

javascript - 将 php 数组传递给 javascript 数组

php - Magento 是框架还是平台?