Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Here is my method for a C# version for doing it using soap... You may be wondering how I got to this.. Read the whole post.</p> <pre><code>private void RemoveImagesFromProduct() { try { List&lt;catalogProductImageEntity&gt; imageList = this.mageObject.catalogProductAttributeMediaList(this.VendorProductId, null, "sku").ToList(); // execute the soap call to remove each one foreach (catalogProductImageEntity catProdImg in imageList) { this.mageObject.catalogProductAttributeMediaRemove(this.VendorProductId, catProdImg.file, "sku"); } } catch (Exception exception) { this.SetProgressErrUpdate("Remove Image Handler Error"); this.SetProgressErrUpdate(exception.Message); } } </code></pre> <p>After determining where the soap call points to, I find that these methods are used in Core Magento:</p> <p>(app/code/core/Mage/Catalog/Model/Product/Attribute/Media/Api.php)</p> <pre><code> public function items($productId, $store = null, $identifierType = null) { $product = $this-&gt;_initProduct($productId, $store, $identifierType); $gallery = $this-&gt;_getGalleryAttribute($product); $galleryData = $product-&gt;getData(self::ATTRIBUTE_CODE); if (!isset($galleryData['images']) || !is_array($galleryData['images'])) { return array(); } $result = array(); foreach ($galleryData['images'] as &amp;$image) { $result[] = $this-&gt;_imageToArray($image, $product); } return $result; } public function remove($productId, $file, $identifierType = null) { $product = $this-&gt;_initProduct($productId, null, $identifierType); $gallery = $this-&gt;_getGalleryAttribute($product); if (!$gallery-&gt;getBackend()-&gt;getImage($product, $file)) { $this-&gt;_fault('not_exists'); } $gallery-&gt;getBackend()-&gt;removeImage($product, $file); try { $product-&gt;save(); } catch (Mage_Core_Exception $e) { $this-&gt;_fault('not_removed', $e-&gt;getMessage()); } return true; } </code></pre> <p>At this point, I know everything that must be done to delete an image, only now a function that stands alone must be written.</p> <pre><code>// Set the product ID here, or load a collection and foreach it and use $product-&gt;getId() $prodId = 4967; // Reload here. Collections in magento are just unpredictable sometimes! $loadedProduct = Mage::getModel('catalog/product')-&gt;load($prodId); $attributes = $loadedProduct-&gt;getTypeInstance(true)-&gt;getSetAttributes($loadedProduct); if (isset($attributes['media_gallery'])) { // From this point forward, the gallery is represented by $attributes $gallery = $attributes['media_gallery']; $galleryData = $loadedProduct-&gt;getData('media_gallery'); if (!isset($galleryData['images']) || !is_array($galleryData['images'])) { die('no images for this product'); } $result = array(); foreach ($galleryData['images'] as &amp;$image) { $data = array( 'file' =&gt; $image['file'], 'label' =&gt; $image['label'], 'position' =&gt; $image['position'], 'exclude' =&gt; $image['disabled'], 'url' =&gt; Mage::getSingleton('catalog/product_media_config')-&gt;getMediaUrl($image['file']), 'types' =&gt; array() ); foreach ($loadedProduct-&gt;getMediaAttributes() as $attribute) { if ($loadedProduct-&gt;getData($attribute-&gt;getAttributeCode()) == $image['file']) { $data['types'][] = $attribute-&gt;getAttributeCode(); } } $result[] = $data; } // At this point all the media info will be displayed for the product // From this point forward you just need to call the same parts of the remove soap api call foreach ($result as $galleryResult) { // if the image exists, delete it. if($gallery-&gt;getBackend()-&gt;getImage($loadedProduct, $galleryResult['file'])) { $gallery-&gt;getBackend()-&gt;removeImage($loadedProduct, $galleryResult['file']); } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload