7

How can i get the product base-image without loading the whole product object ? I have product-id,sku.[I know we can get product base image from product object]

Is there any best method or trick available for that ?

Any help will be appreciated.

Thank you

Keyur Shah
  • 18,046
  • 6
  • 66
  • 80

2 Answers2

8

You can use this code:

$model = Mage::getResourceModel('catalog/product');
$img = $model->getAttributeRawValue($productId, 'image', $storeId);

For "Small image" use small_image and for "Thumbnail" thumbnail. Similar question was posted here.

artwoz
  • 359
  • 2
  • 5
1

In this case you use afterload() function.

  • First load product by loadByAttribute() ,which does not load full image.It take data from product collection

  • then using afterLoad() and using image backend models of base image attribute you can get image easily

    $sku='wbk003c';
    
    $product = Mage::getModel('catalog/product')->loadByAttribute('sku',$sku);
    
    $attributes = $product->getTypeInstance(true)->getSetAttributes($product);
        $image = $attributes['image'];
        $backend = $image->getBackend();
        $backend->afterLoad($product); 
       echo  $Theimage = $product->getImage();
    

Anther example is :

Faster way to load media images in a product collection

Amit Bera
  • 77,456
  • 20
  • 123
  • 237