2

I'm new to Magento. Need to create an extension which will enable to add comments to products on 'product view' pages. I created a new tab next to "descriptions" and "reviews" and added the form, but can't put the correct form action which will load the controller file, save the input information and then save it in the database. Read lot of different articles,but couldn't figure this out. Any help is greatly appreciated!

This is the form action line in app\design\frontend\rwd\default\template\productcomments\productcomments.phtml

<form enctype="multipart/form-data" method="post" action="<?php echo $this->getUrl('productcomments/index/savecomment'); ?>" id="product-view-add-comment">

Here is my indexController.php content:

class Cpstest_ProductComments_IndexController extends Mage_Core_Controller_Front_Action
{
    public function savecommentAction()
    {
        echo "Hello";
    }
}

And I added the block information (tab "Product Comments") in app\design\frontend\rwd\default\layout\catalog.xml like this:

<block type="catalog/product_view_attributes" name="product.comments" as="additional" template="productcomments/productcomments.phtml">
    <action method="setTitle" translate="value"><value>Product Comments</value></action>
</block>
1
<module>Cpatest_ProductComments</module>

I am making some assumptions, but it seems like this should instead be Cpstest_ProductComments. Now that you have added the file paths, it looks like your controller filename is incorrect. It should be: controllers\IndexController.php (note the plural controllers).

  • Thanks so much for your response. Yes, you are right, it should be Cpstest instead of Cpatest. I made a correction, but it still doesn't work. I'm getting a 404 error after submitting the form. – bestwebdevs Mar 1 '17 at 21:26
  • @bestwebdevs - cleared the Magento cache? – fantasticrice Mar 1 '17 at 21:33
  • Yeah, I did, but the error is still there – bestwebdevs Mar 1 '17 at 21:40
  • @bestwebdevs - can you add the file/directory structure of your extension to the question? – fantasticrice Mar 1 '17 at 22:12
  • Sure, I did. Please let me know if you need any other information. – bestwebdevs Mar 1 '17 at 23:05
0

I think you didn't activated your extension, to do so make sure that you already created the file:

app/etc/modules/Cpstest_ProductComments.xml

With the following content:

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

Clear the cache, and from admin go to System > Advanced > Advanced and see if the extension name is listed.

  • thanks for your answer. fantasticrice 's updated reply already resolved the issue. – bestwebdevs Mar 2 '17 at 1:16

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.