I loop through a list of products on a CSV mixed with simple and configurable products. I can successfully create all products how I want them with the exception of one thing.

$product->setWebsiteIds(array(1))//website ID the product is assigned to, as an array
                    ->setAttributeSetId($attributeSet)//ID of a attribute set named 'default'
                    ->setTypeId($typeId)//product type
                    ->setCreatedAt(strtotime('now'))//product creation time
                    ->setName($name)//product name
                    ->setStatus(1)//product status (1 - enabled, 2 - disabled)
                    ->setTaxClassId(2)//tax class (0 - none, 1 - default, 2 - taxable, 4 - shipping)
                    ->setVisibility(Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH)//catalog and search visibility
                    ->setCountryOfManufacture('US')//country of manufacture (2-letter country code)
                    ->setPrice($price)//price in form 11.22
                    ->setMsrpEnabled(1)//enable MAP
                    ->setData('metal_type', $metalType)
                    ->setMediaGallery(array('images' => array(), 'values' => array()))//media gallery initialization


 ->addImageToMediaGallery('media/lees_catalog/BSST1.jpg', array('image','thumbnail','small_image'), true, true);

//Above here

                            'use_config_manage_stock' => 0, //'Use config settings' checkbox
                            'manage_stock' => 0, //manage stock
                            'is_in_stock' => 1, //Stock Availability
                    ->setCategoryIds(array($category)); //assign product to categories

The issue arises when you try to save products with the same image, Magento goes and deletes the image then if the product is saved then it takes it away for both. I've tested this with one product it uploads the image fine, with multiple products with different images it uploads all the images and products fine. This problem only occurs when a product, doesn't matter if its simple or configurable shares the same image(file path). Is there any way to easily fix this?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.