1

how to override the catalog/product/new action, but I am not understanding where I start. I have searched on different forums but I couldn't get any idea. I have tried it by overriding the copy in local but could not succeed.

1

3 Answers 3

2

To override the product controller follow this create file in app/etc/modules/Solsint_Proextended.xml

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

create file in app/code/local/Solsint/Proextended/etc/config.xml

<?xml version="1.0"?>
<config>
<modules>
<Solsint_Proextended>
<version>0.1.0</version>
</Solsint_Proextended>
</modules>

<admin>
    <routers>
        <adminhtml>
            <args>
                <modules>
                    <Solsint_Proextended before="Mage_Adminhtml">Solsint_Proextended</Solsint_Proextended>
                </modules>
            </args>
        </adminhtml>
    </routers>
</admin> 

</config>

and at the end create file in app/code/local/Solsint/Proextended/controllers/catalog/ProductController.php

<?php
include_once("Mage/Adminhtml/controllers/Catalog/ProductController.php");
class Solsint_Proextended_Catalog_ProductController extends Mage_Adminhtml_Catalog_ProductController
{

public function newAction()
{
  echo "Working"; exit; //do here what you want to do
}
}

this is tested code. hope it will be helpful for you.

1
1

Create a small module for overriding the Controller.let see step by step for overriding

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 config.xml file at app/code/local/YourPackageName/Adminhtml/etc/config.xml

<?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 newAction()
        {
            // echo "done"; exit;
        }
    }
?>

Note:- for more information on overriding the create new product in admin refer http://magento-online-tutorials.blogspot.in/2015/10/how-to-override-create-new-product.html

1
  • your answer is also helpful but i already choose correct ans, thanks for your help. Commented Oct 26, 2015 at 12:54
0
  1. You can use phpstorm and magicento plugin for easy override anything you want.
  2. Class name for rewrite Mage_Adminhtml_Catalog_ProductController
  3. Rewrite class may be not best way to do what you want. You should try use observers first.
require_once 'Mage/Adminhtml/controllers/Catalog/ProductController.php';
class YOURMODULENAMESPACE_YOURMODULENAME_Adminhtml_Catalog_ProductController extends Mage_Adminhtml_Catalog_ProductController
{
    public function newAction()
    {
        ...
    }

}

And add rewrite to controller address:


        <rewrite>
<module_catalog_product>
<from><![CDATA[#^/.*/catalog_product/new/#]]></from>
<to>/YOURCONTROLLERADDRESS/adminhtml_catalog_product/new/</to>
</module_catalog_product>
</rewrite>
1
  • That's the old way of doing things. Please don't do this, unless you need to keep compatibility with older versions. Older versions that no longer get security patches I might add.
    – user4351
    Commented Oct 26, 2015 at 19:08

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.