2014-05-24 158 views
1

嗨,我有一個約25000產品的數據庫。有這麼多的產品,有畫廊圖像,但他們沒有分配到產品 您可以告訴我什麼shoyuld查詢,檢查產品沒有縮略圖或基礎圖像,但有畫廊圖像,並分配它們。如何從畫廊產品圖像分配到產品Magento

我已經盡力找到所需的產品與下面的代碼

$products = Mage::getModel('catalog/product') 
->getCollection() 
->addAttributeToSelect('*') 
->addAttributeToFilter('small_image',array('neq'=>'no_selection')); 

,但問題是該產品在畫廊圖像,但不分配。 所以請告訴我如何找到帶有圖庫圖片的產品並將其分配給產品。

回答

0

我已將第一個產品庫圖像設置爲小圖像。

$products = Mage::getModel('catalog/product') 
    ->getCollection() 
    ->addAttributeToSelect('*') 
    ->addAttributeToFilter('small_image',array('neq'=>'no_selection')); 

    foreach($products as $pro){ 

    $product->load($pro->getId()); 
    $gallery = $product->getMediaGalleryImages(); 

    $paths = array(); 
    foreach ($gallery as $image) { 
     $paths[] = $image->getFile(); 
     $product->setSmallImage($image->getFile()) 
      ->save(); 
break; 
    } 

    }