1

So I am constructing an import array with details and using AvS_FastSimpleImport to do the importing work. Here is the relevant code:

$fileName = Mage::getBaseDir()."/".Mage::getStoreConfig(C4B_XmlImport_Model_Catalog_Importer::XML_PATH_IMAGE_IMPORT_DIRECTORY).$imageName;
            if (file_exists($fileName)) {
                $addImage = $defaultImportEntry;
                $addImage['sku'] = '';
                $addImage['_media_image'] = $imageName;
                $addImage['_media_attribute_id'] = Mage::getSingleton('catalog/product')->getResource()->getAttribute('media_gallery')->getAttributeId();
                $addImage['_media_is_disabled'] = 0;
                $addImage['_media_position'] = $imgCounter;
                $addImage['_media_lable'] = $imageName;
                if(!$isAssociatedProduct && $currentNumber == 1) {
                    $addImage['image'] = $fileName;
                    $addImage['small_image'] = $fileName;
                    $addImage['thumbnail'] = $fileName;
                    }
            }

The second if statement is entered only for specific images (as you can see). On these images I want the radio buttons of Base Image, Small Image, and Thumbnail to be set, but apparently it doesn't work.

Here's a tutorial document I was reading: http://www.integer-net.de/download/ImportExport_EN.pdf

2 Answers 2

1

The value in image, small_image and thumbnail should be the same as in _media_image. You should use $imageName instead of $fileName there.

-1

you have to do only one think

Just Set the Store Id when you save your product.

foreach($image_array as $single_image) {
    $img_counter++;    
    if ($img_counter == 1) {
        $img_save_mode = array('image','small_image','thumbnail');
    } else {
        $img_save_mode = array();
    }    
    $upper_path = Mage::getBaseDir('media') . DS . 'import' . DS ;
    $filepath = $upper_path . $single_image;    
    if ( file_exists($filepath) ) {
    try {
        $product->addImageToMediaGallery($filepath, $img_save_mode , false , false);        
        $product->setStoreId(0);
    } catch (Exception $e) {
        echo $e->getMessage();
    }
    } else {
        echo "Product does not have an image or the path is incorrect. Path was: {$filepath}<br/>";
    }
    $product->save();
}
6
  • I work with SimpleXMLElement objects (i.e. my $product obj) so I cannot use addImagToMediaGallery().
    – Syspect
    Commented Feb 7, 2014 at 12:11
  • then just set store id in your product Object
    – Keyul Shah
    Commented Feb 7, 2014 at 12:13
  • Sorry, but I don't understand what role does the store id play here. Can you elaborate why I need it?
    – Syspect
    Commented Feb 7, 2014 at 12:19
  • stackoverflow.com/questions/9372969/… Refer this
    – Keyul Shah
    Commented Feb 7, 2014 at 12:21
  • This still does not help. I simply do not see the place to use the store id.
    – Syspect
    Commented Feb 10, 2014 at 8:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.