php - Programmatically Update Image Labels -
i'm trying update product images' labels. want them same name of product.
what i've tried
$mediamodel = mage::getmodel("catalog/product_attribute_backend_media"); $images = $product->getmediagalleryimages(); foreach ($images $image) { $mediamodel->updateimage( $product->getid(), $image->getfile(), array("label" => $title) ); } but error
fatal error: call member function getattributecode() on non-object in app/code/core/mage/catalog/model/product/attribute/backend/media.php on line 401
i've tried
$mediamodel = mage::getmodel("catalog/product_attribute_media_api"); $images = $mediamodel->items($product->getid()); foreach ($images $image) { $mediamodel->update( $product->getid(), $image['file'], array("label" => $title) ); } which runs fine, values aren't updated in admin.
how go this?
$product = mage::getmodel('catalog/product')->loadbyattribute('sku','xxxxxxxxx'); $mediamodel = mage::getmodel("catalog/product_attribute_media_api"); $images = $mediamodel->items($product->getid()); foreach ($images $image) { $mediamodel->update( $product->getid(), $image['file'], array("label" => 'image label here') ); } $product->getresource()->saveattribute($product, 'media_gallery'); this code works me. clear cache before refresh backend
Comments
Post a Comment