Example #1
0
 /**
  * Returns Google Base recommended Item Types
  *
  * @param string $targetCountry Two-letters country ISO code
  * @return array
  */
 public function getItemTypes($targetCountry)
 {
     $locale = Mage::getSingleton('googlebase/config')->getCountryInfo($targetCountry, 'locale');
     $location = self::ITEM_TYPES_LOCATION . '/' . $locale;
     $itemTypes = array();
     foreach ($this->getGuestService()->getFeed($location)->entries as $entry) {
         if (isset($entry->extensionElements[1])) {
             // has attributes node?
             $typeAttributes = $entry->extensionElements[1]->extensionElements;
             if (is_array($typeAttributes) && !empty($typeAttributes)) {
                 // only items with attributes allowed
                 $type = $entry->extensionElements[0]->text;
                 $item = new Varien_Object();
                 $item->setId($type);
                 $item->setName($entry->title->text);
                 $item->setLocation($entry->id->text);
                 $itemTypes[$type] = $item;
                 $attributes = array();
                 foreach ($typeAttributes as $attr) {
                     $name = $attr->extensionAttributes['name']['value'];
                     $type = $attr->extensionAttributes['type']['value'];
                     $attribute = new Varien_Object();
                     $attribute->setId($name);
                     $attribute->setName($name);
                     $attribute->setType($type);
                     $attributes[$name] = $attribute;
                 }
                 ksort($attributes);
                 $item->setAttributes($attributes);
             }
         }
     }
     ksort($itemTypes);
     $this->_itemTypes = $itemTypes;
     return $itemTypes;
 }