0

I'm trying to override the Product Review Controller from Magento Backend, however the new controller is never called, I followed the exact steps on this post, however it does not seem to work, and the new controller is never called. I can see the Edit Review form action attribute from the backend page is stil <form id="edit_form" action="http://appfactory.loc/index.php/admin/catalog_product_review/save/id/1/" method="post" enctype="multipart/form-data">. Not sure whether this should reflect the new controller URL or path or whether this is handled internally by Magento.

My code is as simple as:

appfactory-magento\app\code\local\AppFactory\Basic\etc\config.xml

...

    <admin>
        <routers>
            <adminhtml> 
                <args> 
                    <modules> 
                        <AppFactory_Basic after="Mage_Adminhtml">AppFactory_Basic_Adminhtml</AppFactory_Basic>
                    </modules> 
                </args> 
            </adminhtml>
        </routers>
    </admin>

...

app\code\local\AppFactory\Basic\controllers\Adminhtml\Catalog\Product\ReviewController.php

require_once 'Mage/Adminhtml/controllers/Catalog/Product/ReviewController.php';


class AppFactory_Basic_Adminhtml_Catalog_Product_ReviewController extends Mage_Adminhtml_Catalog_Product_ReviewController
{


    public function saveAction()
    {
        Mage::Helper('basic/log')->log('You finally did it');
    }

}

Might be relevant as well, but doesnt think it affect anything: app\code\local\AppFactory\Basic\Block\Adminhtml\Review\Edit\Form.php

class AppFactory_Basic_Block_Adminhtml_Review_Edit_Form extends Mage_Adminhtml_Block_Widget_Form
{
    protected function _prepareForm()
    {

        $review = Mage::registry('review_data');
        $product = Mage::getModel('catalog/product')->load($review->getEntityPkValue());
        $customer = Mage::getModel('customer/customer')->load($review->getCustomerId());

        $form = new Varien_Data_Form(array(
            'id'        => 'edit_form',
            'action'    => $this->getUrl('*/*/save', array('id' => $this->getRequest()->getParam('id'), 'ret' => Mage::registry('ret'))),
            'method'    => 'post',
            'enctype' => 'multipart/form-data'
        ));


        $fieldset = $form->addFieldset('review_details', array('legend' => Mage::helper('review')->__('Review Details'), 'class' => 'fieldset-wide'));


        $fieldset->addField('product_name', 'note', array(
            'label'     => Mage::helper('review')->__('Product'),
            'text'      => '<a href="' . $this->getUrl('*/catalog_product/edit', array('id' => $product->getId())) . '" onclick="this.target=\'blank\'">' . $product->getName() . '</a>'
        ));

        if ($customer->getId()) {
            $customerText = Mage::helper('review')->__('<a href="%1$s" onclick="this.target=\'blank\'">%2$s %3$s</a> <a href="mailto:%4$s">(%4$s)</a>', $this->getUrl('*/customer/edit', array('id' => $customer->getId(), 'active_tab'=>'review')), $this->escapeHtml($customer->getFirstname()), $this->escapeHtml($customer->getLastname()), $this->escapeHtml($customer->getEmail()));
        } else {
            if (is_null($review->getCustomerId())) {
                $customerText = Mage::helper('review')->__('Guest');
            } elseif ($review->getCustomerId() == 0) {
                $customerText = Mage::helper('review')->__('Administrator');
            }
        }



        $fieldset->addField('customer', 'note', array(
            'label'     => Mage::helper('review')->__('Posted By'),
            'text'      => $customerText,
        ));

        /* 
         * added new image custom field 
         * 
         */
       if(Mage::helper("reviewimage")->getActive() == '1'){

            $imageUrl = Mage::getBaseUrl("media").'reviewimages/'.$review->getReviewimage();
            $imageName = $review->getReviewimage();

            $imageResized = Mage::getBaseDir('media').DS."creviewimages".DS.$imageName;
            $dirImg = Mage::getBaseDir().str_replace("/",DS,strstr($imageUrl,'/media'));

            if (!file_exists($imageResized)&&file_exists($dirImg)) {
                $imageObj = new Varien_Image($dirImg);
                $imageObj->constrainOnly(TRUE);
                $imageObj->keepAspectRatio(TRUE);
                $imageObj->keepFrame(FALSE);
                $Resolution = Mage::helper("reviewimage")->getResolution();
                $imageObj->resize($Resolution);
                $imageObj->save($imageResized);
            }
            $newImageUrl = Mage::getBaseUrl('media')."creviewimages/".$imageName;

            $image= "<image src='".$newImageUrl."'>";

            $fieldset->addField('reviewimage', 'note', array(
                'label'     => Mage::helper('review')->__('Posted Review Image'),
                'text'      => $image,
            ));

            $fieldset->addField('appfactory_reviewimage', 'file', array(
                    'label'     => 'AppFactory Review Photo',
                    'required'  => false,
                    'name'      => 'appfactory_reviewimage',
            )); 

       }
            /* 
         * added new image custom field 
         * 
         */

        $fieldset->addField('summary_rating', 'note', array(
            'label'     => Mage::helper('review')->__('Summary Rating'),
            'text'      => $this->getLayout()->createBlock('adminhtml/review_rating_summary')->toHtml(),
        ));

        $fieldset->addField('detailed_rating', 'note', array(
            'label'     => Mage::helper('review')->__('Detailed Rating'),
            'required'  => true,
            'text'      => '<div id="rating_detail">'
                           . $this->getLayout()->createBlock('adminhtml/review_rating_detailed')->toHtml()
                           . '</div>',
        ));


        $fieldset->addField('status_id', 'select', array(
            'label'     => Mage::helper('review')->__('Status'),
            'required'  => true,
            'name'      => 'status_id',
            'values'    => Mage::helper('review')->getReviewStatusesOptionArray(),
        ));

        /**
         * Check is single store mode
         */
        if (!Mage::app()->isSingleStoreMode()) {
            $field = $fieldset->addField('select_stores', 'multiselect', array(
                'label'     => Mage::helper('review')->__('Visible In'),
                'required'  => true,
                'name'      => 'stores[]',
                'values'    => Mage::getSingleton('adminhtml/system_store')->getStoreValuesForForm(),
            ));
            $renderer = $this->getLayout()->createBlock('adminhtml/store_switcher_form_renderer_fieldset_element');
            $field->setRenderer($renderer);
            $review->setSelectStores($review->getStores());
        }
        else {
            $fieldset->addField('select_stores', 'hidden', array(
                'name'      => 'stores[]',
                'value'     => Mage::app()->getStore(true)->getId()
            ));
            $review->setSelectStores(Mage::app()->getStore(true)->getId());
        }

        $fieldset->addField('nickname', 'text', array(
            'label'     => Mage::helper('review')->__('Nickname'),
            'required'  => true,
            'name'      => 'nickname'
        ));

        $fieldset->addField('title', 'text', array(
            'label'     => Mage::helper('review')->__('Summary of Review'),
            'required'  => true,
            'name'      => 'title',
        ));

        $fieldset->addField('detail', 'textarea', array(
            'label'     => Mage::helper('review')->__('Review'),
            'required'  => true,
            'name'      => 'detail',
            'style'     => 'height:24em;',
        ));

        $form->setUseContainer(true);
        $form->setValues($review->getData());
        $this->setForm($form);
        return parent::_prepareForm();
    }
}
3

In your config.xml Problem is this line

<AppFactory_Basic after="Mage_Adminhtml">AppFactory_Basic_Adminhtml</AppFactory_Basic>

should be

<AppFactory_Basic before="Mage_Adminhtml">AppFactory_Basic_Adminhtml</AppFactory_Basic>
  • oh my god, it works. Can you share the difference between After and Before and how Magento handle this? – Yehia A.Salam Nov 26 '16 at 14:22
  • I am not sure but may be it indicates that AppFactory_Basic controller will load before Mage_Adminhtml. – Piyush Nov 26 '16 at 14:38

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.