3

i try rewrite my block on app/local/lesson7/test/block but its not working my modules xml (lesson7.xml)

<?xml version="1.0"?>
<config>
    <modules>
        <Lesson7_Test>
            <active>true</active>
            <codePool>local</codePool>
            <depends>
                <Mage_Catalog />
            </depends>
        </Lesson7_Test>
    </modules>
</config>

my layout on app/design/frontend/tutorial/default/layout/lesson7.xml

<?xml version="1.0"?>
<layout version="0.1.0">
  <default>
      <reference name="content">
      </reference>
  </default>
  <lesson7_index_index>
       <reference name="content">
            <block type="lesson7/monblock" name="afficher_monbloc" template="lesson7/afficher.phtml" />
       </reference>
  </lesson7_index_index>
</layout>

my template on app/design/frontend/tutorial/default/template/lesson7/afficher.phtml

<?php

    echo $this->methodblock();

?>

my config on app/local/etc/lesson7/test/etc/config.xml

<?xml version="1.0"?>
  <config>
     <modules>
        <Lesson7_Test>
          <version>1.0.0</version>
        </Lesson7_Test>
     </modules>
 <frontend>
   <routers>
      <lesson7>
          <use>standard</use>
          <args>
             <module>Lesson7_Test</module>
             <frontName>lesson7</frontName>
          </args>
       </lesson7>
   </routers>
   <layout>
     <updates>
          <lesson7>
               <file>lesson7.xml</file>
           </lesson7>
      </updates>
  </layout>
</frontend>
    <global>
      <blocks>
          <catalog>
              <rewrite>
                  <product_view>
                      Lesson7_Test_Block_Product_View
                  </product_view>
              </rewrite>
          </catalog>
        <lesson7>
          <class>Lesson7_Test_Block</class>
        </lesson7>
      </blocks>
    </global>
</config>

my block on app/local/lesson7/test/block/Monblock.php

<?php
class Lesson7_Test_Block_Monblock extends Mage_Core_Block_Template
{
     public function methodblock()
     {
         return 'Lesson 7 Block !!!' ;
     }
}

and my rewrite app/etc/lesson7/test/block/product/View.php

<?php
class Lesson7_Test_Block_Product_View extends Mage_Core_Block_Product_View
{
    public function afficherLesInfo()
    {
        return 'afficher les info !!!';
    }
}

UPDATE
is it possible his error was in my new block? is it true rewrite of models/resource can only be summoned by Mage such as Mage:: getModel (), Mage:: getResourceModel (), Mage:: Helper (), Mage:: getSingletonBlock () ?
please your help, thank you :)

1 Answer 1

2

Your extending block is wrong. There is no Mage_Core_Block_Product_View.php class

Replace this below content: Lesson7/Test/Block/Product/View.php (you should have all folder/file's first letter capital)

<?php
class Lesson7_Test_Block_Product_View extends Mage_Catalog_Block_Product_View
{
    public function afficherLesInfo()
    {
        return 'afficher les info !!!';
    }
}

I also doubt you are not placing your file in right place.

Check where is your View.php file? It should be in app/code/[codepool : community or local]/Lesson7/Test/Block/Product folder.

All your module files/folders should be inside this folder:

app/code/[codepool : community or local]
            |_Lesson7
                 |_Test
                    |_ Block
                    |_ etc

Hope this helps.

[UPDATE]

If you want to test then go to design/your_theme/template/catalog/product/view.phtml and have this code: <?php echo $this->afficherLesInfo();?>. And now go to any simple product and see if this appears. If it does then you have successfully rewritten the block.

9
  • thanks for you answer, i sure view.php file should be in app/code/local/Lesson7/Test/Block/Product folder and i have edit my view.php but it still didnt work
    – gufran
    Commented May 25, 2016 at 3:23
  • if i delete Lesson7_Test_Block in config.xml it still not work (no message) and if i remove the layout 404 not found message
    – gufran
    Commented May 25, 2016 at 3:29
  • what are you trying to do? What's the purpose of rewriting view.php? And which url throw 404 error? If it is your custom url, not product view page, then you don't need to rewrite view.php. Commented May 25, 2016 at 3:35
  • sorry i'm newbie on magento, i just look a tutorial pierrefay.com, and i tried the lesson 8 tutorial Rewrite / modify a magento block, on this lesson he said "how to change a basic block of Magento", but i think if we change it we won look a other message like "les infos complementaires"
    – gufran
    Commented May 25, 2016 at 3:48
  • 1
    Check my udpate. Commented May 25, 2016 at 3:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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