3

I'm adding images to products using the addImageToMediaGallery() function like so:

Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);

$product = Mage::getModel('catalog/product')->load(1234);

try {
    $product->addImageToMediaGallery($filePath, ['small_image', 'thumbnail', 'image'], false, false);
    $product->save();
} catch(Exception $e) {
    echo $e->getMessage();
}

The images are uploaded to the gallery as intended but the media attributes (small_image, thumbnail, image) seem to be ignored and are not selected on the newly uploaded image.

What I expected

I'm running Magento CE 1.9.2.2

0

After experimenting some more I have found a solution.

These values didn't change because there were other storeviews that didn't have "Use default value" selected

settings

Your Answer

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

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