00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 class Mage_GoogleBase_Model_Service_Feed extends Mage_GoogleBase_Model_Service
00035 {
00036 const ITEM_TYPES_LOCATION = 'http://www.google.com/base/feeds/itemtypes';
00037 const ITEMS_LOCATION = 'http://www.google.com/base/feeds/items';
00038
00039
00040
00041
00042
00043
00044
00045
00046 public function getFeed($location = null, $storeId = null)
00047 {
00048 $query = new Zend_Gdata_Query($location);
00049 return $this->getService($storeId)->getFeed($query);
00050 }
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061 public function getItemStats($id, $storeId = null)
00062 {
00063 if (!stristr($id, 'http://')) {
00064 $id = self::ITEMS_LOCATION . '/' . $id;
00065 }
00066 try {
00067 $entry = $this->getService($storeId)->getGbaseItemEntry($id);
00068 return $this->_getEntryStats($entry);
00069 } catch (Exception $e) {
00070 return null;
00071 }
00072 }
00073
00074
00075
00076
00077
00078
00079
00080 protected function _getEntryStats($entry)
00081 {
00082 $result = array();
00083
00084 $draft = 'no';
00085 if (is_object($entry->getControl()) && is_object($entry->getControl()->getDraft())) {
00086 $draft = $entry->getControl()->getDraft()->getText();
00087 }
00088 $result['draft'] = ($draft == 'yes' ? 1 : 0);
00089
00090 $expirationDate = $entry->getGbaseAttribute('expiration_date');
00091 if (isset($expirationDate[0]) && is_object($expirationDate[0])) {
00092 $result['expires'] = Mage::getSingleton('googlebase/service_item')->gBaseDate2DateTime($expirationDate[0]->getText());
00093 }
00094
00095 return $result;
00096 }
00097
00098
00099
00100
00101
00102
00103
00104 public function getItemTypes($targetCountry)
00105 {
00106 $locale = Mage::getSingleton('googlebase/config')->getCountryInfo($targetCountry, 'locale');
00107 $location = self::ITEM_TYPES_LOCATION . '/' . $locale;
00108
00109 $feed = $this->getGuestService()->getFeed($location);
00110
00111 $itemTypes = array();
00112 foreach ($feed->entries as $entry) {
00113 $type = $entry->extensionElements[0]->text;
00114 $item = new Varien_Object();
00115 $item->setId($type);
00116 $item->setName($entry->title->text);
00117 $item->setLocation($entry->id->text);
00118 $itemTypes[$type] = $item;
00119
00120 $typeAttributes = $entry->extensionElements[1]->extensionElements;
00121 $attributes = array();
00122 if (is_array($typeAttributes)) {
00123 foreach($typeAttributes as $attr) {
00124 $name = $attr->extensionAttributes['name']['value'];
00125 $type = $attr->extensionAttributes['type']['value'];
00126 $attribute = new Varien_Object();
00127 $attribute->setId($name);
00128 $attribute->setName($name);
00129 $attribute->setType($type);
00130 $attributes[$name] = $attribute;
00131 }
00132 }
00133 ksort($attributes);
00134 $item->setAttributes($attributes);
00135 }
00136 ksort($itemTypes);
00137 $this->_itemTypes = $itemTypes;
00138 return $itemTypes;
00139 }
00140
00141
00142
00143
00144
00145
00146
00147
00148 public function getAttributes($type, $targetCountry)
00149 {
00150 $itemTypes = $this->getItemTypes($targetCountry);
00151 if (isset($itemTypes[$type]) && $itemTypes[$type] instanceof Varien_Object) {
00152 return $itemTypes[$type]->getAttributes();
00153 }
00154 return array();
00155 }
00156 }