1

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.

  • 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 Nov 3 '13 at 16:31
1

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

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.