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.
2 Answers 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– bestwebdevs2017年05月16日 22:09:27 +00:00Commented May 16, 2017 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– Arjen Miedema2017年05月22日 05:43:22 +00:00Commented May 22, 2017 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– bestwebdevs2017年05月22日 17:56:34 +00:00Commented May 22, 2017 at 17:56
-
Hi @Arjen, I just resolved it, will post an answer now. Your explanations helped me to find a solution.bestwebdevs– bestwebdevs2017年05月22日 18:17:05 +00:00Commented May 22, 2017 at 18:17
-
Great! Glad I could help!Arjen Miedema– Arjen Miedema2017年05月23日 05:51:45 +00:00Commented May 23, 2017 at 5:51
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.
Explore related questions
See similar questions with these tags.
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.urlvalue: magento.stackexchange.com/questions/4449/… You migth use this solution to set the frontend url tocatalog/product/view/id/$productId