You are here

function amazon_component_gallery_clean_xml in Amazon Product Advertisement API 7.2

Take the Amazon XML item and turn it into our own private 'cleaned' data structure.

Parameters

$xml: XML structure as returned from Amazon API call.

Return value

'Cleaned' XML structure for local use.

1 call to amazon_component_gallery_clean_xml()
_amazon_component_batch_lookup_from_web in amazon_component/amazon_component.module
Get 10 or less items from the AWS web service. AWS allows ONLY 10 items, See http://docs.amazonwebservices.com/AWSECommerceService/latest/DG/index.ht....

File

amazon_component/amazon_component.module, line 320

Code

function amazon_component_gallery_clean_xml($xml) {

  // Function Variables
  $item = array();
  $metadata = amazon_data_cache();
  $supported_sizes = preg_split('/,/', AMAZON_IMAGE_SIZES);

  // EXTRACT :: Amazon Product ASIN

  //$item['asin'] = (string)$xml->ASIN;

  // Extract :: Amazon Product ImageSetss
  // LOOP :: Each ImageSets
  // LOOP :: Each ImageSet
  // LOOP :: Each Image
  // $i = Number of image gallery sizes (small, medium,large, swatch, etc...)
  // $k = Number of images in each gallery size (primary, variant, variant, etc...)
  // Array :: Store indexed imagesets in $item array()
  if (isset($xml->ImageSets)) {
    $i = 0;
    foreach ((array) $xml->ImageSets as $ImageSetKey => $ImageSets) {
      foreach ((array) $ImageSets as $ImageSetKey => $ImageSet) {
        $i++;
        $k = 0;
        $ImageSet = (array) $ImageSet;
        foreach ($ImageSet as $imageSize => $imageData) {
          $k++;
          if (in_array($imageSize, $supported_sizes)) {
            $item['imagesets_gallery'][strtolower($imageSize)][$i] = array(
              'asin' => (string) $xml->ASIN,
              'url' => (string) $imageData->URL,
              'category' => (string) $ImageSet['@attributes']['Category'],
              'height' => intval($imageData->Height),
              'width' => intval($imageData->Width),
              'size' => (string) strtolower($imageSize),
              'image_order' => $i,
            );
          }
        }
      }
    }
  }
  return $item;
}