Domanda

how to get all images by using below code. I'm only getting single image

<?php

class Affilnow_Module_Model_Product_Api extends Mage_Api_Model_Resource_Abstract
{
  public function items($attributes)
  {


    $catalog = Mage::getModel('catalog/product')
    ->getCollection()
    ->addStoreFilter(Mage::app()->getStore()->getId());

    $collection = $catalog->addAttributeToSelect("*");
    $tempres = array("helloworld");
    $tempres = json_encode($tempres);
    //var_dump($tempres);
    //echo "<xml>helloworld</xml>";
    //print_r($collection);
    $tempres = json_encode($collection);
    //return $tempres;
    //exit();
    foreach ($collection as $product) {

        $product_id = $product->getId();
        $assoc_variations = array();

        if ($product->isConfigurable()) {

            $assoc_products = $product->getTypeInstance(true)
            ->getConfigurableAttributesAsArray($product);

            foreach ($assoc_products as $assoc_product) {
                $assoc_variations[] = $assoc_product;
            }

        }


      $result[] = array(
        'id'          => $product->getId(),
        'name'        => $product->getName(), 
        'stock'       => $product->isInStock(), 
        'sku'         => $product->getSku(), 
        'weight'      => $product->getWeight(), 
        'description' => $product->getDescription(), 
        'image'       => $product->getImageUrl(), 
        'category'    => $product->getCategoryIds(), 
        'price'       => Mage::helper('core') -> currency($product -> getPrice(), true, false), 
        'hasOptions'  => $product->isConfigurable(), 
        'qty'         => intval($product->getQty()), 
        'created at'  => $product->getCreatedAt(),
        'variations'  => $assoc_variations
        'additional_images' =>$product->getMediaGalleryImage()
        );


  }

  return $result;
  }


}
È stato utile?

Soluzione

Try 1:

$catalog = Mage::getModel('catalog/product')
->getCollection()
->addAttributeToSelect('*') 
->addStoreFilter(Mage::app()->getStore()->getId());

Try 2:

$backendModel = $catalog->getResource()->getAttribute('media_gallery')->getBackend();   

and foreach loop

foreach ($collection as $product) {
   $backendModel->afterLoad($product);
    foreach ($product->getMediaGalleryImages() as $image) {
       echo $image->getUrl();
    }    
}

Altri suggerimenti

try this code :

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

foreach ($product->getMediaGalleryImages() as $image) {
    echo $image->getUrl();
}  
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a magento.stackexchange
scroll top