Mage_GoogleBase_Model_Item Class Reference

Inheritance diagram for Mage_GoogleBase_Model_Item:

Mage_Core_Model_Abstract Varien_Object

List of all members.

Public Member Functions

 getServiceItem ()
 getTargetCountry ()
 insertItem ()
 updateItem ()
 deleteItem ()
 hideItem ()
 activateItem ()
 loadByProduct ($product)
 setProduct ($product)

Public Attributes

const ATTRIBUTES_REGISTRY_KEY = 'gbase_attributes_registry'
const TYPES_REGISTRY_KEY = 'gbase_types_registry'

Protected Member Functions

 _construct ()
 _checkProduct ()
 _prepareProductObject ()
 _getAttributeValues ()
 _getAttributeLabel ($attribute, $storeId)
 _getTypeModel ()
 _getProductAttributes ()
 _getProductImages ()
 _getAttributesCollection ()


Detailed Description

Definition at line 34 of file Item.php.


Member Function Documentation

_checkProduct (  )  [protected]

Check product instance

Returns:
Mage_GoogleBase_Model_Item

Definition at line 182 of file Item.php.

00183     {
00184         if (!($this->getProduct() instanceof Mage_Catalog_Model_Product)) {
00185             Mage::throwException(Mage::helper('googlebase')->__('Invalid Product Model for Google Base Item'));
00186         }
00187         return $this;
00188     }

_construct (  )  [protected]

Enter description here...

Reimplemented from Varien_Object.

Definition at line 39 of file Item.php.

00040     {
00041         parent::_construct();
00042         $this->_init('googlebase/item');
00043     }

_getAttributeLabel ( attribute,
storeId 
) [protected]

Return Product Attribute Store Label

Parameters:
Mage_Catalog_Model_Resource_Eav_Attribute $attribute
int $storeId Store View Id
Returns:
string Attribute Store View Label or Attribute code

Definition at line 260 of file Item.php.

00261     {
00262         $frontendLabel = $attribute->getFrontend()->getLabel();
00263         if (is_array($frontendLabel)) {
00264             $frontendLabel = array_shift($frontendLabel);
00265         }
00266         if (!$this->_translations) {
00267             $this->_translations = Mage::getModel('core/translate_string')
00268                ->load(Mage_Catalog_Model_Entity_Attribute::MODULE_NAME.Mage_Core_Model_Translate::SCOPE_SEPARATOR.$frontendLabel)
00269                ->getStoreTranslations();
00270         }
00271         if (isset($this->_translations[$storeId])) {
00272             return $this->_translations[$storeId];
00273         } else {
00274             return $attribute->getAttributeCode();
00275         }
00276     }

_getAttributesCollection (  )  [protected]

Return attribute collection for current Product Attribute Set

Returns:
Mage_GoogleBase_Model_Mysql4_Attribute_Collection

Definition at line 345 of file Item.php.

00346     {
00347         $registry = Mage::registry(self::ATTRIBUTES_REGISTRY_KEY);
00348         $attributeSetId = $this->getProduct()->getAttributeSetId();
00349         if (is_array($registry) && isset($registry[$attributeSetId])) {
00350             return $registry[$attributeSetId];
00351         }
00352         $collection = Mage::getResourceModel('googlebase/attribute_collection')
00353             ->addAttributeSetFilter($attributeSetId, $this->getTargetCountry())
00354             ->load();
00355         $registry[$attributeSetId] = $collection;
00356         Mage::unregister(self::ATTRIBUTES_REGISTRY_KEY);
00357         Mage::register(self::ATTRIBUTES_REGISTRY_KEY, $registry);
00358         return $collection;
00359     }

_getAttributeValues (  )  [protected]

Return Product attribute values array

Returns:
array Product attribute values

Definition at line 221 of file Item.php.

00222     {
00223         $result = array();
00224         $productAttributes = $this->_getProductAttributes();
00225 
00226         foreach ($this->_getAttributesCollection() as $attribute) {
00227 
00228             $attributeId = $attribute->getAttributeId();
00229 
00230             if (isset($productAttributes[$attributeId])) {
00231                 $productAttribute = $productAttributes[$attributeId];
00232 
00233                 if ($attribute->getGbaseAttribute()) {
00234                     $name = $attribute->getGbaseAttribute();
00235                 } else {
00236                     $name = $this->_getAttributeLabel($productAttribute, $this->getProduct()->getStoreId());
00237                 }
00238 
00239                 $value = $productAttribute->getGbaseValue();
00240                 $type = Mage::getSingleton('googlebase/attribute')->getGbaseAttributeType($productAttribute);
00241 
00242                 if ($name && $value && $type) {
00243                     $result[$name] = array(
00244                         'value'     => $value,
00245                         'type'      => $type
00246                     );
00247                 }
00248             }
00249         }
00250         return $result;
00251     }

_getProductAttributes (  )  [protected]

Return Product attributes array

Returns:
array Product attributes

Definition at line 302 of file Item.php.

00303     {
00304         $product = $this->getProduct();
00305         $attributes = $product->getAttributes();
00306         $result = array();
00307         foreach ($attributes as $attribute) {
00308             $value = $attribute->getFrontend()->getValue($product);
00309             if (is_string($value) && strlen($value) && $product->hasData($attribute->getAttributeCode())) {
00310                 $attribute->setGbaseValue($value);
00311                 $result[$attribute->getAttributeId()] = $attribute;
00312             }
00313         }
00314         return $result;
00315     }

_getProductImages (  )  [protected]

Get Product Media files info

Returns:
array Media files info

Definition at line 322 of file Item.php.

00323     {
00324         $product = $this->getProduct();
00325         $galleryData = $product->getData('media_gallery');
00326 
00327         if (!isset($galleryData['images']) || !is_array($galleryData['images'])) {
00328             return array();
00329         }
00330 
00331         $result = array();
00332         foreach ($galleryData['images'] as $image) {
00333             $image['url'] = Mage::getSingleton('catalog/product_media_config')
00334                 ->getMediaUrl($image['file']);
00335             $result[] = $image;
00336         }
00337         return $result;
00338     }

_getTypeModel (  )  [protected]

Return Google Base Item Type Model for current Product Attribute Set

Returns:
Mage_GoogleBase_Model_Type

Definition at line 283 of file Item.php.

00284     {
00285         $registry = Mage::registry(self::TYPES_REGISTRY_KEY);
00286         $attributeSetId = $this->getProduct()->getAttributeSetId();
00287         if (is_array($registry) && isset($registry[$attributeSetId])) {
00288             return $registry[$attributeSetId];
00289         }
00290         $model = Mage::getModel('googlebase/type')->loadByAttributeSetId($attributeSetId, $this->getTargetCountry());
00291         $registry[$attributeSetId] = $model;
00292         Mage::unregister(self::TYPES_REGISTRY_KEY);
00293         Mage::register(self::TYPES_REGISTRY_KEY, $registry);
00294         return $model;
00295     }

_prepareProductObject (  )  [protected]

Copy Product object and assign additional data to the copy

Returns:
Mage_GoogleBase_Model_Item

Definition at line 195 of file Item.php.

00196     {
00197         $product = clone $this->getProduct();
00198         /* @var $product Mage_Catalog_Model_Product */
00199         $url = $product->getProductUrl(false);
00200         if (!Mage::getStoreConfigFlag('web/url/use_store')) {
00201             $urlInfo = parse_url($url);
00202             $store = $product->getStore()->getCode();
00203             if (isset($urlInfo['query']) && $urlInfo['query'] != '') {
00204                 $url .= '&___store=' . $store;
00205             } else {
00206                 $url .= '?___store=' . $store;
00207             }
00208         }
00209         $product->setUrl($url)
00210             ->setQuantity( $this->getProduct()->getStockItem()->getQty() )
00211             ->setImageUrl( Mage::helper('catalog/product')->getImageUrl($product) );
00212         $this->setProduct($product);
00213         return $this;
00214     }

activateItem (  ) 

Delete Item from Google Base

Returns:
Mage_GoogleBase_Model_Item

Definition at line 137 of file Item.php.

00138     {
00139         $this->getServiceItem()->setItem($this)->activate();
00140         $this->setIsHidden(0);
00141         $this->save();
00142         return $this;
00143     }

deleteItem (  ) 

Delete Item from Google Base

Returns:
Mage_GoogleBase_Model_Item

Definition at line 113 of file Item.php.

00114     {
00115         $this->getServiceItem()->setItem($this)->delete();
00116         return $this;
00117     }

getServiceItem (  ) 

Return Service Item Instance

Returns:
Mage_GoogleBase_Model_Service_Item

Definition at line 50 of file Item.php.

00051     {
00052         return Mage::getModel('googlebase/service_item')->setStoreId($this->getStoreId());
00053     }

getTargetCountry (  ) 

Target Country

Returns:
string Two-letters country ISO code

Definition at line 60 of file Item.php.

00061     {
00062         return Mage::getSingleton('googlebase/config')->getTargetCountry($this->getStoreId());
00063     }

hideItem (  ) 

Delete Item from Google Base

Returns:
Mage_GoogleBase_Model_Item

Definition at line 124 of file Item.php.

00125     {
00126         $this->getServiceItem()->setItem($this)->hide();
00127         $this->setIsHidden(1);
00128         $this->save();
00129         return $this;
00130     }

insertItem (  ) 

Save item to Google Base

Returns:
Mage_GoogleBase_Model_Item

Definition at line 70 of file Item.php.

00071     {
00072         $this->_checkProduct()
00073             ->_prepareProductObject();
00074 
00075         $typeModel = $this->_getTypeModel();
00076         $this->getServiceItem()
00077             ->setItem($this)
00078             ->setObject($this->getProduct())
00079             ->setAttributeValues($this->_getAttributeValues())
00080             ->setItemType($typeModel->getGbaseItemtype())
00081             ->insert();
00082         $this->setTypeId($typeModel->getTypeId());
00083         return $this;
00084     }

loadByProduct ( product  ) 

Load Item Model by Product

Parameters:
Mage_Catalog_Model_Product $product
Returns:
Mage_GoogleBase_Model_Item

Definition at line 151 of file Item.php.

00152     {
00153         if (!$this->getProduct()) {
00154             $this->setProduct($product);
00155         }
00156         $this->getResource()->loadByProduct($this);
00157         return $this;
00158     }

setProduct ( product  ) 

Product Setter

Parameters:
Mage_Catalog_Model_Product 
Returns:
Mage_GoogleBase_Model_Item

Definition at line 166 of file Item.php.

00167     {
00168         if (!($product instanceof Mage_Catalog_Model_Product)) {
00169             Mage::throwException(Mage::helper('googlebase')->__('Invalid Product Model for Google Base Item'));
00170         }
00171         $this->setData('product', $product);
00172         $this->setProductId($product->getId());
00173         $this->setStoreId($product->getStoreId());
00174         return $this;
00175     }

updateItem (  ) 

Update Item data

Returns:
Mage_GoogleBase_Model_Item

Definition at line 91 of file Item.php.

00092     {
00093         $this->_checkProduct()
00094             ->_prepareProductObject();
00095         $this->loadByProduct($this->getProduct());
00096         if ($this->getId()) {
00097             $typeModel = $this->_getTypeModel();
00098             $this->getServiceItem()
00099                 ->setItem($this)
00100                 ->setObject($this->getProduct())
00101                 ->setAttributeValues($this->_getAttributeValues())
00102                 ->setItemType($typeModel->getGbaseItemtype())
00103                 ->update();
00104         }
00105         return $this;
00106     }


Member Data Documentation

const ATTRIBUTES_REGISTRY_KEY = 'gbase_attributes_registry'

Definition at line 36 of file Item.php.

const TYPES_REGISTRY_KEY = 'gbase_types_registry'

Definition at line 37 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