Magento 1.7 – How to Link to Product’s Admin Edit Page from Order View Page

magento-1.7

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?

Best Answer

This should work:

<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>