Magento 1.8设置产品图像属性:Base,Thumbnail,Small_Image

时间:2015-08-20 09:36:46

标签: magento-1.8

我正在以编程方式在magento上创建简单的产品。产品使用图像成功创建,但问题是它没有为图像设置属性Base,Thumbnail,Small_Image。我在这里做错了什么?

            //Image parameters
            $mediaArray = array('thumbnail', 'small_image', 'image'); 
            $img = $img_subdir.'/fimage.jpeg';


            //create new product
            $newProduct = new Mage_Catalog_Model_Product();
            $newProduct->setAttributeSetId(9)
                       ->setTypeId('simple')
                       ->setVisibility(Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH)
                       ->setTaxClassId(2)
                       ->setCreatedAt(strtotime('now'))
                       ->setName('test product #'.mt_rand().'')
                       ->setSku(mt_rand())
                       ->setWeight(25)
                       ->setStatus(1)
                       ->setPrice(25)
                       ->setCategoryIds(explode(',',10))
                       ->setWebsiteIds(explode(',',1))
                       ->setDescription('test')
                       ->setShortDescription('test')
                       ->setMetaTitle('test')
                       ->setMetaKeyword('test')
                       ->setMetaDescription('test')
                       ->setStockData(array(
                                             'manage_stock'=>0,
                                             'min_sale_qty'=>2,
                                             'max_sale_qty'=>10,
                                             'manage_stock'=> 1, 
                                             'is_in_stock'=> 1,
                                             'qty'=> 5,))
                       ->setSetupFee(25)
                       ->addImageToMediaGallery($img, $mediaArray, false, false)
                       ->setsetupCost(25);

                       $newProduct->save(); 

1 个答案:

答案 0 :(得分:0)

在保存之前应该这样做:

#! /usr/bin/python

data = ('Hello')
print data