Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

Creating a new action
 
Ben at Keeward
Jr. Member
 
Avatar
Total Posts:  18
Joined:  2008-06-26
Paris, France
 

I am trying to create a new action in order to display products.

- I created a new template edito.phtml
- I created a new layout page in catalog.xml :

<catalog_product_edito>
        <
reference name="root">
            <
action method="setTemplate"><template>page/empty.phtml</template></action>
        </
reference>
        <
reference name="content">
            <
block type="catalog/product_view" name="catalog_product_edito" template="catalog/product/edito.phtml"/>
        </
reference>
    </
catalog_product_edito>
- Then I tried to create a new action to call this page from the browser (http://localhost/catalog/product/edito/id/733)… without any success…
:-(

Here is what I tried :

First, I just added these lines in app/code/core/Mage/Catalog/controllers/ProductController.php

public function editoAction()
    
{
        $this
->_initProduct();
        
$this->loadLayout();
        
$this->renderLayout();
    
}
This worked like a charm but modifying core code is far for clean…

Then I tried to overload by creating a app/code/local/Mage/Catalog/controllers/ProductController.php : it doesn’t work at all.

At last I spent hours tring to make this tutorial work :
How to overload a controller
but all I manage to do is… nothing.

Anybody here has any clue ?
Is there a simple way to create a new action ?

Regards,
Ben.

 
Magento Community Magento Community
Magento Community
Magento Community
 
Ben at Keeward
Jr. Member
 
Avatar
Total Posts:  18
Joined:  2008-06-26
Paris, France
 

I went to sleep then tried again… and made it work.

First thing : I don’t need the rewrite section since all I want to do is add an action, therefore this is useless (and it looks useless!) :

<rewrite>
            <
mynamespace_catalog_product>
                <
from><![CDATA[#^/catalog/product/#]]></from>
                
<to>/catalog/product/</to>
            </
mynamespace_catalog_product>
        </
rewrite>

Then I added this to my config.xml (I assume you may add this directly to app/etc/local.xml if you are too lazy to put it in your own config.xml) :

<frontend>
        <
routers>
            <
mynamespace_catalog>
                <use>
standard</use>
                <
args>
                    <
module>mynamespace_Catalog</module>
                    <
frontName>catalog</frontName>
                </
args>
            </
mynamespace_catalog>
        </
routers>
    </
frontend>

Then created my own Controller which is pretty much empty :
app/code/local/Mynamespace/Catalog/controllers/ProductController.php :

require_once 'Mage/Catalog/controllers/ProductController.php';

class 
Mynamespace_Catalog_ProductController extends Mage_Catalog_ProductController
{
    
public function editoAction()
    
{
        $this
->_initProduct();
        
$this->loadLayout();
        
$this->renderLayout();
    
}
}

And that’s it, just create your template phtml files and update your xml layouts.

If you want to write PDF files (which was my case) don’t use loadLayout() and renderLayout() in you action controller.

Ben.

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top