如何使用Magento获取完整的图库图像URL路径?

时间:2015-06-05 06:27:12

标签: php image magento

我有一个代码,它有diplays产品sku,产品名称,产品图片完整路径,但不显示图库图片的完整路径,只显示图库图片文件名,但我想显示图库的完整路径,那怎么能我解决了这个问题,任何人都可以告诉我这个答案吗?

Product SKU:HGCL
product name:Earring03
product image url:http://example.com/media/catalog/product/cache/1/image/265x/9df78eab33525d08d6e5fb8d27136e95/0/0/0003_3.jpg

Gallery images not showing the full paths, only image names, i want to display full path.
    /0/0/0003_3.jpg
    /v/c/vcm_s_kf_repr_658x790_28.jpg



<pre>
    <?php
    $product_collection = Mage::getModel('catalog/category')->load($categoryId)->getProductCollection();
    foreach($product_collection as $product) {
    $product_id = $product->getId();
    $full_product = Mage::getModel('catalog/product')->load($product_id);
    $product_sku = $full_product->getSku();
    $product_name = $full_product->getName();
    $product_url = $full_product->getProductUrl();
    $product_image_url = $full_product->getImageUrl();
    $product_image_url_gallery = $full_product->getMediaGallery();
    echo "Product SKU:".$product_sku; echo "<br/>";
    echo "product name:".$product_name; echo "<br/>";
    echo "product image url:".$product_image_url; echo "<br/>";

      for($i=0;$i<count($product_image_url_gallery);$i++)
      {  
      echo $product_image_url_gallery['images'][$i]['file']; echo "<br/>";

      }
      echo "-------------------------------------------------------"; echo "<br/>";

    }
    ?>
    </pre>

1 个答案:

答案 0 :(得分:0)

以下是使用网址获取所有图库图片的更新代码:

$categories = Mage::helper('catalog/category')->getStoreCategories();

foreach($categories as $category) {

$categoryId = $category->getId();
$product_collection = Mage::getModel('catalog/category')->load($categoryId)->getProductCollection();

  foreach($product_collection as $product) {

      $product_id = $product->getId();
      $full_product = Mage::getModel('catalog/product')->load($product_id);
      $product_sku = $full_product->getSku();
      $product_name = $full_product->getName();
      $product_url = $full_product->getProductUrl();
      $product_image_url = $full_product->getImageUrl();
      $product_image_url_gallery = $full_product->getMediaGalleryImages();
      echo "Product SKU:".$product_sku; echo "<br/>";
      echo "product name:".$product_name; echo "<br/>";
      echo "product image url:".$product_image_url; echo "<br/>";


      foreach ($product_image_url_gallery as $image) {
        echo Mage::helper('catalog/image')->init($full_product, 'image', $image->getFile()).'<br>';
      }     

      echo "-------------------------------------------------------"; echo "<br/>";

   }
} 

希望这有帮助!!