1
votes

I have a problem to override Mage_Catalog_Model_Resource_Product_Attribute_Backend_Media.

Here is what I did:

config.xml

<?xml version="1.0"?>
<config>
  <modules>
    <Xx_Catalog>
      <version>0.1.0</version>
    </Xx_Catalog>
  </modules>
  <global>
    <models>
      <xx_catalog>
        <class>Xx_Catalog_Model</class>
      </xx_catalog>
      <catalog_resource>
        <rewrite>
          <product_attribute_backend_media>
        Xx_Catalog_Model_Resource_Product_Attribute_Backend_Media
          </product_attribute_backend_media>
        </rewrite>
      </catalog_resource>
    </models>
</global>

Media.php

class Xx_Catalog_Model_Resource_Product_Attribute_Backend_Media extends Mage_Catalog_Model_Resource_Product_Attribute_Backend_Media
{
  public function loadGallery($product, $object){
    echo "test";
    die();
  }
}

And here is the error:

Fatal error: Call to a member function loadGallery() on a non-object in /magento/app/code/core/Mage/Catalog/Model/Product/Attribute/Backend/Media.php on line 51`

Do you know how to override this class?
I have Magento 1.9.3.3

Thanks

--------- SUCCESS ----------

I had to change catalog_resource to catalog_resource_eav_mysql4:

  <catalog_resource_eav_mysql4>
    <rewrite>
      <product_attribute_backend_media>Xx_Catalog_Model_Resource_Eav_Mysql4_Product_Attribute_Backend_Media</product_attribute_backend_media>
    </rewrite>
  </catalog_resource_eav_mysql4>
1

1 Answers

0
votes

In your config.xml file you have to change from <resource_product_attribute_backend_media> to <product_attribute_backend_media> as like below:

<?xml version="1.0"?>
<config>
  <modules>
    <Xx_Catalog>
      <version>0.1.0</version>
    </Xx_Catalog>
  </modules>
  <global>
    <models>
      <xx_catalog>
        <class>Xx_Catalog_Model</class>
      </xx_catalog>
      <catalog_resource>
    <rewrite>
      <product_attribute_backend_media>
        Xx_Catalog_Model_Resource_Product_Attribute_Backend_Media
      </product_attribute_backend_media>
    </rewrite>
      </catalog_resource>
    </models>
</global>