Try passing an array as the media type. Theer is no need to iterate over each mediaType and setting them individually.
your code would thus be, which will be faster as well.
ini_set('memory_limit', '-1');
require 'app/Mage.php';
Mage::app();
echo "Loading catalog...\n";
$products = Mage::getModel('catalog/product')->setStoreId(13)->getCollection()->addAttributeToSelect('*');
echo count($products) . " products selected for image import.\n";
// Remove unset images, add image to gallery if exists
$importDir = Mage::getBaseDir('media') . DS . 'import/';
foreach ($products as $product) {
$sku = Mage::getModel('catalog/product')->load($product->getId())->getSku();
if (strstr($sku, " ")) {
echo "Sku $sku contains whitespace, skipping.\n";
continue;
}
$imgFile = $importDir . $sku . ".jpg";
// Add three image sizes to media gallery
$mediaArray = array(
'thumbnail',
'small_image',
'image'
);
if (file_exists($imgFile)) {
try {
$product->addImageToMediaGallery($imgFile, $mediaArray, false, false);
$product->save();
echo "Sku: $sku updated.\n";
} catch (Exception $e) {
echo $e->getMessage();
}
} else {
echo "Could not match image to $sku. Path was: {$filePath}\n";
break;
}
}
Anyways, I suspect your issue is related to the fact that your product->save was within the media loop of your original code.
For reference, the end-point of the mediaAttribute is this function, located in class Mage_Catalog_Model_Product_Attribute_Backend_Media
/**
* Set media attribute value
*
* @param Mage_Catalog_Model_Product $product
* @param string|array $mediaAttribute
* @param string $value
* @return Mage_Catalog_Model_Product_Attribute_Backend_Media
*/
public function setMediaAttribute(Mage_Catalog_Model_Product $product, $mediaAttribute, $value)
{
$mediaAttributeCodes = array_keys($product->getMediaAttributes());
if (is_array($mediaAttribute)) {
foreach ($mediaAttribute as $atttribute) {
if (in_array($atttribute, $mediaAttributeCodes)) {
$product->setData($atttribute, $value);
}
}
} elseif (in_array($mediaAttribute, $mediaAttributeCodes)) {
$product->setData($mediaAttribute, $value);
}
return $this;
}
I think you'll need to disable the zoom and initialise it again on the active image.
You may need to change some of the selectors below.
Disable zoom
$('#image').removeData('elevateZoom');
$('.zoomWrapper img.zoomed').unwrap();
$('.zoomContainer').remove();
So it goes like this:
- On page load you initialise the zoom
- When the carousel changes slide you disable the zoom
- When the next slide loads you initialise zoom on the active image (or when the user taps on the zoom icon or however your zoom is initialised)
Best Answer
If I understand correctly you are using Magento DataFlow export which is quite outdated.
I suggest using Magento's ImportExport (System\ImportExport\Export). It exports all gallery images into a
_media_image
column.