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

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.

1
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

3
  • Thanks amit for answer but i don't want to load product,,,is there any trick or sql query to check product base image? – Keyur Shah Jun 16 '15 at 19:02
  • i will see ..... and you have put down vote... – Amit Bera Jun 16 '15 at 19:05
  • no amit i didn't do that,,,and i will never put down your vote ,,because i know the your valuable contribution,,,But still +1 from me – Keyur Shah Jun 16 '15 at 19:13

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.