I\'m having a problem with a third-party ioncube loader encoded feedloader plugin which is no longer supported by the original
In my problem i have set the images for the enabled grouped product. I have set the last image as the base,small and thumbnail image.
$collection = Mage::getModel('catalog/product')
->getCollection()
->addAttributeToFilter("type_id",array("eq","grouped"))
->addAttributeToFilter("status",array("eq","1"));
foreach($collection as $tmpProduct) {
$sku = $tmpProduct->getSku();
$product = Mage::getModel('catalog/product')
->loadByAttribute("sku",$sku);
$_images = Mage::getModel('catalog/product')
->load($product->getId())
->getMediaGalleryImages();
$checkImage = Mage::getBaseDir('media').DS.'catalog'.DS.'product'.DS.$product->getImage();
if( $product->getImage()!='' && is_file($checkImage)) {
continue; // do nothing
} else {
if($_images) {
$baseImage = '';
foreach($_images as $_image) {
$baseImage = $_image->getFile();
}
$groupedImagePath = Mage::getBaseDir('media').DS.'catalog'.DS.'product'.DS.$baseImage;
$product->setMediaGallery(
array('images'=>array (),
'values'=>array ()));
$product->addImageToMediaGallery(
$groupedImagePath,
array('image', 'thumbnail', 'small_image'),
false,
false);
Mage::getModel('catalog/product_attribute_media_api')
->remove($product->getId(),$baseImage);
$product->save();
echo "
$sku has selected image
";
} } }