Extend Core Model in Magento

magento, magento-1.5, model, php

Solution

I've changed the name of the extension from CustomCode_InvisibleProducts to CustomCode_Visible, because I didn't know what else to do.

And somehow, the extension started working right away.

Final code:

app/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);
    }

Problem

I'm trying to extend: Mage_Catalog_Model_Product_Visibility I'm modifying the following in the Visibility.php file: ``` public function getVisibleInSiteIds() { return array(self::VISIBILITY_IN_SEARCH, self::VISIBILITY_IN_CATALOG, self::VISIBILITY_BOTH); } ``` Into: ``` public function getVisibleInSiteIds() { return array(self::VISIBILITY_IN_SEARCH, self::VISIBILITY_IN_CATALOG, self::VISIBILITY_BOTH, self::VISIBILITY_NOT_VISIBLE); } ``` Outdated products that are set to Not Visible will still show from their direct URL (by default Magento would show a 404). I tested this by modifying the core file and it works. But I'd like to create a little extension and so far I can't get it to work. This is what I've done so far: 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 { ..... ``` Somehow I'm not extending the Model correctly because nothing seems to be happening/changing. Thanks for the help!

Original source