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?

Gogol
  • 127
  • 1
  • 14
  • 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 Answers1

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

Teja Bhagavan Kollepara
  • 3,816
  • 5
  • 32
  • 69
Amit Bera
  • 77,456
  • 20
  • 123
  • 237