1

I have been working on our site to download the images for specific SKUs. I am fetching the images like following

require('../app/Mage.php');
Mage::init();
$sku = $_REQUEST['sku'];
$product = Mage::getModel('catalog/product')->loadByAttribute('sku', $sku);
$_images = $product->getMediaGalleryImages();
$url = array();
if(empty($_images))
    die();
foreach ($_images as $image) {
   $url[] =  str_replace('https:' , 'http:',$image->getUrl());
} 
echo implode("|||" , $url);

It works well for the enabled products, but images for disabled products can't be fetched using this snippet. Can anybody help me out to load disabled product images by SKU?

3
  • Does your Magento install use flat tables?
    – Rob
    May 14 '15 at 12:02
  • Yes it does @Rob
    – Gogol
    May 14 '15 at 12:20
  • I will refine my answer once back at a computer. But when loading a collection with flat tables "on" it will not return disabled products unless you load it in the context of the admin store. I'd start there. I'll post more once I'm on.
    – Rob
    May 14 '15 at 12:27
1

As per as magento system loadByAttribute() get item from Collection and magento does not provide all data of product from product Collection... See at Class Mage_Catalog_Model_Abstract

 public function loadByAttribute($attribute, $value, $additionalAttributes = '*')
    {
        $collection = $this->getResourceCollection()
            ->addAttributeToSelect($additionalAttributes)
            ->addAttributeToFilter($attribute, $value)
            ->setPage(1,1);

        foreach ($collection as $object) {
            return $object;
        }
        return false;
    }

If magento collect product collection at frontend then magento remove all Disable product Collection.

So that you need use load function.

Or use Current store as admin by Changing

Mage::init();

to

Mage::app('admin');

Also,check the link for getting media image faster ways.See the link

Faster way to load media images in a product collection

1
  • Changing Mage::init(); to Mage::app('admin'); does the trick thanks!
    – Gogol
    May 14 '15 at 13:01

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.