Skip to main content
added 928 characters in body
Source Link
Fabian Schmengler
  • 66.1k
  • 25
  • 188
  • 422

This is one of the very rare cases in Magento where a class is not used with the factory methods like Mage::getModel().

Actually Mage_Catalog_Model_Product_Type only contains static methods, which makes it play in the same league as the Mage class itself and totally different from all other model classes.

Ergo, you cannot rewriteErgo, you cannot rewrite it.

What makes it really evil is that it might seem to work because in some places Magento instantiates the class with Mage::getSingleton('catalog/product_type') but in other cases it calls the methods statically.

###For example:

  • In Mage_Catalog_Model_Resource_Prodcut_Flat_Indexer the static call is used:

      foreach (array_keys(Mage_Catalog_Model_Product_Type::getTypes()) as $typeId) {
    
  • In Mage_Adminhtml_Block_Catalog_Product_Grid the singleton is used:

      $this->addColumn('type',
          array(
              'header'=> Mage::helper('catalog')->__('Type'),
              'width' => '60px',
              'index' => 'type_id',
              'type'  => 'options',
              'options' => Mage::getSingleton('catalog/product_type')->getOptionArray(),
      ));
    

(in case you are wondering, calling static methods on an instance is totally allowed in PHP)

This is one of the very rare cases in Magento where a class is not used with the factory methods like Mage::getModel().

Actually Mage_Catalog_Model_Product_Type only contains static methods, which makes it play in the same league as the Mage class itself and totally different from all other model classes.

Ergo, you cannot rewrite it.

This is one of the very rare cases in Magento where a class is not used with the factory methods like Mage::getModel().

Actually Mage_Catalog_Model_Product_Type only contains static methods, which makes it play in the same league as the Mage class itself and totally different from all other model classes.

Ergo, you cannot rewrite it.

What makes it really evil is that it might seem to work because in some places Magento instantiates the class with Mage::getSingleton('catalog/product_type') but in other cases it calls the methods statically.

###For example:

  • In Mage_Catalog_Model_Resource_Prodcut_Flat_Indexer the static call is used:

      foreach (array_keys(Mage_Catalog_Model_Product_Type::getTypes()) as $typeId) {
    
  • In Mage_Adminhtml_Block_Catalog_Product_Grid the singleton is used:

      $this->addColumn('type',
          array(
              'header'=> Mage::helper('catalog')->__('Type'),
              'width' => '60px',
              'index' => 'type_id',
              'type'  => 'options',
              'options' => Mage::getSingleton('catalog/product_type')->getOptionArray(),
      ));
    

(in case you are wondering, calling static methods on an instance is totally allowed in PHP)

Source Link
Fabian Schmengler
  • 66.1k
  • 25
  • 188
  • 422

This is one of the very rare cases in Magento where a class is not used with the factory methods like Mage::getModel().

Actually Mage_Catalog_Model_Product_Type only contains static methods, which makes it play in the same league as the Mage class itself and totally different from all other model classes.

Ergo, you cannot rewrite it.