Magento: rewrite block not working

I am trying to rewrite the main file from magento. Somehow this does not overwrite the code. I am trying to overwrite the getProduct () function.

Tipfix / block / product / view.php

<?php class WP_Tipfix_Block_Catalog_Product_View extends Mage_Catalog_Block_Product_View { public function getProduct() { if (!Mage::registry('product') && $this->getProductId()) { $product = Mage::getModel('catalog/product')->load($this->getProductId()); Mage::register('product', $product); } //return Mage::registry('product'); } } 

Tipfix / etc. /config.xml

 <blocks> <WP_Tipfix> <class>WP_Tipfix_Block</class> </WP_Tipfix> <catalog> <rewrite> <product_view>WP_Tipfix_Block_Catalog_Product_View</product_view> </rewrite> </catalog> </blocks> 

I know what I'm doing wrong.

Gr. Lex

+6
source share
2 answers

Your class is WP_Tipfix_Block_Catalog_Product_View , which means that it should be in the WP/Tipfix/Block/Catalog/Product/View.php . You must either move the Product directory to a new directory called Catalog in this place, or rename your class (both class and XML) to WP_Tipfix_Block_Product_View . I recommend moving the file.

+9
source

Change the contents of config.xml your module to this, and I'm sure it should work: -

 <?xml version="1.0" encoding="UTF-8"?> <config> <modules> <WP_Tipfix> <version>1.0.0</version> </WP_Tipfix> </modules> <global> <blocks> <wptipfix> <class>WP_Tipfix_Block</class> </wptipfix> <catalog> <rewrite> <product_view>WP_Tipfix_Block_Catalog_Product_View</product_view> </rewrite> </catalog> </blocks> </global> </config> 

Hope this helps.


UPDATE: - After Ben's comment, I believe that I should have mentioned that the OP should also use the solution specified in Max in its answer . Thus, the OP will need a joint effort to fix its problem.

+3
source

Source: https://habr.com/ru/post/909990/


All Articles