0

I am developing a custom module for Magento (CE, 1.9) and I'm running into the most basic problem, my models (which should override core models) are not being found/loaded correctly. I have diagnosed this back to Mage.php and can see where it is adding, for example the singleton catalog/layer, and instead of adding the object it only gets a boolean. This causes all subsequent code to fail of course.

I have checked my configuration against this module creator and my directories and code all match exactly what is produced, so I'm at a loss!

etc/modules/Namespace_Pricing.xml

<?xml version="1.0"?>
<config>
  <modules>
    <Namespace_Pricing>
      <active>true</active>
      <codePool>community</codePool>
      <version>0.1.0</version>
    </Namespace_Pricing>
  </modules>
</config>

app/code/community/Namespace/Pricing/etc/config.xml

<?xml version="1.0"?>
<config>
    <modules>
        <Namespace_Pricing>
            <version>1.0</version>
        </Namespace_Pricing>
    </modules>
    <global>
        <helpers>
            <pricing>
                <class>Namespace_Pricing_Helper</class>
            </pricing>
        </helpers>
        <models>
            <pricing>
                <class>Namespace_Pricing_Model</class>
            </pricing>
            <catalog>
                <rewrite>
                    <product_type_price>Namespace_Pricing_Model_Catalog_Product_Type_Price</product_type_price>
                </rewrite>
            </catalog>
            <catalog>
                <rewrite>
                    <layer>Namespace_Pricing_Model_Catalog_Layer</layer>
                </rewrite>
            </catalog>-->
        </models>
    </global>
</config>

app/code/community/Namespace/Pricing/Model/Catalog/Layer.php

<?php
class Namespace_Pricing_Model_Catalog_Layer extends Mage_Catalog_Model_Layer
{

}

app/code/community/Namespace/Pricing/Model/Catalog/Product/Type/Price.php

<?php
class Namespace_Pricing_Model_Catalog_Product_Type_Price extends Mage_Catalog_Model_Product_Type_Price
{

}

Namespace is not literal, but it's just a string and is correctly cased everywhere used. What else do I need to look at outside these directories? With the module active, in fact just with the rewrites in place in config.xml, Magento throws an exception that the model (catalog/layer etc) already exists in the registry, because it only exists as a boolean False when set.

  • Code is working for me.Whats your code in model post in question? or check any other extension rewrite same class which one you are trying. – Prashant Valanda Mar 18 '16 at 13:15
1

You are defining <catalog> tag twice in your config.xml file. In addition to this, there is an ending xml comment piece of code

Change this

    <models>
        <pricing>
            <class>Namespace_Pricing_Model</class>
        </pricing>
        <catalog>
            <rewrite>
                <product_type_price>Namespace_Pricing_Model_Catalog_Product_Type_Price</product_type_price>
            </rewrite>
        </catalog>
        <catalog>
            <rewrite>
                <layer>Namespace_Pricing_Model_Catalog_Layer</layer>
            </rewrite>
        </catalog>-->
    </models>

For this

    <models>
        <pricing>
            <class>Namespace_Pricing_Model</class>
        </pricing>
        <catalog>
            <rewrite>
                <layer>Namespace_Pricing_Model_Catalog_Layer</layer>
                <product_type_price>Namespace_Pricing_Model_Catalog_Product_Type_Price</product_type_price>
            </rewrite>
        </catalog>
    </models>
  • Well the left over comment closing doesn't make any difference, but combining the duplicate <catalog> was the key - thanks very much indeed, the fact Magento doesn't combine them is a good nugget to remember! – James Mar 18 '16 at 13:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.