1

hello I have a problem again with my rewrite, I tried to rewrite the product view block

app/code/local/Lesson/Test/etc/config.xml

 <?xml version="1.0"?> <config> <modules> <Lesson_Test> <version>1.0.0</version> </Lesson_Test> </modules> <global> <blocks> <catalog> <rewrite> <product_view>Lesson_Test_Block_Catalog_Product_View</product_view> </rewrite> </catalog> </blocks> </global> </config> 

app/code/local/Lesson/Test/Block/Catalog/Product/View.php

<?php Class Lesson_Test_Block_Catalog_Product_View extends Mage_Catalog_Block_Product_View { public function afficherLesInfos() { return 'les infos complementaires'; } } 

app/etc/modules/Lesson.xml

<?xml version="1.0"?> <config> <modules> <Lesson_Test> <active>true</active> <codePool>local</codePool> </Lesson_Test> </modules> </config> 

I tried to access

http://127.0.0.1/magento/magento-tutorial/index.php/ http://127.0.0.1/magento/magento-tutorial/index.php/lesson http://127.0.0.1/magento/magento-tutorial/index.php/lesson/product http://127.0.0.1/magento/magento-tutorial/index.php/lesson/product/view http://127.0.0.1/magento/magento-tutorial/index.php/product/view http://127.0.0.1/magento/magento-tutorial/index.php/lesson/catalog/product/view 

no one of that at work

1
  • 1
    your global configuration file name should be Lesson_Test.xml instead of Lesson.xml Commented Jun 7, 2016 at 9:20

1 Answer 1

3

I'm confused by what you want to achieve here.

Rewriting a block does not involve changing the URLs.

In your case, you're rewriting the catalog product view block so you just need to access a normal product view page.

But the way you're rewriting the block and adding a new method afficherLesInfos won't do anything if you don't call that method in your template.

To get that working you need to edit app/design/<your_package>/<your_theme>/template/catalog/product/view.phtml and add the following line to the template:

<?php echo $this->afficherLesInfos(); ?> 

Also app/code/local/Lesson/Test/etc/config.php must be an XML file and not a PHP file like you said.

On top of that, as Amit said, your global config should be renamed from Lesson.xml to Lesson_Test.xml

3
  • thanks @Raphael but it still not work (404 not found), i've create a template, layout, and i add on config and i acces 127.0.0.1/magento/magento-tutorial/index.php/lesson Commented Jun 7, 2016 at 9:12
  • 1
    @gufran I don't understand why you're trying to access 127.0.0.1/magento/magento-tutorial/index.php/lesson ? Your code only implies block rewrite and does not declare custom route. You should try to access a product page as I said in my answer Commented Jun 7, 2016 at 9:25
  • sorry @Raphael, thanks i understand know :) i tried access this page (my some product) 127.0.0.1/magento/magento-tutorial/index.php/product-coba.html you are my hero :) Commented Jun 7, 2016 at 22:31

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.