2

We are looking to create a link to the frontend of a product and the backend of a product from the "items ordered" area of the sales order page. We have the code to create both, but not from the same section. By this we mean we can't combine them into the same column/area, For example we have:

Frontend:

    <td>
        <?php if ($this->canDisplayContainer()): ?>
        <div id="<?php echo $this->getHtmlId() ?>" class="item-container">
        <?php endif; ?>
        <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>
        <?php if ($this->canDisplayContainer()): ?>
        </div>
        <?php endif ?>
    </td>

And for the backend:

<td>
        <?php if ($this->canDisplayContainer()): ?>
        <div id="<?php echo $this->getHtmlId() ?>" class="item-container">
        <?php endif; ?>
        <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>
        <?php if ($this->canDisplayContainer()): ?>
        </div>
        <?php endif ?>
    </td>

Can this code be combined to create a link to the frontend from the product name, and a link to the product backend from the SKU?

We would ideally like to create a small module or file to override the default configuration in Magento so the code is not overwritten in future updates.

1
  • No takers on this? I've still not managed to develop a way to do this unfortunately. Another issue is that the above code doesn't work on configurable products or products with a custom option added to it such as size or colour, so the sales order page won't load at all.
    – MagentoMac
    Commented Nov 3, 2013 at 16:31

1 Answer 1

2

You can get the url for frontend like this:

$_pullProduct = Mage::getModel('catalog/product')->load($_item->getProductId());
if ($_pullProduct->getId()) { //if the product still exists
    $url = $_pullProduct->getProductUrl();
}
else {
    $url = false; //product does not exist anymore
}

For backend try this

$_pullProduct = Mage::getModel('catalog/product')->load($_item->getProductId());
if ($_pullProduct->getId()) { //if the product still exists
    $url = Mage::helper('adminhtml')->getUrl('adminhtml/catalog_product/edit', array('id'=>$_pullProduct->getId()));
}
else {
    $url = false; //product does not exist anymore
}

Note:
The backend url works only if you call this code from the backend or if you disable the session key in url (but you shouldn't do that).

2
  • Perfect! Thanks. Sorry for slow reply. Any idea how to package this into a mini custom module so it's not overwritten in Magento updates?
    – MagentoMac
    Commented Mar 28, 2014 at 0:28
  • @Blair. You can change the admin theme: magentocommerce.com/wiki/4_-_themes_and_template_customization/… and in your theme add just the file you need to edit and make your modifications there.
    – Marius
    Commented Mar 28, 2014 at 7:04

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.