简体   繁体   中英

Magento Catalog ProductController rewrite

I try to override the magento Mage\\Catalog\\controllers\\ProductController.php with a module. In my module i try this:

\\etc\\config.xml

<global>
    <rewrite>        
        <aion_fbpage_catalog_productcontroller>
            <from><![CDATA[#^catalog/product/#]]></from> <!-- Mage_Catalog_ProductController  -->
            <to>fbpage/catalog_product/</to> <!-- Aion_FbPage_Catalog_ProductController  -->
        </aion_fbpage_catalog_productcontroller>
    </rewrite>
</global>
<frontend>
    <routers>
        <fbpage>
            <use>standard</use>
            <args>
                <module>Aion_FbPage</module>
                <frontName>fbPage</frontName>
            </args>
        </fbpage>
    </routers>
</frontend>

\\controllers\\Catalog\\ProductController.php

<?php
require_once "Mage/Catalog/controllers/ProductController.php";

class Aion_FbPage_Catalog_ProductController extends Mage_Catalog_ProductController
{
    // My override stuff
}

And when i try to reach my product, to see what the rewrite does, i get this error:

Fatal error: Call to a member function getMetaTitle() on a non-object in C:\\xampp\\htdocs\\igneum\\app\\code\\core\\Mage\\Catalog\\Block\\Product\\View.php on line 56

I get the same error message, if i do nothing in my class

you can use like below

Edit you Package/Module/etc/config.xml

<?xml version="1.0"?>
<config>
... Your Other config here ....
   <frontend> 
        <routers> 
          <catalog> 
             <args> 
             <modules> 
                <Package_Catalog before="Mage_Catalog">Package_Catalog</Package_Catalog>
             </modules> 
             </args> 
         </catalog> 
       </routers> 
   </frontend> 
</config>

Now your controller already ready.

include(Mage::getBaseDir()."/app/code/core/Mage/Catalog/controllers/ProductController.php");
class Package_Catalog_ProductController extends Mage_Catalog_ProductController
{
      public function viewAction(){
             echo __METHOD__;
      }
}
?>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM