1

I have a custom grid, where I need to add links to Product Edit pages on back-end. I was able to get product front-end URLs using a renderer, but can't get the product links on back-end.

I have tried this code, but it redirects to the "Manage products" page instead of that particular product and I'm getting an error "This product no longer exists".

$this->addColumn('action', array(
    'header'    => Mage::helper('catalog')->__('Action'),
    'width'     => '50px',
    'type'      => 'action',
    'getter'    => 'getId',
    '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',
));

How can I get the product edit page URLs on the back-end? Thanks for help in advance.

  • Hi, could you provide the complete url you get from a sample product? I think you are missing the product id value at the end of the url. Regarding whether to show a frontend or backend url that depends on what you want to accomplish. The first would be if you want to show how the product looks in the store and the second if you want to edit something in the product. – Jalogut Apr 25 '17 at 19:55
  • Hi @Jalogut, thanks for your response. I'm getting this url after pressing the "View" link: formodulecheck.dev/index.php/catalog/product/view/id/33/key/… – bestwebdevs Apr 25 '17 at 20:57
  • 1
    Hi @bestwebdevs, the problem is that you get an admin url with the path for the product into the frontend. Can you try with adminhtml/catalog_product/edit? This should give you a valid admin url to the product management. I will check tomorrow how to return the product frontend url. – Jalogut Apr 25 '17 at 21:51
  • Just found here that you can pass the complete url to the url value: magento.stackexchange.com/questions/4449/… You migth use this solution to set the frontend url to catalog/product/view/id/$productId – Jalogut Apr 25 '17 at 22:03
  • Hi @bestwebdevs, I edited my last comment with another solution. Let me know if that works. – Jalogut Apr 26 '17 at 6:16
2

In your code you're using single quotes for the url. Within single quotes, it's not possible to parse variables, that might be part of your problem.

Also, this functionality is also in the core Magento file app/code/core/Mage/Adminhtml/Block/Catalog/Product/Grid.php, which might be the perfect example to get your solution. When you check that file and look for the line where the "Edit" action is added to the grid, you will find this code:

$this->addColumn('action',
    array(
        'header'    => Mage::helper('catalog')->__('Action'),
        'width'     => '50px',
        'type'      => 'action',
        'getter'     => 'getId',
        'actions'   => array(
            array(
                'caption' => Mage::helper('catalog')->__('Edit'),
                'url'     => array(
                    'base'=>'*/*/edit',
                    'params'=>array('store'=>$this->getRequest()->getParam('store'))
                ),
                'field'   => 'id'
            )
        ),
        'filter'    => false,
        'sortable'  => false,
        'index'     => 'stores',
));

Now, in your case you can't use the */*/edit part, because it will try to initialise the edit action of your custom extension, which probably doesn't exist. So you need to replace the */*/ part with a working URL path. If you go to the file app/code/core/Mage/Catalog/etc/adminhtml.xml, you can find the URLs that are used for the links in the menu. Since */* just "tells" Magento to use the same module and controller as the current page, you can get this info from that file. Here you can see that the link to the "Manage Products" page is adminhtml/catalog_product. There is no action defined here, which means it will use the index action.

So if you replace */*/edit with adminhtml/catalog_product/edit, your links should work properly, except for the fact that the field needs to be changed to the correct field you're using in your extension.

  • Thanks @Arjen,I appreciate your detailed response (sorry for delay).I do have an edit action on my custom module and you are right */*/edit is redirecting there. But "adminhtml/catalog_product/edit" also doesn't work correctly, it's redirecting to "New Product' page instead of "Edit product". – bestwebdevs May 16 '17 at 22:09
  • 1
    @bestwebdevs do you get an ID in that URL? Because that's the difference between editing an existing product and creating a new one. I have the feeling that the part 'field' => 'id' is where it goes wrong here. – Arjen Miedema May 22 '17 at 5:43
  • Hi @Arjen, I have made changes to the codes, now the link goes to "Manage products page" and also I'm getting an error "This product no longer exists.". The URL of that page is .../index.php/admin/catalog_product/index/key/00ca27bdd64116dba79ee661ac034f04/ And when I put 'field' => 'productcomment_increment_id', it redirects to "New product" page again. (productcomment_increment_id is the product id in my custom grid database table). – bestwebdevs May 22 '17 at 17:56
  • Hi @Arjen, I just resolved it, will post an answer now. Your explanations helped me to find a solution. – bestwebdevs May 22 '17 at 18:17
  • Great! Glad I could help! – Arjen Miedema May 23 '17 at 5:51
1

This is how I resolved the issue:

$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, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.