0

I have developed a custom module with a grid. Also added a column named "View Product" to be able to navigate to the current product page. With my current solution all "view" links redirect to products page, not to that particular product. How can I fix that?

Thanks,

$product_id=$this->getRequest()->getParam('id');                    
$this->addColumn('view',
array(
'header'    => Mage::helper('catalog')->__('View Product'),
'width'     => '40px',
'type'      => 'action',
'getter'     => 'getId',
'actions'   => array(
array(
'caption' => Mage::helper('catalog')->__('View'),
'url'     => array(
    'base'=>'adminhtml/catalog_product/edit/id/$product_id',
    'params'=>array('store'=>$this->getRequest()->getParam('store'))
                ),
    'field'   => 'id'
     )
     ),
    'filter'    => false,
    'sortable'  => false,
    'index'     => 'stores',
    ));

Solution Type 2: Also tried this solution but it redirects to the "New Product" page instead of the "Edit product" page.

$link= Mage::helper('adminhtml')->getUrl('adminhtml/catalog_product/edit/') .'id/$entity_id';
$this->addColumn('action_edit', array(
'header'   => $this->helper('catalog')->__('Action'),
'width'    => 15,
'sortable' => false,
'filter'   => false,
'type'     => 'action',
'actions'  => array(
 array(
'url'     => $link,
'caption' => $this->helper('catalog')->__('Edit'),
),
)
));

2 Answers 2

0

Loose id/$product_id:

   ....
   'base'=>'adminhtml/catalog_product/edit'
   ....
6
  • Gerasimov when I remove id/$product_id I get this error message (please view my question, i have added the print screen there). Also, I need each "view" link to redirect to that particular product page instead of "Manage products" page. Commented May 2, 2017 at 17:02
  • post your view url that gets generated, do not call me gerasimov my name is konstantin.
    – goivvy.com
    Commented May 2, 2017 at 17:44
  • Hi @Konstantin , here is the url. formodulecheck.dev/index.php/admin/catalog_product/index/key/… I wrote both your name and last name, the first name disappeared with @. Thanks Commented May 2, 2017 at 17:52
  • this url doesn't have edit in it - post the url that is attached to view text in your grid. (right click on it and copy url)
    – goivvy.com
    Commented May 2, 2017 at 18:29
  • I don't really understand how that can happen, but this is the url that's being loaded after clicking on the "View". I added another type of solution to my question, which also doesn't work correctly, it redirects to "New Product" page and the URL for that page is: formodulecheck.dev/index.php/admin/catalog_product/edit/key/… Commented May 2, 2017 at 19:17
0

Here is the solution to this problem:

$this->addColumn('action',
array(
    'header'    => Mage::helper('catalog')->__('Action'),
    'width'     => '50px',
    'type'      => 'action',
    'getter'     => 'getProductcomment_increment_id',
    'actions'   => array(
        array(
            'caption' => Mage::helper('catalog')->__('Product Backend Url'),
            'url'     => array(

    'base'=>'adminhtml/catalog_product/edit/productcomment_increment_id/',
                'params'=>array('store'=>$this->getRequest()->getParam('entity_id'))
            ),
    'field'   => 'id'
        )
    ),
    'filter'    => false,
    'sortable'  => false,
    'index'     => 'stores',
));

Explanations:

In the database table of my custom grid product IDs are stored in the column named "productcomment_increment_id", so I should put

'getter'     => 'getProductcomment_increment_id'

instead of 'getter' => 'getId'.

Also the base should be:

'base'=>'adminhtml/catalog_product/edit/productcomment_increment_id/',

Pay attention to the name after .../edit/.

And lastly, the field should be 'field' => 'id'.

I have spent hours to find this solution, hopefully it will help someone.

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.