Public Member Functions | |
setObject ($object) | |
getObject () | |
setItem ($item) | |
getItem () | |
getService ($storeId=null) | |
insert () | |
update () | |
delete () | |
hide () | |
activate () | |
gBaseDate2DateTime ($gBaseDate) | |
Public Attributes | |
const | DEFAULT_ITEM_TYPE = 'products' |
const | DEFAULT_ATTRIBUTE_TYPE = 'text' |
Protected Member Functions | |
_saveDraft ($yes=true) | |
_prepareEnrtyForSave () | |
_setUniversalData () | |
_setAttribute ($attribute, $value, $type= 'text') | |
_setAttributePrice ($attribute, $value, $type= 'text') | |
_getAttributeValue ($attribute) | |
_getItemType () | |
_checkItem () | |
_normalizeString ($string) | |
Protected Attributes | |
$_object = null | |
$_item = null |
Definition at line 34 of file Item.php.
_checkItem | ( | ) | [protected] |
Check Item Instance
Definition at line 371 of file Item.php.
00372 { 00373 if (!($this->getItem() instanceof Mage_GoogleBase_Model_Item)) { 00374 Mage::throwException(Mage::helper('googlebase')->__('Item model is not specified to delete Google Base entry')); 00375 } 00376 }
_getAttributeValue | ( | $ | attribute | ) | [protected] |
Return Google Base Item Attribute Value
string | $attribute Google Base attribute name |
Definition at line 346 of file Item.php.
00347 { 00348 $entry = $this->getEntry(); 00349 $attributeArr = $entry->getGbaseAttribute($attribute); 00350 if (is_array($attributeArr) && is_object($attributeArr[0])) { 00351 return $attributeArr[0]->getText(); 00352 } 00353 return null; 00354 }
_getItemType | ( | ) | [protected] |
_normalizeString | ( | $ | string | ) | [protected] |
Prepare Google Base attribute name before save
string | Attribute name |
Definition at line 384 of file Item.php.
00385 { 00386 return preg_replace('/\s+/', '_', $string); 00387 00388 // $string = preg_replace('/([^a-z^0-9^_])+/','_',strtolower($string)); 00389 // $string = preg_replace('/_{2,}/','_',$string); 00390 // return trim($string,'_'); 00391 }
_prepareEnrtyForSave | ( | ) | [protected] |
Prepare Entry data and attributes before saving in Google Base
Definition at line 216 of file Item.php.
00217 { 00218 $object = $this->getObject(); 00219 if (!($object instanceof Varien_Object)) { 00220 Mage::throwException(Mage::helper('googlebase')->__('Object model is not specified to save Google Base entry')); 00221 } 00222 00223 $this->_setUniversalData(); 00224 00225 $attributes = $this->getAttributeValues(); 00226 if (is_array($attributes) && count($attributes)) { 00227 foreach ($attributes as $name => $data) { 00228 00229 $name = $this->_normalizeString($name); 00230 $value = isset($data['value']) ? $data['value'] : ''; 00231 $type = isset($data['type']) && $data['type'] ? $data['type'] : self::DEFAULT_ATTRIBUTE_TYPE; 00232 00233 $customSetter = '_setAttribute' . ucfirst($name); 00234 if (method_exists($this, $customSetter)) { 00235 $this->$customSetter($name, $value, $type); 00236 } else { 00237 $this->_setAttribute($name, $value, $type); 00238 } 00239 } 00240 } 00241 return $this; 00242 }
_saveDraft | ( | $ | yes = true |
) | [protected] |
Update item Control property
boolean | Save as draft or not |
Definition at line 195 of file Item.php.
00196 { 00197 $this->_checkItem(); 00198 00199 $service = $this->getService(); 00200 $entry = $service->getGbaseItemEntry( $this->getItem()->getGbaseItemId() ); 00201 00202 $draftText = $yes ? 'yes' : 'no'; 00203 $draft = $service->newDraft($draftText); 00204 $control = $service->newControl($draft); 00205 00206 $entry->setControl($control); 00207 $entry->save(); 00208 return $this; 00209 }
_setAttribute | ( | $ | attribute, | |
$ | value, | |||
$ | type = 'text' | |||
) | [protected] |
Set Google Base Item Attribute
string | $attribute Google Base attribute name | |
string | $value Google Base attribute value | |
string | $type Google Base attribute type |
Definition at line 309 of file Item.php.
00310 { 00311 $entry = $this->getEntry(); 00312 $gBaseAttribute = $entry->getGbaseAttribute($attribute); 00313 if (isset($gBaseAttribute[0]) && is_object($gBaseAttribute[0])) { 00314 $gBaseAttribute[0]->text = $value; 00315 } else { 00316 $entry->addGbaseAttribute($attribute, $value, $type); 00317 } 00318 return $this; 00319 }
_setAttributePrice | ( | $ | attribute, | |
$ | value, | |||
$ | type = 'text' | |||
) | [protected] |
Custom setter for 'price' attribute
string | $attribute Google Base attribute name | |
mixed | $value Fload price value | |
string | $type Google Base attribute type |
Definition at line 330 of file Item.php.
00331 { 00332 $targetCountry = $this->getConfig()->getTargetCountry($this->getStoreId()); 00333 $this->_setAttribute( 00334 $this->getConfig()->getCountryInfo($targetCountry, 'price_attribute_name', $this->getStoreId()), 00335 sprintf('%.2f', $value), 00336 'floatUnit' 00337 ); 00338 }
_setUniversalData | ( | ) | [protected] |
Assign values to universal attribute of entry
Definition at line 249 of file Item.php.
00250 { 00251 $service = $this->getService(); 00252 $object = $this->getObject(); 00253 $entry = $this->getEntry(); 00254 00255 $this->_setAttribute('id', $object->getId() . '_' . $this->getStoreId(), 'text'); 00256 00257 if ($object->getName()) { 00258 $title = $service->newTitle()->setText( $object->getName() ); 00259 $entry->setTitle($title); 00260 } 00261 00262 if ($object->getUrl()) { 00263 $links = $entry->getLink(); 00264 if (!is_array($links)) { 00265 $links = array(); 00266 } 00267 $link = $service->newLink(); 00268 $link->setHref($object->getUrl()); 00269 $link->setRel('alternate'); 00270 $link->setType('text/html'); 00271 if ($object->getName()) { 00272 $link->setTitle($object->getName()); 00273 } 00274 $links[0] = $link; 00275 $entry->setLink($links); 00276 } 00277 00278 if ($object->getDescription()) { 00279 $content = $service->newContent()->setText( $object->getDescription() ); 00280 $entry->setContent($content); 00281 } 00282 00283 if ($object->getQuantity()) { 00284 $quantity = $object->getQuantity() ? max(1, (int)$object->getQuantity()) : 1; 00285 $this->_setAttribute('quantity', $quantity, 'int'); 00286 } 00287 00288 $targetCountry = $this->getConfig()->getTargetCountry($this->getStoreId()); 00289 00290 if ($object->getData('image_url')) { 00291 $this->_setAttribute('image_link', $object->getData('image_url'), 'url'); 00292 } 00293 00294 $this->_setAttribute('target_country', $targetCountry, 'text'); 00295 $this->_setAttribute('item_language', $this->getConfig()->getCountryInfo($targetCountry, 'language'), 'text'); 00296 00297 return $this; 00298 }
activate | ( | ) |
Publish item in Google Base
Definition at line 183 of file Item.php.
00184 { 00185 $this->_saveDraft(false); 00186 return $this; 00187 }
delete | ( | ) |
Delete Item from Google Base
Definition at line 158 of file Item.php.
00159 { 00160 $this->_checkItem(); 00161 00162 $service = $this->getService(); 00163 $entry = $service->getGbaseItemEntry( $this->getItem()->getGbaseItemId() ); 00164 return $service->deleteGbaseItem($entry, $this->getDryRun()); 00165 }
gBaseDate2DateTime | ( | $ | gBaseDate | ) |
Convert Google Base date format to unix timestamp Ex. 2008-12-08T16:57:23Z -> 2008-12-08 16:57:23
string | Google Base datetime |
Definition at line 400 of file Item.php.
00401 { 00402 return Mage::getSingleton('core/date')->date(null, $gBaseDate); 00403 }
getItem | ( | ) |
getObject | ( | ) |
getService | ( | $ | storeId = null |
) |
Return Store level Service Instance
Reimplemented from Mage_GoogleBase_Model_Service.
Definition at line 102 of file Item.php.
00103 { 00104 if ($storeId === null) { 00105 $storeId = $this->getStoreId(); 00106 } 00107 return parent::getService($storeId); 00108 }
hide | ( | ) |
Hide item in Google Base
Definition at line 172 of file Item.php.
00173 { 00174 $this->_saveDraft(true); 00175 return $this; 00176 }
insert | ( | ) |
Insert Item into Google Base
Definition at line 115 of file Item.php.
00116 { 00117 $this->_checkItem(); 00118 $service = $this->getService(); 00119 $entry = $service->newItemEntry(); 00120 $this->setEntry($entry); 00121 $this->_prepareEnrtyForSave(); 00122 $this->getEntry()->setItemType($this->_getItemType()); 00123 $entry = $service->insertGbaseItem($this->getEntry()); 00124 $this->setEntry($entry); 00125 $entryId = $this->getEntry()->getId(); 00126 $published = $this->gBaseDate2DateTime($this->getEntry()->getPublished()->getText()); 00127 $this->getItem() 00128 ->setGbaseItemId($entryId) 00129 ->setPublished($published); 00130 00131 if ($expires = $this->_getAttributeValue('expiration_date')) { 00132 $expires = $this->gBaseDate2DateTime($expires); 00133 $this->getItem()->setExpires($expires); 00134 } 00135 }
setItem | ( | $ | item | ) |
setObject | ( | $ | object | ) |
update | ( | ) |
Update Item data in Google Base
Definition at line 142 of file Item.php.
00143 { 00144 $this->_checkItem(); 00145 $service = $this->getService(); 00146 $entry = $service->getGbaseItemEntry( $this->getItem()->getGbaseItemId() ); 00147 $this->setEntry($entry); 00148 $this->_prepareEnrtyForSave(); 00149 $entry = $service->updateGbaseItem($this->getEntry()); 00150 00151 }
const DEFAULT_ATTRIBUTE_TYPE = 'text' |
const DEFAULT_ITEM_TYPE = 'products' |