我正在从 Helper 函数动态创建产品。这很好。并为默认商店视图设置图像工作正常。但对于多商店视图,图像未选为“缩略图”、“小图像”或“图像”。
$product = new Mage_Catalog_Model_Product();
// Build the product
//$product->setSku('pkg-sku-1');
$product->setAttributeSetId(4); //default attribute-set
$product->setTypeId('simple');
$product->setName($pkg_data['pkg_name']);
$product->setCategoryIds(array(7)); # some cat id's, my is 7
$product->setWebsiteIDs(array(1)); # Website id, my is 1 (default frontend)
$product->setDescription('EventPackageForOrder');
$product->setShortDescription($pkg_id);
$product->setPrice($pkg_data['pkg_price']); # Set some price
//Default Magento attribute
$product->setWeight(4.0000);
$product->setVisibility(Mage_Catalog_Model_Product_Visibility::VISIBILITY_NOT_VISIBLE);
$product->setStatus(1);
$product->setTaxClassId(2); # Taxable goods
$product->setStockData(array(
'is_in_stock' => 1,
'qty' => 5
));
$im_url_path = Mage::getBaseUrl('media').'eventdiscpkgs/event_logo.jpeg';
$im_absolute_path = Mage::getBaseDir('media') . DS . 'eventdiscpkgs/event_logo.jpeg';
$product->setMediaGallery (array('images'=>array (), 'values'=>array ()));
$product->addImageToMediaGallery($im_absolute_path, array ('thumbnail'), false, false);
$product->addImageToMediaGallery($im_absolute_path, array ('small_image'), false, false);
$product->addImageToMediaGallery($im_absolute_path, array ('image'), false, false);
$product->setHasOptions(true);
$product->setCreatedAt(strtotime('now'));
try {
$product->save();
}
catch (Exception $ex) {
$ex->getMessage();
}
任何我可以改变的想法。