Question

I'm looking to get links to the products in the customer's My Orders page.

The implementation is for adding the product review link on the "My Orders Page".

I have the following code to fetch the URL of the product using the SKU.

    <?php 
       $sku = $this->htmlEscape(Mage::helper('core/string')->splitInjection($this->getSku())); 
        $url = Mage::getModel('catalog/product')->loadByAttribute('sku',$sku)->getProductUrl();
    ?>
    <td class="a-right"><a href="<?php echo $url; ?>/#add-my-review" target="_blank" class="rate-me"><?php echo $this->htmlEscape('Rate this Item') ?></a></td>

But I'm getting the following error

PHP Fatal ErrorGET /sales/order/view/order_id/20494
Call to a member function getProductUrl() on a non-object

Any thoughts on fixing this?

Was it helpful?

Solution

Using the SKU seems to be a long way of doing things, and potentially unreliable since an order item's SKU can be generated dynamically. You should be able to get an URL more directly.

$url = $this->getOrderItem()->getProduct()->getProductUrl();

OTHER TIPS

It seems like you didn't get the product object using Mage::getModel('catalog/product')->loadByAttribute('sku',$sku)

Can you check your $sku value ?? Please check what value you are getting into $sku and cross check into your magento admin panel that you have the product with that sku value. This can be the reason because of that your code is not returning the object of product which you want here to get the product url.

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top