Mage_Catalog_Model_Product Class Reference

Inheritance diagram for Mage_Catalog_Model_Product:

Mage_Catalog_Model_Abstract Mage_Core_Model_Abstract Varien_Object

List of all members.

Public Member Functions

 getStoreId ()
 getResourceCollection ()
 getUrlModel ()
 validate ()
 getName ()
 getPrice ()
 getTypeId ()
 getStatus ()
 getTypeInstance ($singleton=false)
 setTypeInstance ($instance, $singleton=false)
 getLinkInstance ()
 getIdBySku ($sku)
 getCategoryId ()
 getCategory ()
 setCategoryIds ($ids)
 getCategoryIds ()
 getCategoryCollection ()
 getWebsiteIds ()
 getStoreIds ()
 getAttributes ($groupId=null, $skipSuper=false)
 canAffectOptions ($value=null)
 cleanCache ()
 getPriceModel ()
 getTierPrice ($qty=null)
 getTierPriceCount ()
 getFormatedTierPrice ($qty=null)
 getFormatedPrice ()
 getFinalPrice ($qty=null)
 getCalculatedFinalPrice ()
 getMinimalPrice ()
 getSpecialPrice ()
 getSpecialFromDate ()
 getSpecialToDate ()
 getRelatedProducts ()
 getRelatedProductIds ()
 getRelatedProductCollection ()
 getRelatedLinkCollection ()
 getUpSellProducts ()
 getUpSellProductIds ()
 getUpSellProductCollection ()
 getUpSellLinkCollection ()
 getCrossSellProducts ()
 getCrossSellProductIds ()
 getCrossSellProductCollection ()
 getCrossSellLinkCollection ()
 getGroupedLinkCollection ()
 getMediaAttributes ()
 getMediaGalleryImages ()
 addImageToMediaGallery ($file, $mediaAttribute=null, $move=false, $exclude=true)
 getMediaConfig ()
 duplicate ()
 isSuperGroup ()
 isSuperConfig ()
 isGrouped ()
 isConfigurable ()
 isSuper ()
 getVisibleInCatalogStatuses ()
 isVisibleInCatalog ()
 getVisibleInSiteVisibilities ()
 isVisibleInSiteVisibility ()
 isDuplicable ()
 setIsDuplicable ($value)
 isSalable ()
 isVirtual ()
 isSaleable ()
 isInStock ()
 getAttributeText ($attributeCode)
 getCustomDesignDate ()
 getProductUrl ($useSid=true)
 formatUrlKey ($str)
 getUrlPath ($category=null)
 addAttributeUpdate ($code, $value, $store)
 toArray (array $arrAttributes=array())
 fromArray ($data)
 loadParentProductIds ()
 delete ()
 getRequestPath ()
 getGiftMessageAvailable ()
 getRatingSummary ()
 isComposite ()
 getSku ()
 getWeight ()
 getOptionInstance ()
 getProductOptionsCollection ()
 addOption (Mage_Catalog_Model_Product_Option $option)
 getOptionById ($optionId)
 getOptions ()
 getIsVirtual ()
 addCustomOption ($code, $value, $product=null)
 setCustomOptions (array $options)
 getCustomOptions ()
 getCustomOption ($code)
 hasCustomOptions ()
 canBeShowInCategory ($categoryId)
 getAvailableInCategories ()
 getDefaultAttributeSetId ()
 getImageUrl ()
 getSmallImageUrl ($width=88, $height=77)
 getThumbnailUrl ($width=75, $height=75)
 getReservedAttributes ()
 isReservedAttribute ($attribute)
 setOrigData ($key=null, $data=null)
 reset ()

Public Attributes

const CACHE_TAG = 'catalog_product'

Protected Member Functions

 _construct ()
 _beforeSave ()
 _afterSave ()
 _beforeDelete ()
 _afterLoad ()
 _substractQtyFromQuotes ()

Protected Attributes

 $_cacheTag = 'catalog_product'
 $_eventPrefix = 'catalog_product'
 $_eventObject = 'product'
 $_canAffectOptions = false
 $_typeInstance = null
 $_typeInstanceSingleton = null
 $_linkInstance
 $_customOptions = array()
 $_urlModel = null
 $_errors = array()
 $_optionInstance
 $_options = array()
 $_reservedAttributes
 $_isDuplicable = true

Static Protected Attributes

static $_url
static $_urlRewrite


Detailed Description

Definition at line 34 of file Product.php.


Member Function Documentation

_afterLoad (  )  [protected]

Load product options if they exists

Returns:
Mage_Catalog_Model_Product

Load product options

Reimplemented from Mage_Core_Model_Abstract.

Definition at line 517 of file Product.php.

00518     {
00519         parent::_afterLoad();
00520         /**
00521          * Load product options
00522          */
00523         if ($this->getHasOptions()) {
00524             foreach ($this->getProductOptionsCollection() as $option) {
00525                 $option->setProduct($this);
00526                 $this->addOption($option);
00527             }
00528         }
00529         return $this;
00530     }

_afterSave (  )  [protected]

Saving product type related data

Returns:
Mage_Catalog_Model_Product

Product Options

Reimplemented from Mage_Core_Model_Abstract.

Definition at line 486 of file Product.php.

00487     {
00488         $this->getLinkInstance()->saveProductRelations($this);
00489         $this->getTypeInstance(true)->save($this);
00490 
00491         /**
00492          * Product Options
00493          */
00494         $this->getOptionInstance()->setProduct($this)
00495             ->saveOptions();
00496 
00497         parent::_afterSave();
00498     }

_beforeDelete (  )  [protected]

Clear chache related with product and protect delete from not admin

Returns:
Mage_Catalog_Model_Product

Reimplemented from Mage_Core_Model_Abstract.

Definition at line 505 of file Product.php.

00506     {
00507         $this->cleanCache();
00508         $this->_protectFromNonAdmin();
00509         return parent::_beforeDelete();
00510     }

_beforeSave (  )  [protected]

Check product options and type options and save them, too

$this->_canAffectOptions - set by type instance only $this->getCanSaveCustomOptions() - set either in controller when "Custom Options" ajax tab is loaded, or in type instance as well

Set true, if any Set false, ONLY if options have been affected by Options tab and Type instance tab

Reimplemented from Mage_Catalog_Model_Abstract.

Definition at line 411 of file Product.php.

00412     {
00413         $this->cleanCache();
00414         $this->setTypeHasOptions(false);
00415         $this->setTypeHasRequiredOptions(false);
00416 
00417         $this->getTypeInstance(true)->beforeSave($this);
00418 
00419         $hasOptions         = false;
00420         $hasRequiredOptions = false;
00421 
00422         /**
00423          * $this->_canAffectOptions - set by type instance only
00424          * $this->getCanSaveCustomOptions() - set either in controller when "Custom Options" ajax tab is loaded,
00425          * or in type instance as well
00426          */
00427         $this->canAffectOptions($this->_canAffectOptions && $this->getCanSaveCustomOptions());
00428         if ($this->getCanSaveCustomOptions()) {
00429             $options = $this->getProductOptions();
00430             if (is_array($options)) {
00431                 foreach ($this->getProductOptions() as $option) {
00432                     $this->getOptionInstance()->addOption($option);
00433                     if ((!isset($option['is_delete'])) || $option['is_delete'] != '1') {
00434                         $hasOptions = true;
00435                     }
00436                 }
00437                 foreach ($this->getOptionInstance()->getOptions() as $option) {
00438                         if ($option['is_require'] == '1') {
00439                             $hasRequiredOptions = true;
00440                         break;
00441                     }
00442                 }
00443             }
00444         }
00445 
00446         /**
00447          * Set true, if any
00448          * Set false, ONLY if options have been affected by Options tab and Type instance tab
00449          */
00450         if ($hasOptions || (bool)$this->getTypeHasOptions()) {
00451             $this->setHasOptions(true);
00452             if ($hasRequiredOptions || (bool)$this->getTypeHasRequiredOptions()) {
00453                 $this->setRequiredOptions(true);
00454             }
00455             elseif ($this->canAffectOptions()) {
00456                 $this->setRequiredOptions(false);
00457             }
00458         }
00459         elseif ($this->canAffectOptions()) {
00460             $this->setHasOptions(false);
00461             $this->setRequiredOptions(false);
00462         }
00463         parent::_beforeSave();
00464     }

_construct (  )  [protected]

Initialize resources

Reimplemented from Varien_Object.

Definition at line 99 of file Product.php.

00100     {
00101         $this->_init('catalog/product');
00102     }

_substractQtyFromQuotes (  )  [protected]

Deprecated:
See also:
Mage_Sales_Model_Observer.substractQtyFromQuotes()

Definition at line 1544 of file Product.php.

01545     {
01546         // kept for legacy purposes
01547     }

addAttributeUpdate ( code,
value,
store 
)

Definition at line 1188 of file Product.php.

01189     {
01190         $oldValue = $this->getData($code);
01191         $oldStore = $this->getStoreId();
01192 
01193         $this->setData($code, $value);
01194         $this->setStoreId($store);
01195         $this->getResource()->saveAttribute($this, $code);
01196 
01197         $this->setData($code, $oldValue);
01198         $this->setStoreId($oldStore);
01199     }

addCustomOption ( code,
value,
product = null 
)

Add custom option information to product

Parameters:
string $code
mixed $value
int $productId
Returns:
Mage_Catalog_Model_Product

Definition at line 1366 of file Product.php.

01367     {
01368         $product = $product ? $product : $this;
01369         $this->_customOptions[$code] = new Varien_Object(array(
01370             'product_id'=> $product->getId(),
01371             'product'   => $product,
01372             'code'      => $code,
01373             'value'     => $value,
01374         ));
01375         return $this;
01376     }

addImageToMediaGallery ( file,
mediaAttribute = null,
move = false,
exclude = true 
)

Add image to media gallery

Parameters:
string $file file path of image in file system
string|array $mediaAttribute code of attribute with type 'media_image', leave blank if image should be only in gallery
boolean $move if true, it will move source file
boolean $exclude mark image as disabled in product page view

Definition at line 891 of file Product.php.

00892     {
00893         $attributes = $this->getTypeInstance(true)->getSetAttributes($this);
00894         if (!isset($attributes['media_gallery'])) {
00895             return $this;
00896         }
00897         $mediaGalleryAttribute = $attributes['media_gallery'];
00898         /* @var $mediaGalleryAttribute Mage_Catalog_Model_Resource_Eav_Attribute */
00899         $mediaGalleryAttribute->getBackend()->addImage($this, $file, $mediaAttribute, $move, $exclude);
00900         return $this;
00901     }

addOption ( Mage_Catalog_Model_Product_Option option  ) 

Add option to array of product options

Parameters:
Mage_Catalog_Model_Product_Option $option
Returns:
Mage_Catalog_Model_Product

Definition at line 1317 of file Product.php.

01318     {
01319         $this->_options[$option->getId()] = $option;
01320         return $this;
01321     }

canAffectOptions ( value = null  ) 

Check/set if options can be affected when saving product If value specified, it will be set.

Parameters:
bool $value
Returns:
bool

Definition at line 473 of file Product.php.

00474     {
00475         if (null !== $value) {
00476             $this->_canAffectOptions = (bool)$value;
00477         }
00478         return $this->_canAffectOptions;
00479     }

canBeShowInCategory ( categoryId  ) 

Check availability display product in category

Parameters:
int $categoryId
Returns:
bool

Definition at line 1427 of file Product.php.

01428     {
01429         return $this->_getResource()->canBeShowInCategory($this, $categoryId);
01430     }

cleanCache (  ) 

Clear cache related with product id

Returns:
Mage_Catalog_Model_Product

Definition at line 537 of file Product.php.

00538     {
00539         Mage::app()->cleanCache('catalog_product_'.$this->getId());
00540         return $this;
00541     }

delete (  ) 

Delete object from database

Returns:
Mage_Core_Model_Abstract

Reimplemented from Mage_Core_Model_Abstract.

Definition at line 1229 of file Product.php.

01230     {
01231         parent::delete();
01232         Mage::dispatchEvent($this->_eventPrefix.'_delete_after_done', array($this->_eventObject=>$this));
01233         return $this;
01234     }

duplicate (  ) 

Create duplicate

Returns:
Mage_Catalog_Model_Product

Definition at line 918 of file Product.php.

00919     {
00920         $this->getWebsiteIds();
00921         $this->getCategoryIds();
00922 
00923         $newProduct = Mage::getModel('catalog/product')->setData($this->getData())
00924             ->setIsDuplicate(true)
00925             ->setOriginalId($this->getId())
00926             ->setSku(null)
00927             ->setStatus(Mage_Catalog_Model_Product_Status::STATUS_DISABLED)
00928             ->setCreatedAt(null)
00929             ->setUpdatedAt(null)
00930             ->setId(null)
00931             ->setStoreId(Mage::app()->getStore()->getId());
00932 
00933         Mage::dispatchEvent('catalog_model_product_duplicate', array('current_product'=>$this, 'new_product'=>$newProduct));
00934 
00935         /* @var $newProduct Mage_Catalog_Model_Product */
00936 
00937 //        $newOptionsArray = array();
00938 //        $newProduct->setCanSaveCustomOptions(true);
00939 //        foreach ($this->getOptions() as $_option) {
00940 //            /* @var $_option Mage_Catalog_Model_Product_Option */
00941 //            $newOptionsArray[] = $_option->prepareOptionForDuplicate();
00942 //        }
00943 //        $newProduct->setProductOptions($newOptionsArray);
00944 
00945         /* Prepare Related*/
00946         $data = array();
00947         $this->getLinkInstance()->useRelatedLinks();
00948         $attributes = array();
00949         foreach ($this->getLinkInstance()->getAttributes() as $_attribute) {
00950             if (isset($_attribute['code'])) {
00951                 $attributes[]=$_attribute['code'];
00952             }
00953         }
00954         foreach ($this->getRelatedLinkCollection() as $_link) {
00955             $data[$_link->getLinkedProductId()] = $_link->toArray($attributes);
00956         }
00957         $newProduct->setRelatedLinkData($data);
00958 
00959         /* Prepare UpSell*/
00960         $data = array();
00961         $this->getLinkInstance()->useUpSellLinks();
00962         $attributes = array();
00963         foreach ($this->getLinkInstance()->getAttributes() as $_attribute) {
00964             if (isset($_attribute['code'])) {
00965                 $attributes[]=$_attribute['code'];
00966             }
00967         }
00968         foreach ($this->getUpSellLinkCollection() as $_link) {
00969             $data[$_link->getLinkedProductId()] = $_link->toArray($attributes);
00970         }
00971         $newProduct->setUpSellLinkData($data);
00972 
00973         /* Prepare Cross Sell */
00974         $data = array();
00975         $this->getLinkInstance()->useCrossSellLinks();
00976         $attributes = array();
00977         foreach ($this->getLinkInstance()->getAttributes() as $_attribute) {
00978             if (isset($_attribute['code'])) {
00979                 $attributes[]=$_attribute['code'];
00980             }
00981         }
00982         foreach ($this->getCrossSellLinkCollection() as $_link) {
00983             $data[$_link->getLinkedProductId()] = $_link->toArray($attributes);
00984         }
00985         $newProduct->setCrossSellLinkData($data);
00986 
00987         /* Prepare Grouped */
00988         $data = array();
00989         $this->getLinkInstance()->useGroupedLinks();
00990         $attributes = array();
00991         foreach ($this->getLinkInstance()->getAttributes() as $_attribute) {
00992             if (isset($_attribute['code'])) {
00993                 $attributes[]=$_attribute['code'];
00994             }
00995         }
00996         foreach ($this->getGroupedLinkCollection() as $_link) {
00997             $data[$_link->getLinkedProductId()] = $_link->toArray($attributes);
00998         }
00999         $newProduct->setGroupedLinkData($data);
01000 
01001         $newProduct->save();
01002 
01003         $this->getOptionInstance()->duplicate($this->getId(), $newProduct->getId());
01004         $this->getResource()->duplicate($this->getId(), $newProduct->getId());
01005 
01006         // TODO - duplicate product on all stores of the websites it is associated with
01007         /*if ($storeIds = $this->getWebsiteIds()) {
01008             foreach ($storeIds as $storeId) {
01009                 $this->setStoreId($storeId)
01010                    ->load($this->getId());
01011 
01012                 $newProduct->setData($this->getData())
01013                     ->setSku(null)
01014                     ->setStatus(Mage_Catalog_Model_Product_Status::STATUS_DISABLED)
01015                     ->setId($newId)
01016                     ->save();
01017             }
01018         }*/
01019         return $newProduct;
01020     }

formatUrlKey ( str  ) 

Definition at line 1172 of file Product.php.

01173     {
01174         return $this->getUrlModel()->formatUrlKey($str);
01175     }

fromArray ( data  ) 

Definition at line 1211 of file Product.php.

01212     {
01213         if (isset($data['stock_item'])) {
01214             $stockItem = Mage::getModel('cataloginventory/stock_item')
01215                 ->setData($data['stock_item'])
01216                 ->setProduct($this);
01217             $this->setStockItem($stockItem);
01218             unset($data['stock_item']);
01219         }
01220         $this->setData($data);
01221         return $this;
01222     }

getAttributes ( groupId = null,
skipSuper = false 
)

Retrieve product attributes

if $groupId is null - retrieve all product attributes

Parameters:
int $groupId
Returns:
array

Definition at line 390 of file Product.php.

00391     {
00392         $productAttributes = $this->getTypeInstance(true)->getEditableAttributes($this);
00393         if ($groupId) {
00394             $attributes = array();
00395             foreach ($productAttributes as $attribute) {
00396                 if ($attribute->isInGroup($this->getAttributeSetId(), $groupId)) {
00397                     $attributes[] = $attribute;
00398                 }
00399             }
00400         }
00401         else {
00402             $attributes = $productAttributes;
00403         }
00404 
00405         return $attributes;
00406     }

getAttributeText ( attributeCode  ) 

Definition at line 1144 of file Product.php.

01145     {
01146         return $this->getResource()
01147             ->getAttribute($attributeCode)
01148                 ->getSource()
01149                     ->getOptionText($this->getData($attributeCode));
01150     }

getAvailableInCategories (  ) 

Definition at line 1433 of file Product.php.

01434     {
01435         $allCategories = array();
01436         if (is_null($this->getData('_available_in_categories'))) {
01437             $assigned = $this->getCategoryIds();
01438             foreach ($assigned as $one) {
01439                 $allCategories[] = $one;
01440                 $anchors = Mage::getModel('catalog/category')->load($one)->getAnchorsAbove();
01441                 foreach ($anchors as $anchor) {
01442                     $allCategories[] = $anchor;
01443                 }
01444             }
01445 
01446             $this->setData('_available_in_categories', $allCategories);
01447         }
01448         return $this->getData('_available_in_categories');
01449     }

getCalculatedFinalPrice (  ) 

Definition at line 610 of file Product.php.

00611     {
00612         return $this->_getData('calculated_final_price');
00613     }

getCategory (  ) 

Retrieve product category

Returns:
Mage_Catalog_Model_Category

Definition at line 281 of file Product.php.

00282     {
00283         $category = $this->getData('category');
00284         if (is_null($category) && $this->getCategoryId()) {
00285             $category = Mage::getModel('catalog/category')->load($this->getCategoryId());
00286             $this->setCategory($category);
00287         }
00288         return $category;
00289     }

getCategoryCollection (  ) 

Retrieve product categories

Returns:
Varien_Data_Collection

Definition at line 343 of file Product.php.

00344     {
00345         return $this->getResource()->getCategoryCollection($this);
00346     }

getCategoryId (  ) 

Retrieve product category id

Returns:
int

Definition at line 268 of file Product.php.

00269     {
00270         if ($category = Mage::registry('current_category')) {
00271             return $category->getId();
00272         }
00273         return false;
00274     }

getCategoryIds (  ) 

Definition at line 307 of file Product.php.

00308     {
00309         if ($this->hasData('category_ids')) {
00310             $ids = $this->_getData('category_ids');
00311             if (!is_array($ids)) {
00312                 $wasLocked = false;
00313                 if ($this->isLockedAttribute('category_ids')) {
00314                     $this->unlockAttribute('category_ids');
00315                     $wasLocked = true;
00316                 }
00317 
00318                 $ids = !empty($ids) ? explode(',', $ids) : array();
00319                 $this->setData('category_ids', $ids);
00320                 if ($wasLocked) {
00321                     $this->lockAttribute('category_ids');
00322                 }
00323             }
00324         } else {
00325             $wasLocked = false;
00326             if ($this->isLockedAttribute('category_ids')) {
00327                 $this->unlockAttribute('category_ids');
00328             }
00329             $ids = $this->_getResource()->getCategoryIds($this);
00330             $this->setData('category_ids', $ids);
00331             if ($wasLocked) {
00332                 $this->lockAttribute('category_ids');
00333             }
00334         }
00335         return $this->_getData('category_ids');
00336     }

getCrossSellLinkCollection (  ) 

Retrieve collection cross sell link

Definition at line 811 of file Product.php.

00812     {
00813         $collection = $this->getLinkInstance()->useCrossSellLinks()
00814             ->getLinkCollection();
00815         $collection->setProduct($this);
00816         $collection->addLinkTypeIdFilter();
00817         $collection->addProductIdFilter();
00818         $collection->joinAttributes();
00819         return $collection;
00820     }

getCrossSellProductCollection (  ) 

Retrieve collection cross sell product

Returns:
Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Link_Product_Collection

Definition at line 799 of file Product.php.

00800     {
00801         $collection = $this->getLinkInstance()->useCrossSellLinks()
00802             ->getProductCollection()
00803             ->setIsStrongMode();
00804         $collection->setProduct($this);
00805         return $collection;
00806     }

getCrossSellProductIds (  ) 

Retrieve cross sell products identifiers

Returns:
array

Definition at line 782 of file Product.php.

00783     {
00784         if (!$this->hasCrossSellProductIds()) {
00785             $ids = array();
00786             foreach ($this->getCrossSellProducts() as $product) {
00787                 $ids[] = $product->getId();
00788             }
00789             $this->setCrossSellProductIds($ids);
00790         }
00791         return $this->getData('cross_sell_product_ids');
00792     }

getCrossSellProducts (  ) 

Retrieve array of cross sell products

Returns:
array

Definition at line 765 of file Product.php.

00766     {
00767         if (!$this->hasCrossSellProducts()) {
00768             $products = array();
00769             foreach ($this->getCrossSellProductCollection() as $product) {
00770                 $products[] = $product;
00771             }
00772             $this->setCrossSellProducts($products);
00773         }
00774         return $this->getData('cross_sell_products');
00775     }

getCustomDesignDate (  ) 

Definition at line 1152 of file Product.php.

01153     {
01154         $result = array();
01155         $result['from'] = $this->getData('custom_design_from');
01156         $result['to'] = $this->getData('custom_design_to');
01157 
01158         return $result;
01159     }

getCustomOption ( code  ) 

Get product custom option info

Parameters:
string $code
Returns:
array

Definition at line 1399 of file Product.php.

01400     {
01401         if (isset($this->_customOptions[$code])) {
01402             return $this->_customOptions[$code];
01403         }
01404         return null;
01405     }

getCustomOptions (  ) 

Get all custom options of the product

Returns:
array

Definition at line 1388 of file Product.php.

01389     {
01390         return $this->_customOptions;
01391     }

getDefaultAttributeSetId (  ) 

Retrieve default attribute set id

Returns:
int

Definition at line 1457 of file Product.php.

01458     {
01459         return $this->getResource()->getEntityType()->getDefaultAttributeSetId();
01460     }

getFinalPrice ( qty = null  ) 

Get product final price

Parameters:
double $qty
Returns:
double

Definition at line 601 of file Product.php.

00602     {
00603         $price = $this->_getData('final_price');
00604         if ($price !== null) {
00605             return $price;
00606         }
00607         return $this->getPriceModel()->getFinalPrice($qty, $this);
00608     }

getFormatedPrice (  ) 

Get formated by currency product price

Returns:
array || double

Definition at line 590 of file Product.php.

00591     {
00592         return $this->getPriceModel()->getFormatedPrice($this);
00593     }

getFormatedTierPrice ( qty = null  ) 

Get formated by currency tier price

Parameters:
double $qty
Returns:
array || double

Definition at line 580 of file Product.php.

00581     {
00582         return $this->getPriceModel()->getFormatedTierPrice($qty, $this);
00583     }

getGiftMessageAvailable (  ) 

Custom function for other modules

Definition at line 1245 of file Product.php.

01246     {
01247         return $this->_getData('gift_message_available');
01248     }

getGroupedLinkCollection (  ) 

Retrieve collection grouped link

Definition at line 825 of file Product.php.

00826     {
00827         $collection = $this->getLinkInstance()->useGroupedLinks()
00828             ->getLinkCollection();
00829         $collection->setProduct($this);
00830         $collection->addLinkTypeIdFilter();
00831         $collection->addProductIdFilter();
00832         $collection->joinAttributes();
00833         return $collection;
00834     }

getIdBySku ( sku  ) 

Retrive product id by sku

Parameters:
string $sku
Returns:
integer

Definition at line 258 of file Product.php.

00259     {
00260         return $this->_getResource()->getIdBySku($sku);
00261     }

getImageUrl (  ) 

Deprecated since 1.1.5

Definition at line 1466 of file Product.php.

01467     {
01468         return (string)Mage::helper('catalog/image')->init($this, 'image')->resize(265);
01469     }

getIsVirtual (  ) 

Retrieve is a virtual product

Returns:
bool

Definition at line 1353 of file Product.php.

01354     {
01355         return $this->getTypeInstance(true)->isVirtual($this);
01356     }

getLinkInstance (  ) 

Retrieve link instance

Returns:
Mage_Catalog_Model_Product_Link

Definition at line 244 of file Product.php.

00245     {
00246         if (!$this->_linkInstance) {
00247             $this->_linkInstance = Mage::getSingleton('catalog/product_link');
00248         }
00249         return $this->_linkInstance;
00250     }

getMediaAttributes (  ) 

Retrive attributes for media gallery

Returns:
array

Definition at line 844 of file Product.php.

00845     {
00846         if (!$this->hasMediaAttributes()) {
00847             $mediaAttributes = array();
00848             foreach ($this->getAttributes() as $attribute) {
00849                 if($attribute->getFrontend()->getInputType() == 'media_image') {
00850                     $mediaAttributes[$attribute->getAttributeCode()] = $attribute;
00851                 }
00852             }
00853             $this->setMediaAttributes($mediaAttributes);
00854         }
00855         return $this->getData('media_attributes');
00856     }

getMediaConfig (  ) 

Retrive product media config

Returns:
Mage_Catalog_Model_Product_Media_Config

Definition at line 908 of file Product.php.

00909     {
00910         return Mage::getSingleton('catalog/product_media_config');
00911     }

getMediaGalleryImages (  ) 

Retrive media gallery images

Returns:
Varien_Data_Collection

Definition at line 863 of file Product.php.

00864     {
00865         if(!$this->hasData('media_gallery_images') && is_array($this->getMediaGallery('images'))) {
00866             $images = new Varien_Data_Collection();
00867             foreach ($this->getMediaGallery('images') as $image) {
00868                 if ($image['disabled']) {
00869                     continue;
00870                 }
00871                 $image['url'] = $this->getMediaConfig()->getMediaUrl($image['file']);
00872                 $image['id'] = isset($image['value_id']) ? $image['value_id'] : null;
00873                 $image['path'] = $this->getMediaConfig()->getMediaPath($image['file']);
00874                 $images->addItem(new Varien_Object($image));
00875             }
00876             $this->setData('media_gallery_images', $images);
00877         }
00878 
00879         return $this->getData('media_gallery_images');
00880     }

getMinimalPrice (  ) 

Definition at line 615 of file Product.php.

00616     {
00617         return $this->_getData('minimal_price');
00618     }

getName (  ) 

Get product name

Returns:
string

Definition at line 161 of file Product.php.

00162     {
00163         return $this->_getData('name');
00164     }

getOptionById ( optionId  ) 

Get option from options array of product by given option id

Parameters:
int $optionId
Returns:
Mage_Catalog_Model_Product_Option | null

Definition at line 1329 of file Product.php.

01330     {
01331         if (isset($this->_options[$optionId])) {
01332             return $this->_options[$optionId];
01333         }
01334 
01335         return null;
01336     }

getOptionInstance (  ) 

Retrieve option instance

Returns:
Mage_Catalog_Model_Product_Option

Definition at line 1290 of file Product.php.

01291     {
01292         if (!$this->_optionInstance) {
01293             $this->_optionInstance = Mage::getSingleton('catalog/product_option');
01294         }
01295         return $this->_optionInstance;
01296     }

getOptions (  ) 

Get all options of product

Returns:
array

Definition at line 1343 of file Product.php.

01344     {
01345         return $this->_options;
01346     }

getPrice (  ) 

Get product price throught type instance

Returns:
unknown

Definition at line 171 of file Product.php.

00172     {
00173         return $this->getPriceModel()->getPrice($this);
00174     }

getPriceModel (  ) 

Get product price model

Returns:
Mage_Catalog_Model_Product_Type_Price

Definition at line 548 of file Product.php.

00549     {
00550         return Mage::getSingleton('catalog/product_type')->priceFactory($this->getTypeId());
00551     }

getProductOptionsCollection (  ) 

Retrieve options collection of product

Returns:
Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Option_Collection

Definition at line 1303 of file Product.php.

01304     {
01305         $collection = $this->getOptionInstance()
01306             ->getProductOptionCollection($this);
01307 
01308         return $collection;
01309     }

getProductUrl ( useSid = true  ) 

Get product url

Parameters:
bool $useSid
Returns:
string

Definition at line 1167 of file Product.php.

01168     {
01169         return $this->getUrlModel()->getProductUrl($this, $useSid);
01170     }

getRatingSummary (  ) 

Definition at line 1250 of file Product.php.

01251     {
01252         return $this->_getData('rating_summary');
01253     }

getRelatedLinkCollection (  ) 

Retrieve collection related link

Definition at line 689 of file Product.php.

00690     {
00691         $collection = $this->getLinkInstance()->useRelatedLinks()
00692             ->getLinkCollection();
00693         $collection->setProduct($this);
00694         $collection->addLinkTypeIdFilter();
00695         $collection->addProductIdFilter();
00696         $collection->joinAttributes();
00697         return $collection;
00698     }

getRelatedProductCollection (  ) 

Retrieve collection related product

Definition at line 677 of file Product.php.

00678     {
00679         $collection = $this->getLinkInstance()->useRelatedLinks()
00680             ->getProductCollection()
00681             ->setIsStrongMode();
00682         $collection->setProduct($this);
00683         return $collection;
00684     }

getRelatedProductIds (  ) 

Retrieve related products identifiers

Returns:
array

Definition at line 662 of file Product.php.

00663     {
00664         if (!$this->hasRelatedProductIds()) {
00665             $ids = array();
00666             foreach ($this->getRelatedProducts() as $product) {
00667                 $ids[] = $product->getId();
00668             }
00669             $this->setRelatedProductIds($ids);
00670         }
00671         return $this->getData('related_product_ids');
00672     }

getRelatedProducts (  ) 

Retrieve array of related roducts

Returns:
array

Definition at line 644 of file Product.php.

00645     {
00646         if (!$this->hasRelatedProducts()) {
00647             $products = array();
00648             $collection = $this->getRelatedProductCollection();
00649             foreach ($collection as $product) {
00650                 $products[] = $product;
00651             }
00652             $this->setRelatedProducts($products);
00653         }
00654         return $this->getData('related_products');
00655     }

getRequestPath (  ) 

Definition at line 1236 of file Product.php.

01237     {
01238         return $this->_getData('request_path');
01239     }

getReservedAttributes (  ) 

Returns system reserved attribute codes

Returns:
array Reserved attribute names

Definition at line 1492 of file Product.php.

01493     {
01494         if ($this->_reservedAttributes === null) {
01495             $_reserved = array('position');
01496             $methods = get_class_methods(__CLASS__);
01497             foreach ($methods as $method) {
01498                 if (preg_match('/^get([A-Z]{1}.+)/', $method, $matches)) {
01499                     $method = $matches[1];
01500                     $tmp = strtolower(preg_replace('/(.)([A-Z])/', "$1_$2", $method));
01501                     $_reserved[] = $tmp;
01502                 }
01503             }
01504             $_allowed = array(
01505                 'type_id','calculated_final_price','request_path','rating_summary'
01506             );
01507             $this->_reservedAttributes = array_diff($_reserved, $_allowed);
01508         }
01509         return $this->_reservedAttributes;
01510     }

getResourceCollection (  ) 

Get collection instance

Returns:
object

Reimplemented from Mage_Catalog_Model_Abstract.

Definition at line 122 of file Product.php.

00123     {
00124         if (empty($this->_resourceCollectionName)) {
00125             Mage::throwException(Mage::helper('core')->__('Model collection resource name is not defined'));
00126         }
00127         $collection = Mage::getResourceModel($this->_resourceCollectionName);
00128         $collection->setStoreId($this->getStoreId());
00129         return $collection;
00130     }

getSku (  ) 

Retrieve sku through type instance

Returns:
string

Definition at line 1270 of file Product.php.

01271     {
01272         return $this->getTypeInstance(true)->getSku($this);
01273     }

getSmallImageUrl ( width = 88,
height = 77 
)

Deprecated since 1.1.5

Definition at line 1474 of file Product.php.

01475     {
01476         return (string)Mage::helper('catalog/image')->init($this, 'small_image')->resize($width, $height);
01477     }

getSpecialFromDate (  ) 

Definition at line 625 of file Product.php.

00626     {
00627         return $this->_getData('special_from_date');
00628     }

getSpecialPrice (  ) 

Definition at line 620 of file Product.php.

00621     {
00622         return $this->_getData('special_price');
00623     }

getSpecialToDate (  ) 

Definition at line 630 of file Product.php.

00631     {
00632         return $this->_getData('special_to_date');
00633     }

getStatus (  ) 

Get product status

Returns:
int

Definition at line 191 of file Product.php.

00192     {
00193         return $this->_getData('status');
00194     }

getStoreId (  ) 

Retrieve Store Id

Returns:
int

Definition at line 109 of file Product.php.

00110     {
00111         if ($this->hasData('store_id')) {
00112             return $this->getData('store_id');
00113         }
00114         return Mage::app()->getStore()->getId();
00115     }

getStoreIds (  ) 

Get all sore ids where product is presented

Returns:
array

Definition at line 367 of file Product.php.

00368     {
00369         if (!$this->hasStoreIds()) {
00370             $storeIds = array();
00371             if ($websiteIds = $this->getWebsiteIds()) {
00372                 foreach ($websiteIds as $websiteId) {
00373                     $websiteStores = Mage::app()->getWebsite($websiteId)->getStoreIds();
00374                     $storeIds = array_merge($storeIds, $websiteStores);
00375                 }
00376             }
00377             $this->setStoreIds($storeIds);
00378         }
00379         return $this->getData('store_ids');
00380     }

getThumbnailUrl ( width = 75,
height = 75 
)

Deprecated since 1.1.5

Definition at line 1482 of file Product.php.

01483     {
01484         return (string)Mage::helper('catalog/image')->init($this, 'thumbnail')->resize($width, $height);
01485     }

getTierPrice ( qty = null  ) 

Get product tier price by qty

Parameters:
double $qty
Returns:
double

Definition at line 559 of file Product.php.

00560     {
00561         return $this->getPriceModel()->getTierPrice($qty, $this);
00562     }

getTierPriceCount (  ) 

Count how many tier prices we have for the product

Returns:
int

Definition at line 569 of file Product.php.

00570     {
00571         return $this->getPriceModel()->getTierPriceCount($this);
00572     }

getTypeId (  ) 

Get product type identifier

Returns:
int

Definition at line 181 of file Product.php.

00182     {
00183         return $this->_getData('type_id');
00184     }

getTypeInstance ( singleton = false  ) 

Retrieve type instance

Type instance implement type depended logic

Parameters:
bool $singleton
Returns:
Mage_Catalog_Model_Product_Type_Abstract

Definition at line 204 of file Product.php.

00205     {
00206         if ($singleton === true) {
00207             if (is_null($this->_typeInstanceSingleton)) {
00208                 $this->_typeInstanceSingleton = Mage::getSingleton('catalog/product_type')
00209                     ->factory($this, true);
00210             }
00211             return $this->_typeInstanceSingleton;
00212         }
00213 
00214         if ($this->_typeInstance === null) {
00215             $this->_typeInstance = Mage::getSingleton('catalog/product_type')
00216                 ->factory($this);
00217         }
00218         return $this->_typeInstance;
00219     }

getUpSellLinkCollection (  ) 

Retrieve collection up sell link

Definition at line 749 of file Product.php.

00750     {
00751         $collection = $this->getLinkInstance()->useUpSellLinks()
00752             ->getLinkCollection();
00753         $collection->setProduct($this);
00754         $collection->addLinkTypeIdFilter();
00755         $collection->addProductIdFilter();
00756         $collection->joinAttributes();
00757         return $collection;
00758     }

getUpSellProductCollection (  ) 

Retrieve collection up sell product

Definition at line 737 of file Product.php.

00738     {
00739         $collection = $this->getLinkInstance()->useUpSellLinks()
00740             ->getProductCollection()
00741             ->setIsStrongMode();
00742         $collection->setProduct($this);
00743         return $collection;
00744     }

getUpSellProductIds (  ) 

Retrieve up sell products identifiers

Returns:
array

Definition at line 722 of file Product.php.

00723     {
00724         if (!$this->hasUpSellProductIds()) {
00725             $ids = array();
00726             foreach ($this->getUpSellProducts() as $product) {
00727                 $ids[] = $product->getId();
00728             }
00729             $this->setUpSellProductIds($ids);
00730         }
00731         return $this->getData('up_sell_product_ids');
00732     }

getUpSellProducts (  ) 

Retrieve array of up sell products

Returns:
array

Definition at line 705 of file Product.php.

00706     {
00707         if (!$this->hasUpSellProducts()) {
00708             $products = array();
00709             foreach ($this->getUpSellProductCollection() as $product) {
00710                 $products[] = $product;
00711             }
00712             $this->setUpSellProducts($products);
00713         }
00714         return $this->getData('up_sell_products');
00715     }

getUrlModel (  ) 

Get product url model

Returns:
Mage_Catalog_Model_Product_Url

Definition at line 137 of file Product.php.

00138     {
00139         if ($this->_urlModel === null) {
00140             $this->_urlModel = Mage::getSingleton('catalog/product_url');
00141         }
00142         return $this->_urlModel;
00143     }

getUrlPath ( category = null  ) 

Retrieve Product Url Path (include category)

Parameters:
Mage_Catalog_Model_Category $category
Returns:
string

Definition at line 1183 of file Product.php.

01184     {
01185         return $this->getUrlModel()->getUrlPath($this, $category);
01186     }

getVisibleInCatalogStatuses (  ) 

Definition at line 1056 of file Product.php.

01057     {
01058         return Mage::getSingleton('catalog/product_status')->getVisibleStatusIds();
01059     }

getVisibleInSiteVisibilities (  ) 

Definition at line 1066 of file Product.php.

01067     {
01068         return Mage::getSingleton('catalog/product_visibility')->getVisibleInSiteIds();
01069     }

getWebsiteIds (  ) 

Retrieve product websites identifiers

Returns:
array

Definition at line 353 of file Product.php.

00354     {
00355         if (!$this->hasWebsiteIds()) {
00356             $ids = $this->_getResource()->getWebsiteIds($this);
00357             $this->setWebsiteIds($ids);
00358         }
00359         return $this->getData('website_ids');
00360     }

getWeight (  ) 

Retrieve weight throught type instance

Returns:
unknown

Definition at line 1280 of file Product.php.

01281     {
01282         return $this->getTypeInstance(true)->getWeight($this);
01283     }

hasCustomOptions (  ) 

Checks if there custom option for this product

Returns:
bool

Definition at line 1412 of file Product.php.

01413     {
01414         if (count($this->_customOptions)) {
01415             return true;
01416         } else {
01417             return false;
01418         }
01419     }

isComposite (  ) 

Check is product composite

Returns:
bool

Definition at line 1260 of file Product.php.

01261     {
01262         return $this->getTypeInstance(true)->isComposite($this);
01263     }

isConfigurable (  ) 

Check is product configurable

Returns:
bool

Definition at line 1046 of file Product.php.

01047     {
01048         return $this->getTypeId() == Mage_Catalog_Model_Product_Type::TYPE_CONFIGURABLE;
01049     }

isDuplicable (  ) 

Checks product can be duplicated

Returns:
boolean

Definition at line 1081 of file Product.php.

01082     {
01083         return $this->_isDuplicable;
01084     }

isGrouped (  ) 

Check is product grouped

Returns:
bool

Definition at line 1036 of file Product.php.

01037     {
01038         return $this->getTypeId() == Mage_Catalog_Model_Product_Type::TYPE_GROUPED;
01039     }

isInStock (  ) 

Definition at line 1139 of file Product.php.

01140     {
01141         return $this->getStatus() == Mage_Catalog_Model_Product_Status::STATUS_ENABLED;
01142     }

isReservedAttribute ( attribute  ) 

Check whether attribute reserved or not

Parameters:
Mage_Eav_Model_Entity_Attribute $attribute Attribute model object
Returns:
boolean

Definition at line 1518 of file Product.php.

01519     {
01520         return $attribute->getIsUserDefined()
01521             && in_array($attribute->getAttributeCode(), $this->getReservedAttributes());
01522     }

isSalable (  ) 

Check is product available for sale

Returns:
bool

Definition at line 1104 of file Product.php.

01105     {
01106         Mage::dispatchEvent('catalog_product_is_salable_before', array(
01107             'product'   => $this
01108         ));
01109 
01110         $salable = $this->getTypeInstance(true)->isSalable($this);
01111 
01112         $object = new Varien_Object(array(
01113             'product'    => $this,
01114             'is_salable' => $salable
01115         ));
01116         Mage::dispatchEvent('catalog_product_is_salable_after', array(
01117             'product'   => $this,
01118             'salable'   => $object
01119         ));
01120         return $object->getIsSalable();
01121     }

isSaleable (  ) 

Definition at line 1134 of file Product.php.

01135     {
01136         return $this->isSalable();
01137     }

isSuper (  ) 

Definition at line 1051 of file Product.php.

01052     {
01053         return $this->isConfigurable() || $this->isGrouped();
01054     }

isSuperConfig (  ) 

Definition at line 1027 of file Product.php.

01028     {
01029         return $this->isConfigurable();
01030     }

isSuperGroup (  ) 

Definition at line 1022 of file Product.php.

01023     {
01024         return $this->getTypeId() == Mage_Catalog_Model_Product_Type::TYPE_GROUPED;
01025     }

isVirtual (  ) 

Check is a virtual product Data helper wraper

Returns:
bool

Definition at line 1129 of file Product.php.

01130     {
01131         return $this->getIsVirtual();
01132     }

isVisibleInCatalog (  ) 

Definition at line 1061 of file Product.php.

01062     {
01063         return in_array($this->getStatus(), $this->getVisibleInCatalogStatuses());
01064     }

isVisibleInSiteVisibility (  ) 

Definition at line 1071 of file Product.php.

01072     {
01073         return in_array($this->getVisibility(), $this->getVisibleInSiteVisibilities());
01074     }

loadParentProductIds (  ) 

Definition at line 1224 of file Product.php.

01225     {
01226         return $this->setParentProductIds($this->_getResource()->getParentProductIds($this));
01227     }

reset (  ) 

Reset all model data

Returns:
Mage_Catalog_Model_Product

Definition at line 1554 of file Product.php.

01555     {
01556         $this->setData(array());
01557         $this->setOrigData();
01558         $this->_customOptions       = array();
01559         $this->_optionInstance      = null;
01560         $this->_options             = array();
01561         $this->_canAffectOptions    = false;
01562         $this->_errors              = array();
01563 
01564         return $this;
01565     }

setCategoryIds ( ids  ) 

Definition at line 291 of file Product.php.

00292     {
00293         if (is_string($ids)) {
00294             $ids = explode(',', $ids);
00295         } elseif (!is_array($ids)) {
00296             Mage::throwException(Mage::helper('catalog')->__('Invalid category IDs'));
00297         }
00298         foreach ($ids as $i=>$v) {
00299             if (empty($v)) {
00300                 unset($ids[$i]);
00301             }
00302         }
00303         $this->setData('category_ids', $ids);
00304         return $this;
00305     }

setCustomOptions ( array options  ) 

Definition at line 1378 of file Product.php.

01379     {
01380         $this->_customOptions = $options;
01381     }

setIsDuplicable ( value  ) 

Set is duplicable flag

Parameters:
boolean $value
Returns:
Mage_Catalog_Model_Product

Definition at line 1092 of file Product.php.

01093     {
01094         $this->_isDuplicable = (boolean) $value;
01095         return $this;
01096     }

setOrigData ( key = null,
data = null 
)

Set original loaded data if needed

Parameters:
string $key
mixed $data
Returns:
Varien_Object

Reimplemented from Varien_Object.

Definition at line 1531 of file Product.php.

01532     {
01533         if (Mage::app()->getStore()->isAdmin()) {
01534             return parent::setOrigData($key, $data);
01535         }
01536 
01537         return $this;
01538     }

setTypeInstance ( instance,
singleton = false 
)

Set type instance for external

Parameters:
Mage_Catalog_Model_Product_Type_Abstract $singleton
bool $singleton
Returns:
Mage_Catalog_Model_Product

Definition at line 228 of file Product.php.

00229     {
00230         if ($singleton === true) {
00231             $this->_typeInstanceSingleton = $instance;
00232         }
00233         else {
00234             $this->_typeInstance = $instance;
00235         }
00236         return $this;
00237     }

toArray ( array arrAttributes = array()  ) 

Public wrapper for __toArray

Parameters:
array $arrAttributes
Returns:
array

Reimplemented from Varien_Object.

Definition at line 1201 of file Product.php.

01202     {
01203         $data = parent::toArray($arrAttributes);
01204         if ($stock = $this->getStockItem()) {
01205             $data['stock_item'] = $stock->toArray();
01206         }
01207         unset($data['stock_item']['product']);
01208         return $data;
01209     }

validate (  ) 

Validate Product Data

Returns:
Mage_Catalog_Model_Product

Definition at line 150 of file Product.php.

00151     {
00152         $this->_getResource()->validate($this);
00153         return $this;
00154     }


Member Data Documentation

$_cacheTag = 'catalog_product' [protected]

Reimplemented from Mage_Core_Model_Abstract.

Definition at line 37 of file Product.php.

$_canAffectOptions = false [protected]

Definition at line 40 of file Product.php.

$_customOptions = array() [protected]

Definition at line 66 of file Product.php.

$_errors = array() [protected]

Definition at line 78 of file Product.php.

$_eventObject = 'product' [protected]

Reimplemented from Mage_Core_Model_Abstract.

Definition at line 39 of file Product.php.

$_eventPrefix = 'catalog_product' [protected]

Reimplemented from Mage_Core_Model_Abstract.

Definition at line 38 of file Product.php.

$_isDuplicable = true [protected]

Definition at line 94 of file Product.php.

$_linkInstance [protected]

Definition at line 59 of file Product.php.

$_optionInstance [protected]

Definition at line 80 of file Product.php.

$_options = array() [protected]

Definition at line 82 of file Product.php.

$_reservedAttributes [protected]

Product reserved attribute codes

Definition at line 87 of file Product.php.

$_typeInstance = null [protected]

Definition at line 47 of file Product.php.

$_typeInstanceSingleton = null [protected]

Product type instance as singleton

Definition at line 52 of file Product.php.

$_url [static, protected]

Definition at line 75 of file Product.php.

$_urlModel = null [protected]

Definition at line 73 of file Product.php.

$_urlRewrite [static, protected]

Definition at line 76 of file Product.php.

const CACHE_TAG = 'catalog_product'

Definition at line 36 of file Product.php.


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

Generated on Sat Jul 4 17:23:39 2009 for Magento by  doxygen 1.5.8