1

app\code\core\Mage\Adminhtml\controllers\Catalog\ProductController.php

I want to override save and edit function from ProductControll.php page.

While saving product want to override function.

  • why -1????????? – jassi Jul 11 '16 at 12:47
1

Lets create a small module for overriding the product controller

Step 1:- Create YourPackageName_Adminhtml.xml file at app/etc/

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

Step 2:- Create module’s config.xml file at app/code/local/YourPackageName/Adminhtml/etc/

<?xml version="1.0"?>
<config>
    <modules>
        <YourPackageName_Adminhtml>
        <version>0.0.1</version>
        </YourPackageName_Adminhtml>
    </modules>
    <admin>
        <routers>
            <adminhtml>
                <args>
                    <modules>
                        <yourpackagename_adminhtml before="Mage_Adminhtml">YourPackageName_Adminhtml</yourpackagename_adminhtml>
                    </modules>
                </args>
            </adminhtml>
        </routers>
    </admin>
</config>

Step 3:- Create ProductController.php controller file at app/code/local/YourPackageName/Adminhtml/controllers/Catalog/ProductController.php

<?php
include_once("Mage/Adminhtml/controllers/Catalog/ProductController.php");
class YourPackageName_Adminhtml_Catalog_ProductController extends Mage_Adminhtml_Catalog_ProductController
{
    public function editAction()
    {
        // your custom logic for editAction comes here
    }

    public function saveAction()
    {
        // your custom logic for saveAction comes here
    }
}
?>

Clear the cache and refresh and you have done.

  • still it is taking core file – jassi Jul 11 '16 at 12:00
  • show me your code – Pradeep Sanku Jul 11 '16 at 12:11
  • app\code\local\Product\Adminhtml\etc\config.xml <?xml version="1.0"?> <config> <modules> <Product_Adminhtml> <version>0.0.1</version> </Product_Adminhtml> </modules> <admin> <routers> <adminhtml> <args> <modules> <product_adminhtml before="Mage_Adminhtml">Product_Adminhtml</product_adminhtml> </modules> </args> </adminhtml> </routers> </admin> </config> – jassi Jul 11 '16 at 12:15
  • i mean all three files code. not just file name – Pradeep Sanku Jul 11 '16 at 12:16
  • app\etc\modules\Product_Adminhtml.xml <?xml version="1.0"?> <config> <modules> <Product_Adminhtml> <active>true</active> <codePool>local</codePool> </Product_Adminhtml> </modules> </config> app\code\local\Product\Adminhtml\controllers\Catalog include_once("Mage/Adminhtml/controllers/Catalog/ProductController.php"); class Product_Adminhtml_Catalog_ProductController extends Mage_Adminhtml_Catalog_ProductController { /** * Save product action */ public function saveAction() { echo "local new save"; exit; } – jassi Jul 11 '16 at 12:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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