public function addImageSet($productFromCollection, AlvineImageSet $imageSet)
 {
     $product = Mage::getModel("catalog/product")->load($productFromCollection->getId());
     $imagesToAdd = $imageSet->getImages();
     self::log("aktuelles Produkt: " . $product->getId());
     foreach ($imagesToAdd as $image) {
         self::log("bearbeite\t" . $image->getType());
         $this->storeImageToTempPath($image);
         if ($image->getType() === AlvineImage::TYPE_MAIN) {
             $product->addImageToMediaGallery($this->getTempFilename($image), $this->getMediaAttributes(), false, false);
         } else {
             $product->addImageToMediaGallery($this->getTempFilename($image), null, false, false);
         }
         $gallery = $product->getData('media_gallery');
         $galleryImage = array_pop($gallery["images"]);
         $imageData = $this->getImportData($image);
         $galleryImage['label'] = $imageData['label'];
         $galleryImage['position'] = $imageData['position'];
         $galleryImage['disabled'] = $imageData['disabled'];
         $gallery["images"][] = $galleryImage;
         $product->setData('media_gallery', $gallery);
     }
     if ($product->getTypeId() == 'simple') {
         $product->setVisibility("1");
     } elseif ($product->getTypeId() == 'configurable') {
         $stockItem = Mage::getModel('cataloginventory/stock_item')->load($product->getId(), 'product_id');
         $stockItem->setData('manage_stock', 1);
         $stockItem->setData('is_in_stock', 1);
         $stockItem->setTypeId($product->getTypeId());
         $stockItem->save();
     }
     $product->save();
 }
Пример #2
0
function importImageSet(AlvineImageSet $set)
{
    $helper = new MagentoImageHelper();
    $mainImage = $set->getMainImage();
    $products = $helper->fetchProducts($mainImage->getArticleNumber(), $mainImage->getColorCode());
    $helper->log(sprintf("%s Produkt(e) geladen", $products->count()));
    foreach ($products as $product) {
        $helper->addImageSet($product, $set);
    }
}