2014-09-25 109 views
0

我可以在創建期間使用以下腳本將圖像添加到產品。但是,我無法加載產品並將其他圖像添加到產品媒體庫。是否必須刪除產品媒體庫並一次讀取所有圖像?它是一個csv文件中的每行一個圖像。如何將附加圖像添加到Magento中的產品

public function addImage($product, $image) 
{ 
    $imagePath = $this->downloadImage($image); 
    $product->setMediaGallery(array('images' => array(), 'values' => array())); 
    if (is_file($imagePath)) { 
     $product->addImageToMediaGallery($imagePath, array('image', 'small_image', 'thumbnail'), false, false); 
    } 
} 

回答

0

爲什麼使用腳本添加圖像?在magento中添加圖像可以通過管理界面輕鬆完成。

只需登錄管理面板,目錄>管理產品>編輯產品>圖像(左側面板)。

0

使用以下腳本添加其他圖像。

$importDir = Mage::getBaseDir('media') . DS; 
// additional images 
    if ($import_product[29] != '') { 
     $addImages = explode(",", trim($import_product[29])); 
     foreach ($addImages as $additional_image) { 
      $image_directory = $dir .DS.'data'.DS. trim($additional_image); 
      if (file_exists($image_directory)) { 
       $product->addImageToMediaGallery($image_directory, null, false, false); 
      } else { 
       $image_directory = $dir . 'data' . DS . 'comingsoon.jpg'; 
       $product->addImageToMediaGallery($image_directory, null, false, false); 
      } 
     } 
     echo 'Additional images for product ' . $product->getName() . ' ' . $product->getId() . ' imported successfully' . PHP_EOL; 
    } 

$ import_product [29]是由逗號分隔的圖像陣列。請參閱我的教程以及解釋如何設置默認圖像。

http://www.pearlbells.co.uk/how-to-add-main-image-and-additional-image-to-the-products-pro-grammatically-magento/

相關問題