Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Magento 1.7 - How to link to product's Admin Edit Page from within the Order View page?

When viewing an order, my employees would like to be able to click on the product's name or SKU, and for that to be a link to that product's Product Info edit page.

I figured out how to change the product name into a link, with that link being the url of the product page on Front End, but I don't want the link going to the front end, I need it to link to the products edit page in Admin Dashboard.

This is the code I used in:

app/design/adminhtml/default/default/template/sales/order/view/items/renderer/default.phtml

<div class="item-text">
<?php $_pullProduct = Mage::getModel('catalog/product')->loadByAttribute('sku', $_item->getData('sku')); ?>
<a target="_blank" rel="external" href="<?php echo Mage::getUrl() . $_pullProduct->getData('url_path'); ?>"><?php echo $this->getColumnHtml($_item, 'name') ?></a>
</div>

...and this properly links me to the product frontend page. Now, as I said, that's not what I want, so how do I get this to be a link to the product's admin dashboard edit page?

I attempted at changing the above code in the same file to:

<div class="item-text">
<?php $_pullProduct = Mage::getModel('catalog/product')->loadByAttribute('sku', $_item->getData('sku')); ?>
<a target="_blank" rel="external" href="<?php echo Mage::getSingleton('adminhtml/url')->getUrl('adminhtml/catalog_product/edit', array('id' => $this->getProduct()->getId()))?>"><?php echo $this->getColumnHtml($_item, 'name') ?></a>
</div>

...however that's not right, and the Order View page breaks when I try this. I feel like I'm getting close, can any of you help me in the right direction, please?

like image 279
stephen wise Avatar asked Apr 22 '13 20:04

stephen wise


2 Answers

Ok, so this following code, used in app/design/adminhtml/default/default/template/sales/order/view/items/renderer/default.phtml

works perfectly! This answer was given to me by Marius in the Magento Stack Exchange site. Thanks Marius!

<div class="item-text">
<?php $_pullProduct = Mage::getModel('catalog/product')->loadByAttribute('sku', $_item->getData('sku')); ?>
<a target="_blank" rel="external" href="<?php echo Mage::helper('adminhtml')->getUrl('adminhtml/catalog_product/edit', array('id' => $_pullProduct->getId()))?>"><?php echo $this->getColumnHtml($_item, 'name') ?></a>
</div>
like image 72
stephen wise Avatar answered Oct 19 '22 07:10

stephen wise


I am not sure if this helps but hopefully this will bring you on the right path. I faced a similar problems with regards to admin links in Mage 1.7.0.2

I was trying to redirect an user to the catalog product listing page if the user tries to edit a product that has been marked as not his (I used an attribute to store the product's admin user) via an observer function.

I used the following code :

Mage::app()->getResponse()->setRedirect(Mage::getUrl('adminhtml/catalog_product/index'))->sendResponse();

It works. Previously all redirects would only lead to the frontend. You would need to figure out how to put this code in .phtml files. My suggestion would be to extend the core block for this template.

like image 29
Fadzly Othman Avatar answered Oct 19 '22 08:10

Fadzly Othman