1

I want to display the productimage, based on the SKU of the product.

How can I achieve this?

My currenty code in a custom module, that displays the SKU based on the following code:

<?php echo $item->getProduct() ? $item->getProduct()->getSku() : Mage::helper('rma')->getOrderItemLabel($item) ?>
2

If you have $item object then you can easily get the product image by like this,

Mage::getModel('catalog/product_media_config')->getMediaUrl($item->getProduct()->getSmallImage());

But still If you want the product Image based on SKU then you can get it like this,

    $product = Mage::getModel('catalog/product')->loadByAttribute('sku', $item->getProduct()->getSku());

    $imageUrl=Mage::getModel('catalog/product_media_config')->getMediaUrl($product->getSmallImage());
1

Use this :

$product = Mage::getModel('catalog/product')->loadByAttribute('sku',$_sku);
$product->getData('image');
$product->getData('thumbnail');
$product->getData('small_image');
1

Keyur Shah first part is correct, but there is no loadBySku method as suggested in 2nd part. For loading products by SKU you should use

Mage::getModel('catalog/product')->loadByAttribute('sku',$_sku);

To keep the loaded data as small as possible you can add a 3rd parameter with attribute codes you want to load, e.g.

$attributes = array('image', 'thumbnail');
Mage::getModel('catalog/product')->loadByAttribute('sku', $_sku, $attributes);

(Default value for 3rd parameter is '*', so it will load all attributes)

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.