$product1 = Mage::getModel('catalog/product')->loadByAttribute('sku', 'FN244403');
$product2 = Mage::getModel('catalog/product')->loadByAttribute('sku', 'FN229437');
$product1ID = $product1->getId();
$connection = Mage::getSingleton('core/resource')->getConnection('core_read');
$sql = "SELECT * FROM `catalog_product_entity_media_gallery` WHERE `entity_id` = '$product1ID'
LIMIT 1";
$rows = $connection->fetchAll($sql);
echo $path = $rows[0]['value'];
echo "Edited sku is ".$product1->getSku()." ".$product1->getImage()." ".$product1-
>getThumbnail()." ".$product2->getImage();
echo " asdasd ".Mage::getBaseDir('media') . DS . 'catalog/product' .trim($rows[0]['value']);
Mage::app()->getStore()->setId(Mage_Core_Model_App::ADMIN_STORE_ID);
$product1->addImageToMediaGallery(Mage::getBaseDir('media') . DS . 'catalog/product' .trim
($rows[0]['value']), array('image', 'small_image', 'thumbnail'), false, false);
$product1->save();
我添加产品图片,如小图片,基本图片,缩略图。如何删除第二个丢失的图像,不选择小图像,基本图像,缩略图?谢谢!
答案 0 :(得分:1)
看看@ Magento programmatically remove product images
$collection = Mage::getModel('catalog/product')->getCollection();
foreach($collection as $product){
if ($product->getId()){
$mediaApi = Mage::getModel("catalog/product_attribute_media_api");
$items = $mediaApi->items($product->getId());
foreach($items as $item){
view elements of $item array
print_r($item);
if($item[] not check ){
$mediaApi->remove($product->getId(), $item['file']);
}
}
}
}