Mage_GoogleBase_Model_Service_Item Class Reference

Inheritance diagram for Mage_GoogleBase_Model_Service_Item:

Mage_GoogleBase_Model_Service Varien_Object

List of all members.

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


Detailed Description

Definition at line 34 of file Item.php.


Member Function Documentation

_checkItem (  )  [protected]

Check Item Instance

Returns:
void

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

Parameters:
string $attribute Google Base attribute name
Returns:
string|null Attribute value

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]

Return assign item type or default item type

Returns:
string Google Base Item Type

Definition at line 361 of file Item.php.

00362     {
00363         return $this->getItemType() ? $this->getItemType() : $this->getConfig()->getDefaultItemType($this->getStoreId());
00364     }

_normalizeString ( string  )  [protected]

Prepare Google Base attribute name before save

Parameters:
string Attribute name
Returns:
string Normalized 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

Returns:
Mage_GoogleBase_Model_Service_Item

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

Parameters:
boolean Save as draft or not
Returns:
Mage_GoogleBase_Model_Service_Item

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

Parameters:
string $attribute Google Base attribute name
string $value Google Base attribute value
string $type Google Base attribute type
Returns:
Mage_GoogleBase_Model_Service_Item

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

Parameters:
string $attribute Google Base attribute name
mixed $value Fload price value
string $type Google Base attribute type
Returns:
Mage_GoogleBase_Model_Service_Item

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

Returns:
Mage_GoogleBase_Model_Service_Item

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

Returns:
Mage_GoogleBase_Model_Service_Item

Definition at line 183 of file Item.php.

00184     {
00185         $this->_saveDraft(false);
00186         return $this;
00187     }

delete (  ) 

Delete Item from Google Base

Returns:
Zend_Gdata_Gbase_ItemFeed

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

Parameters:
string Google Base datetime
Returns:
int

Definition at line 400 of file Item.php.

00401     {
00402         return Mage::getSingleton('core/date')->date(null, $gBaseDate);
00403     }

getItem (  ) 

$_item Getter

Returns:
Mage_GoogleBase_Model_Item

Definition at line 92 of file Item.php.

00093     {
00094         return $this->_item;
00095     }

getObject (  ) 

$_object Getter

Returns:
Varien_Object

Definition at line 70 of file Item.php.

00071     {
00072         return $this->_object;
00073     }

getService ( storeId = null  ) 

Return Store level Service Instance

Returns:
Zend_Gdata_Gbase

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

Returns:
Mage_GoogleBase_Model_Service_Item

Definition at line 172 of file Item.php.

00173     {
00174         $this->_saveDraft(true);
00175         return $this;
00176     }

insert (  ) 

Insert Item into Google Base

Returns:
Zend_Gdata_Gbase_ItemEntry

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  ) 

$_item Setter

Parameters:
Mage_GoogleBase_Model_Item $item
Returns:
Mage_GoogleBase_Model_Service_Item

Definition at line 81 of file Item.php.

00082     {
00083         $this->_item = $item;
00084         return $this;
00085     }

setObject ( object  ) 

$_object Setter

Parameters:
Varien_Object $object
Returns:
Mage_GoogleBase_Model_Service_Item

Definition at line 59 of file Item.php.

00060     {
00061         $this->_object = $object;
00062         return $this;
00063     }

update (  ) 

Update Item data in Google Base

Returns:
Zend_Gdata_Gbase_ItemEntry

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     }


Member Data Documentation

$_item = null [protected]

Definition at line 51 of file Item.php.

$_object = null [protected]

Definition at line 44 of file Item.php.

Definition at line 37 of file Item.php.

const DEFAULT_ITEM_TYPE = 'products'

Definition at line 36 of file Item.php.


The documentation for this class was generated from the following file:

Generated on Sat Jul 4 17:24:15 2009 for Magento by  doxygen 1.5.8