1
votes

I've created a magento product with no default (Admin) images, but I've properly setted an image as thumbnail, small_image and imageset for the "italian" store view.

If I use the following code in a phtml files I'get the correct image url:

echo "url = " . Mage::helper('catalog/image')->init($product, 'thumbnail')->resize(95,95)

I get : media/catalog/product/cache/6/image/80x/9df78eab33525d08d6e5fb8d27136e95/1/9/1901186_10152274267007184_1589016979_n_7.jpg

Inside a controller for an ajax callback fucntion I use the following:

$product = Mage::getModel('catalog/product')->loadByAttribute('sku',$sku);
echo "url = " . Mage::helper('catalog/image')->init($product, 'thumbnail')->resize(95,95);

but I alwais get the placeholder image /media/catalog/product/cache/6/thumbnail/95x95/9df78eab33525d08d6e5fb8d27136e95/placeholder/websites/3/LOGO_1.png

I try to set the product storeId before loading the product data but no result:

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

    echo "vediamo " . Mage::helper('catalog/image')->init($product, 'thumbnail')->resize(95,95);;

Thank for any helps and sorry for my english. Giuseppe

2

2 Answers

0
votes

This is working for me

$cathlpimg = new Mage_Catalog_Helper_Image();
echo $cathlpimg->init($_item, 'image')->resize(200);   
0
votes

I'm surprised to see that didn't work - the key thing for me was to specify the store ID before calling load(), but I can see you already tried that.

Although, strictly speaking, you didn't use load(), you used loadByAttribute(). Maybe it doesn't work in quite the same way. Have you tried:

$product = Mage::getModel('catalog/product');
$product = $product->setStoreId(6);
$product = $product->load($id);

If you only know the sku and not the ID, just use this:

$id = Mage::getModel('catalog/product')->getIdBySku($sku);