0

I have uploaded several images for a product.

Now I want to get only non-exluded images of type 'small_image'.

I have this code:

$mediaGalleryImages =  Mage::getModel('catalog/product')->load(1749)->getMediaGalleryImages('small_image');
                                        Zend_Debug::dump($mediaGalleryImages->toArray());exit;

output:

 array(2) {
  ["totalRecords"] => int(7)
  ["items"] => array(7) {
    [0] => array(11) {
      ["value_id"] => string(5) "12196"
      ["file"] => string(41) "/c/u/custom-leather-sofa-holly-hill-3.jpg"
      ["label"] => string(41) "Custom Upholstered Fabric Sofa Holly Hill"
      ["position"] => string(1) "1"
      ["disabled"] => string(1) "0"
      ["label_default"] => string(41) "Custom Upholstered Fabric Sofa Holly Hill"
      ["position_default"] => string(1) "1"
      ["disabled_default"] => string(1) "0"
      ["url"] => string(91) "http://localhost/silvercoast/media/catalog/product/c/u/custom-leather-sofa-holly-hill-3.jpg"
      ["id"] => string(5) "12196"
      ["path"] => string(88) "/var/www/html/silvercoast/media/catalog/product/c/u/custom-leather-sofa-holly-hill-3.jpg"
    }
    [1] => array(11) {
      ["value_id"] => string(5) "12194"
      ["file"] => string(41) "/c/u/custom-leather-sofa-holly-hill_1.jpg"
      ["label"] => string(41) "Custom Upholstered Fabric Sofa Holly Hill"
      ["position"] => string(1) "2"
      ["disabled"] => string(1) "0"
      ["label_default"] => string(41) "Custom Upholstered Fabric Sofa Holly Hill"
      ["position_default"] => string(1) "2"
      ["disabled_default"] => string(1) "0"
      ["url"] => string(91) "http://localhost/silvercoast/media/catalog/product/c/u/custom-leather-sofa-holly-hill_1.jpg"
      ["id"] => string(5) "12194"
      ["path"] => string(88) "/var/www/html/silvercoast/media/catalog/product/c/u/custom-leather-sofa-holly-hill_1.jpg"
    }
    [2] => array(11) {
      ["value_id"] => string(4) "9182"
      ["file"] => string(42) "/c/u/custom-leather-sofa-holly-hill_2_.jpg"
      ["label"] => string(41) "Custom Upholstered Fabric Sofa Holly Hill"
      ["position"] => string(1) "3"
      ["disabled"] => string(1) "0"
      ["label_default"] => string(41) "Custom Upholstered Fabric Sofa Holly Hill"
      ["position_default"] => string(1) "3"
      ["disabled_default"] => string(1) "0"
      ["url"] => string(92) "http://localhost/silvercoast/media/catalog/product/c/u/custom-leather-sofa-holly-hill_2_.jpg"
      ["id"] => string(4) "9182"
      ["path"] => string(89) "/var/www/html/silvercoast/media/catalog/product/c/u/custom-leather-sofa-holly-hill_2_.jpg"
    }
    [3] => array(11) {
      ["value_id"] => string(5) "13615"
      ["file"] => string(41) "/c/u/custom-leather-sofa-holly-hill_2.jpg"
      ["label"] => string(41) "Custom Upholstered Fabric Sofa Holly Hill"
      ["position"] => string(2) "10"
      ["disabled"] => string(1) "0"
      ["label_default"] => string(41) "Custom Upholstered Fabric Sofa Holly Hill"
      ["position_default"] => string(2) "10"
      ["disabled_default"] => string(1) "0"
      ["url"] => string(91) "http://localhost/silvercoast/media/catalog/product/c/u/custom-leather-sofa-holly-hill_2.jpg"
      ["id"] => string(5) "13615"
      ["path"] => string(88) "/var/www/html/silvercoast/media/catalog/product/c/u/custom-leather-sofa-holly-hill_2.jpg"
    }
    [4] => array(11) {
      ["value_id"] => string(5) "12195"
      ["file"] => string(41) "/c/u/custom-leather-sofa-holly-hill-2.jpg"
      ["label"] => string(41) "Custom Upholstered Fabric Sofa Holly Hill"
      ["position"] => string(2) "11"
      ["disabled"] => string(1) "0"
      ["label_default"] => string(41) "Custom Upholstered Fabric Sofa Holly Hill"
      ["position_default"] => string(2) "11"
      ["disabled_default"] => string(1) "0"
      ["url"] => string(91) "http://localhost/silvercoast/media/catalog/product/c/u/custom-leather-sofa-holly-hill-2.jpg"
      ["id"] => string(5) "12195"
      ["path"] => string(88) "/var/www/html/silvercoast/media/catalog/product/c/u/custom-leather-sofa-holly-hill-2.jpg"
    }
    [5] => array(11) {
      ["value_id"] => string(4) "9183"
      ["file"] => string(42) "/c/u/custom-leather-sofa-holly-hill_1_.jpg"
      ["label"] => string(41) "Custom Upholstered Fabric Sofa Holly Hill"
      ["position"] => string(2) "15"
      ["disabled"] => string(1) "0"
      ["label_default"] => string(41) "Custom Upholstered Fabric Sofa Holly Hill"
      ["position_default"] => string(2) "15"
      ["disabled_default"] => string(1) "0"
      ["url"] => string(92) "http://localhost/silvercoast/media/catalog/product/c/u/custom-leather-sofa-holly-hill_1_.jpg"
      ["id"] => string(4) "9183"
      ["path"] => string(89) "/var/www/html/silvercoast/media/catalog/product/c/u/custom-leather-sofa-holly-hill_1_.jpg"
    }
    [6] => array(11) {
      ["value_id"] => string(5) "14475"
      ["file"] => string(41) "/c/u/custom-leather-sofa-holly-hill_3.jpg"
      ["label"] => string(46) "Custom Upholstered Fabric Sofa Holly Hill test"
      ["position"] => string(2) "20"
      ["disabled"] => string(1) "0"
      ["label_default"] => string(46) "Custom Upholstered Fabric Sofa Holly Hill test"
      ["position_default"] => string(2) "20"
      ["disabled_default"] => string(1) "0"
      ["url"] => string(91) "http://localhost/silvercoast/media/catalog/product/c/u/custom-leather-sofa-holly-hill_3.jpg"
      ["id"] => string(5) "14475"
      ["path"] => string(88) "/var/www/html/silvercoast/media/catalog/product/c/u/custom-leather-sofa-holly-hill_3.jpg"
    }
  }
}

I have also check this post: How to get the image type in media image collection?

http://www.magecoders.com/blog/2013/05/programmatically-exclude-product-images-in-magento/

1

finally I found the answer:

$secondimage = "";
$smallimage = "";
$smallimageLabel = "";
$secondimageLabel = "";
$product = Mage::getModel('catalog/product')->load($product->getId());
$getSecondSmallImage = $product->getSecondsmallimage();
$getSmallImage = $product->getSmallImage();

foreach ($product->getMediaGalleryImages() as $_image) {

    $imageFile = $_image->getFile();
    if ($imageFile == $getSecondSmallImage && "" == $secondimage) {
        $secondimage = (string)Mage::helper('catalog/image')
            ->init($product, 'secondsmallimage', $imageFile)
            ->keepFrame(false)->resize(573, 282);
        $secondimageLabel = $_image->getLabel();
    }

    if ($imageFile == $getSmallImage && "" == $smallimage) {
        $smallimage = (string)Mage::helper('catalog/image')
            ->init($product, 'small_image', $imageFile)
            ->keepFrame(false)->resize(573, 282);
        $smallimageLabel = $_image->getLabel();
    }

}
0

Use below code:

$mediaGalleryImages =  Mage::getModel('catalog/product')->load(1749)->getMediaGalleryImages('small_image');
   foreach ($mediaGalleryImages as $image) {
         if ($image['disabled']) {
              //here is your code
         }else{
              continue;
         }

   }
  • this will give me all non-excluded images of the product but I want only non-excluded small_image. Also there is no effect on passing the parameter into getMediaGalleryImages() – Faiyaz Alam Mar 30 '16 at 10:49
  • updated answer try it – Prashant Valanda Mar 30 '16 at 10:51
  • I tried your answer but it is not working – Faiyaz Alam Mar 30 '16 at 11:10

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.