Your shopping cart is empty. Browse our Store

Magento

Open Source eCommerce Evolved

Product Images API

Last modified by Michael on Fri, July 4, 2008 13:32
Source|Old Revisions  

Allows to work with product images’ gallery

Module: Mage_Catalog

Resource: catalog_product_attribute_media

Aliases:

  • product_attribute_media
  • product_media

Methods

catalog_product_attribute_media.currentStore

Set/Get current store view

Return: int

Arguments:

  • mixed storeView - store view code or ID (optional)

Aliases:

  • product_attribute_media.currentStore
  • product_media.currentStore

catalog_product_attribute_media.list

Retrieve product image list

Return: array

Arguments:

  • mixed product - product ID or Sku
  • mixed storeView - store view ID or code (optional)

Aliases:

  • product_attribute_media.list
  • product_media.list

catalog_product_attribute_media.info

Retrieve product image data

Return: array

Arguments:

  • mixed product - product ID or Sku
  • string file - image file name
  • mixed storeView - store view ID or code (optional)

Aliases:

  • product_attribute_media.info
  • product_media.info

catalog_product_attribute_media.types

Retrieve product image types (image, small_image, thumbnail, etc...)

Return: array

Arguments:

  • int setId - product attribute set ID

Aliases:

  • product_attribute_media.types
  • product_media.types

catalog_product_attribute_media.create

Upload new product image

Return: string - image file name

Arguments:

  • mixed product - product ID or code
  • array data - image data. requires file content in base64, and image mime-type. \ Example: array(’file’ ⇒ array(’content’ ⇒ base64_encode($file), ‘mime’ ⇒ ‘type/jpeg’)
  • mixed storeView - store view ID or code (optional)

Aliases:

  • product_attribute_media.create
  • product_media.create

catalog_product_attribute_media.update

Update product image

Return: boolean

Arguments:

  • mixed product - product ID or code
  • string file - image file name
  • array data - image data (label, position, exclude, types)
  • mixed storeView - store view ID or code (optional)

Aliases:

  • product_attribute_media.update
  • product_media.update

catalog_product_attribute_media.remove

Remove product image

Return: boolean

Arguments:

  • mixed product - product ID or Sku
  • string file - image file name

Aliases:

  • product_attribute_media.remove
  • product_media.remove

Faults

Fault Code Fault Message
100 Requested store view not found.
101 Product not exists.
102 Invalid data given. Details in error message.
103 Requested image not exists in product images’ gallery.
104 Image creation failed. Details in error message.
105 Image not updated. Details in error message.
106 Image not removed. Details in error message.
107 Requested product doesn’t support images

Examples

Example 1. Working with product images

  1. $proxy = new SoapClient('http://magentohost/api/soap/?wsdl');
  2. $sessionId = $proxy->login('apiUser', 'apiKey');
  3.  
  4. $newImage = array(
  5.     'file' => array(
  6.         'content' => base64_encode(file_get_contents('product.jpg')),
  7.         'mime'    => 'image/jpeg'
  8.     ),
  9.     'label'    => 'Cool Image Througth Soap',
  10.     'position' => 2,
  11.     'types'    => array('small_image'),
  12.     'exclude'  => 0
  13. );
  14.  
  15. $imageFilename = $proxy->call($sessionId, 'product_media.create', array('Sku', $newImage));
  16.  
  17.  
  18. var_dump($imageFilename);
  19.  
  20. // Newly created image file
  21. var_dump($proxy->call($sessionId, 'product_media.list', 'Sku'));
  22.  
  23. $proxy->call($sessionId, 'product_media.update', array(
  24.     'Sku',
  25.     $imageFilename,
  26.     array('position' => 2, 'types' => array('image') /* Lets do it main image for product */)
  27. ));
  28.  
  29. // Updated image file
  30. var_dump($proxy->call($sessionId, 'product_media.list', 'Sku'));
  31.  
  32. // Remove image file
  33. $proxy->call($sessionId, 'product_media.remove', array('Sku', $imageFilename));
  34.  
  35. // Images without our file
  36. var_dump($proxy->call($sessionId, 'product_media.list', 'Sku'));



 

Popular Wiki Tags  |  View all

 vtiger   CRM   video   upload   image   pdf   diagram   virtual product   schema   cms   default   aspiration hosting   attribute   product page   pages 

Professional Services from the Magento Team

Professional Installation from the Magento Team

Magento Job Board - Some sort of tag line goes here

Latest Posts| View all Jobs
Sales: Call 877.832.5289 (North America) 310.295.4144 (International) to request a call-back.
© Copyright 2008 Varien. Magento is a trademark of Irubin Consulting Inc. DBA Varien
Privacy Policy|Terms of Service
Magento Community Count
30665 users|497 users currently online|69190 forum posts