Magento

eCommerce Software for Online Growth

Magento Forum

From setting up your store to managing your products, pages and promotions to generating detailed reports, the Magento User Guide empowers the user to utilize the platform for all of its vast capacity.
Available in eBook and Print formats – Download Now!!!
   
Creating a new action
 
Benjamin Bellamy
Jr. Member
 
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.

 Signature 

Benjamin Bellamy

 
Magento Community Magento Community
Magento Community
Magento Community
 
Benjamin Bellamy
Jr. Member
 
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.

 Signature 

Benjamin Bellamy

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
    Back to top
 
© Copyright 2010 Magento Inc.
Privacy Policy|Terms of Service
Magento Community Count
195866 users|782 users currently online|366277 forum posts