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_Catalog_Model_Product extends Mage_Catalog_Model_Abstract
00035 {
00036 const CACHE_TAG = 'catalog_product';
00037 protected $_cacheTag = 'catalog_product';
00038 protected $_eventPrefix = 'catalog_product';
00039 protected $_eventObject = 'product';
00040 protected $_canAffectOptions = false;
00041
00042
00043
00044
00045
00046
00047 protected $_typeInstance = null;
00048
00049
00050
00051
00052 protected $_typeInstanceSingleton = null;
00053
00054
00055
00056
00057
00058
00059 protected $_linkInstance;
00060
00061
00062
00063
00064
00065
00066 protected $_customOptions = array();
00067
00068
00069
00070
00071
00072
00073 protected $_urlModel = null;
00074
00075 protected static $_url;
00076 protected static $_urlRewrite;
00077
00078 protected $_errors = array();
00079
00080 protected $_optionInstance;
00081
00082 protected $_options = array();
00083
00084
00085
00086
00087 protected $_reservedAttributes;
00088
00089
00090
00091
00092
00093
00094 protected $_isDuplicable = true;
00095
00096
00097
00098
00099 protected function _construct()
00100 {
00101 $this->_init('catalog/product');
00102 }
00103
00104
00105
00106
00107
00108
00109 public function getStoreId()
00110 {
00111 if ($this->hasData('store_id')) {
00112 return $this->getData('store_id');
00113 }
00114 return Mage::app()->getStore()->getId();
00115 }
00116
00117
00118
00119
00120
00121
00122 public function getResourceCollection()
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 }
00131
00132
00133
00134
00135
00136
00137 public function getUrlModel()
00138 {
00139 if ($this->_urlModel === null) {
00140 $this->_urlModel = Mage::getSingleton('catalog/product_url');
00141 }
00142 return $this->_urlModel;
00143 }
00144
00145
00146
00147
00148
00149
00150 public function validate()
00151 {
00152 $this->_getResource()->validate($this);
00153 return $this;
00154 }
00155
00156
00157
00158
00159
00160
00161 public function getName()
00162 {
00163 return $this->_getData('name');
00164 }
00165
00166
00167
00168
00169
00170
00171 public function getPrice()
00172 {
00173 return $this->getPriceModel()->getPrice($this);
00174 }
00175
00176
00177
00178
00179
00180
00181 public function getTypeId()
00182 {
00183 return $this->_getData('type_id');
00184 }
00185
00186
00187
00188
00189
00190
00191 public function getStatus()
00192 {
00193 return $this->_getData('status');
00194 }
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204 public function getTypeInstance($singleton = false)
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 }
00220
00221
00222
00223
00224
00225
00226
00227
00228 public function setTypeInstance($instance, $singleton = false)
00229 {
00230 if ($singleton === true) {
00231 $this->_typeInstanceSingleton = $instance;
00232 }
00233 else {
00234 $this->_typeInstance = $instance;
00235 }
00236 return $this;
00237 }
00238
00239
00240
00241
00242
00243
00244 public function getLinkInstance()
00245 {
00246 if (!$this->_linkInstance) {
00247 $this->_linkInstance = Mage::getSingleton('catalog/product_link');
00248 }
00249 return $this->_linkInstance;
00250 }
00251
00252
00253
00254
00255
00256
00257
00258 public function getIdBySku($sku)
00259 {
00260 return $this->_getResource()->getIdBySku($sku);
00261 }
00262
00263
00264
00265
00266
00267
00268 public function getCategoryId()
00269 {
00270 if ($category = Mage::registry('current_category')) {
00271 return $category->getId();
00272 }
00273 return false;
00274 }
00275
00276
00277
00278
00279
00280
00281 public function getCategory()
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 }
00290
00291 public function setCategoryIds($ids)
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 }
00306
00307 public function getCategoryIds()
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 }
00337
00338
00339
00340
00341
00342
00343 public function getCategoryCollection()
00344 {
00345 return $this->getResource()->getCategoryCollection($this);
00346 }
00347
00348
00349
00350
00351
00352
00353 public function getWebsiteIds()
00354 {
00355 if (!$this->hasWebsiteIds()) {
00356 $ids = $this->_getResource()->getWebsiteIds($this);
00357 $this->setWebsiteIds($ids);
00358 }
00359 return $this->getData('website_ids');
00360 }
00361
00362
00363
00364
00365
00366
00367 public function getStoreIds()
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 }
00381
00382
00383
00384
00385
00386
00387
00388
00389
00390 public function getAttributes($groupId = null, $skipSuper=false)
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 }
00407
00408
00409
00410
00411 protected function _beforeSave()
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
00424
00425
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
00448
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 }
00465
00466
00467
00468
00469
00470
00471
00472
00473 public function canAffectOptions($value = null)
00474 {
00475 if (null !== $value) {
00476 $this->_canAffectOptions = (bool)$value;
00477 }
00478 return $this->_canAffectOptions;
00479 }
00480
00481
00482
00483
00484
00485
00486 protected function _afterSave()
00487 {
00488 $this->getLinkInstance()->saveProductRelations($this);
00489 $this->getTypeInstance(true)->save($this);
00490
00491
00492
00493
00494 $this->getOptionInstance()->setProduct($this)
00495 ->saveOptions();
00496
00497 parent::_afterSave();
00498 }
00499
00500
00501
00502
00503
00504
00505 protected function _beforeDelete()
00506 {
00507 $this->cleanCache();
00508 $this->_protectFromNonAdmin();
00509 return parent::_beforeDelete();
00510 }
00511
00512
00513
00514
00515
00516
00517 protected function _afterLoad()
00518 {
00519 parent::_afterLoad();
00520
00521
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 }
00531
00532
00533
00534
00535
00536
00537 public function cleanCache()
00538 {
00539 Mage::app()->cleanCache('catalog_product_'.$this->getId());
00540 return $this;
00541 }
00542
00543
00544
00545
00546
00547
00548 public function getPriceModel()
00549 {
00550 return Mage::getSingleton('catalog/product_type')->priceFactory($this->getTypeId());
00551 }
00552
00553
00554
00555
00556
00557
00558
00559 public function getTierPrice($qty=null)
00560 {
00561 return $this->getPriceModel()->getTierPrice($qty, $this);
00562 }
00563
00564
00565
00566
00567
00568
00569 public function getTierPriceCount()
00570 {
00571 return $this->getPriceModel()->getTierPriceCount($this);
00572 }
00573
00574
00575
00576
00577
00578
00579
00580 public function getFormatedTierPrice($qty=null)
00581 {
00582 return $this->getPriceModel()->getFormatedTierPrice($qty, $this);
00583 }
00584
00585
00586
00587
00588
00589
00590 public function getFormatedPrice()
00591 {
00592 return $this->getPriceModel()->getFormatedPrice($this);
00593 }
00594
00595
00596
00597
00598
00599
00600
00601 public function getFinalPrice($qty=null)
00602 {
00603 $price = $this->_getData('final_price');
00604 if ($price !== null) {
00605 return $price;
00606 }
00607 return $this->getPriceModel()->getFinalPrice($qty, $this);
00608 }
00609
00610 public function getCalculatedFinalPrice()
00611 {
00612 return $this->_getData('calculated_final_price');
00613 }
00614
00615 public function getMinimalPrice()
00616 {
00617 return $this->_getData('minimal_price');
00618 }
00619
00620 public function getSpecialPrice()
00621 {
00622 return $this->_getData('special_price');
00623 }
00624
00625 public function getSpecialFromDate()
00626 {
00627 return $this->_getData('special_from_date');
00628 }
00629
00630 public function getSpecialToDate()
00631 {
00632 return $this->_getData('special_to_date');
00633 }
00634
00635
00636
00637
00638
00639
00640
00641
00642
00643
00644 public function getRelatedProducts()
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 }
00656
00657
00658
00659
00660
00661
00662 public function getRelatedProductIds()
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 }
00673
00674
00675
00676
00677 public function getRelatedProductCollection()
00678 {
00679 $collection = $this->getLinkInstance()->useRelatedLinks()
00680 ->getProductCollection()
00681 ->setIsStrongMode();
00682 $collection->setProduct($this);
00683 return $collection;
00684 }
00685
00686
00687
00688
00689 public function getRelatedLinkCollection()
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 }
00699
00700
00701
00702
00703
00704
00705 public function getUpSellProducts()
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 }
00716
00717
00718
00719
00720
00721
00722 public function getUpSellProductIds()
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 }
00733
00734
00735
00736
00737 public function getUpSellProductCollection()
00738 {
00739 $collection = $this->getLinkInstance()->useUpSellLinks()
00740 ->getProductCollection()
00741 ->setIsStrongMode();
00742 $collection->setProduct($this);
00743 return $collection;
00744 }
00745
00746
00747
00748
00749 public function getUpSellLinkCollection()
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 }
00759
00760
00761
00762
00763
00764
00765 public function getCrossSellProducts()
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 }
00776
00777
00778
00779
00780
00781
00782 public function getCrossSellProductIds()
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 }
00793
00794
00795
00796
00797
00798
00799 public function getCrossSellProductCollection()
00800 {
00801 $collection = $this->getLinkInstance()->useCrossSellLinks()
00802 ->getProductCollection()
00803 ->setIsStrongMode();
00804 $collection->setProduct($this);
00805 return $collection;
00806 }
00807
00808
00809
00810
00811 public function getCrossSellLinkCollection()
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 }
00821
00822
00823
00824
00825 public function getGroupedLinkCollection()
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 }
00835
00836
00837
00838
00839
00840
00841
00842
00843
00844 public function getMediaAttributes()
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 }
00857
00858
00859
00860
00861
00862
00863 public function getMediaGalleryImages()
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 }
00881
00882
00883
00884
00885
00886
00887
00888
00889
00890
00891 public function addImageToMediaGallery($file, $mediaAttribute=null, $move=false, $exclude=true)
00892 {
00893 $attributes = $this->getTypeInstance(true)->getSetAttributes($this);
00894 if (!isset($attributes['media_gallery'])) {
00895 return $this;
00896 }
00897 $mediaGalleryAttribute = $attributes['media_gallery'];
00898
00899 $mediaGalleryAttribute->getBackend()->addImage($this, $file, $mediaAttribute, $move, $exclude);
00900 return $this;
00901 }
00902
00903
00904
00905
00906
00907
00908 public function getMediaConfig()
00909 {
00910 return Mage::getSingleton('catalog/product_media_config');
00911 }
00912
00913
00914
00915
00916
00917
00918 public function duplicate()
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
00936
00937
00938
00939
00940
00941
00942
00943
00944
00945
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
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
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
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
01007
01008
01009
01010
01011
01012
01013
01014
01015
01016
01017
01018
01019 return $newProduct;
01020 }
01021
01022 public function isSuperGroup()
01023 {
01024 return $this->getTypeId() == Mage_Catalog_Model_Product_Type::TYPE_GROUPED;
01025 }
01026
01027 public function isSuperConfig()
01028 {
01029 return $this->isConfigurable();
01030 }
01031
01032
01033
01034
01035
01036 public function isGrouped()
01037 {
01038 return $this->getTypeId() == Mage_Catalog_Model_Product_Type::TYPE_GROUPED;
01039 }
01040
01041
01042
01043
01044
01045
01046 public function isConfigurable()
01047 {
01048 return $this->getTypeId() == Mage_Catalog_Model_Product_Type::TYPE_CONFIGURABLE;
01049 }
01050
01051 public function isSuper()
01052 {
01053 return $this->isConfigurable() || $this->isGrouped();
01054 }
01055
01056 public function getVisibleInCatalogStatuses()
01057 {
01058 return Mage::getSingleton('catalog/product_status')->getVisibleStatusIds();
01059 }
01060
01061 public function isVisibleInCatalog()
01062 {
01063 return in_array($this->getStatus(), $this->getVisibleInCatalogStatuses());
01064 }
01065
01066 public function getVisibleInSiteVisibilities()
01067 {
01068 return Mage::getSingleton('catalog/product_visibility')->getVisibleInSiteIds();
01069 }
01070
01071 public function isVisibleInSiteVisibility()
01072 {
01073 return in_array($this->getVisibility(), $this->getVisibleInSiteVisibilities());
01074 }
01075
01076
01077
01078
01079
01080
01081 public function isDuplicable()
01082 {
01083 return $this->_isDuplicable;
01084 }
01085
01086
01087
01088
01089
01090
01091
01092 public function setIsDuplicable($value)
01093 {
01094 $this->_isDuplicable = (boolean) $value;
01095 return $this;
01096 }
01097
01098
01099
01100
01101
01102
01103
01104 public function isSalable()
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 }
01122
01123
01124
01125
01126
01127
01128
01129 public function isVirtual()
01130 {
01131 return $this->getIsVirtual();
01132 }
01133
01134 public function isSaleable()
01135 {
01136 return $this->isSalable();
01137 }
01138
01139 public function isInStock()
01140 {
01141 return $this->getStatus() == Mage_Catalog_Model_Product_Status::STATUS_ENABLED;
01142 }
01143
01144 public function getAttributeText($attributeCode)
01145 {
01146 return $this->getResource()
01147 ->getAttribute($attributeCode)
01148 ->getSource()
01149 ->getOptionText($this->getData($attributeCode));
01150 }
01151
01152 public function getCustomDesignDate()
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 }
01160
01161
01162
01163
01164
01165
01166
01167 public function getProductUrl($useSid = true)
01168 {
01169 return $this->getUrlModel()->getProductUrl($this, $useSid);
01170 }
01171
01172 public function formatUrlKey($str)
01173 {
01174 return $this->getUrlModel()->formatUrlKey($str);
01175 }
01176
01177
01178
01179
01180
01181
01182
01183 public function getUrlPath($category=null)
01184 {
01185 return $this->getUrlModel()->getUrlPath($this, $category);
01186 }
01187
01188 public function addAttributeUpdate($code, $value, $store)
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 }
01200
01201 public function toArray(array $arrAttributes=array())
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 }
01210
01211 public function fromArray($data)
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 }
01223
01224 public function loadParentProductIds()
01225 {
01226 return $this->setParentProductIds($this->_getResource()->getParentProductIds($this));
01227 }
01228
01229 public function delete()
01230 {
01231 parent::delete();
01232 Mage::dispatchEvent($this->_eventPrefix.'_delete_after_done', array($this->_eventObject=>$this));
01233 return $this;
01234 }
01235
01236 public function getRequestPath()
01237 {
01238 return $this->_getData('request_path');
01239 }
01240
01241
01242
01243
01244
01245 public function getGiftMessageAvailable()
01246 {
01247 return $this->_getData('gift_message_available');
01248 }
01249
01250 public function getRatingSummary()
01251 {
01252 return $this->_getData('rating_summary');
01253 }
01254
01255
01256
01257
01258
01259
01260 public function isComposite()
01261 {
01262 return $this->getTypeInstance(true)->isComposite($this);
01263 }
01264
01265
01266
01267
01268
01269
01270 public function getSku()
01271 {
01272 return $this->getTypeInstance(true)->getSku($this);
01273 }
01274
01275
01276
01277
01278
01279
01280 public function getWeight()
01281 {
01282 return $this->getTypeInstance(true)->getWeight($this);
01283 }
01284
01285
01286
01287
01288
01289
01290 public function getOptionInstance()
01291 {
01292 if (!$this->_optionInstance) {
01293 $this->_optionInstance = Mage::getSingleton('catalog/product_option');
01294 }
01295 return $this->_optionInstance;
01296 }
01297
01298
01299
01300
01301
01302
01303 public function getProductOptionsCollection()
01304 {
01305 $collection = $this->getOptionInstance()
01306 ->getProductOptionCollection($this);
01307
01308 return $collection;
01309 }
01310
01311
01312
01313
01314
01315
01316
01317 public function addOption(Mage_Catalog_Model_Product_Option $option)
01318 {
01319 $this->_options[$option->getId()] = $option;
01320 return $this;
01321 }
01322
01323
01324
01325
01326
01327
01328
01329 public function getOptionById($optionId)
01330 {
01331 if (isset($this->_options[$optionId])) {
01332 return $this->_options[$optionId];
01333 }
01334
01335 return null;
01336 }
01337
01338
01339
01340
01341
01342
01343 public function getOptions()
01344 {
01345 return $this->_options;
01346 }
01347
01348
01349
01350
01351
01352
01353 public function getIsVirtual()
01354 {
01355 return $this->getTypeInstance(true)->isVirtual($this);
01356 }
01357
01358
01359
01360
01361
01362
01363
01364
01365
01366 public function addCustomOption($code, $value, $product=null)
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 }
01377
01378 public function setCustomOptions(array $options)
01379 {
01380 $this->_customOptions = $options;
01381 }
01382
01383
01384
01385
01386
01387
01388 public function getCustomOptions()
01389 {
01390 return $this->_customOptions;
01391 }
01392
01393
01394
01395
01396
01397
01398
01399 public function getCustomOption($code)
01400 {
01401 if (isset($this->_customOptions[$code])) {
01402 return $this->_customOptions[$code];
01403 }
01404 return null;
01405 }
01406
01407
01408
01409
01410
01411
01412 public function hasCustomOptions()
01413 {
01414 if (count($this->_customOptions)) {
01415 return true;
01416 } else {
01417 return false;
01418 }
01419 }
01420
01421
01422
01423
01424
01425
01426
01427 public function canBeShowInCategory($categoryId)
01428 {
01429 return $this->_getResource()->canBeShowInCategory($this, $categoryId);
01430 }
01431
01432
01433 public function getAvailableInCategories()
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 }
01450
01451
01452
01453
01454
01455
01456
01457 public function getDefaultAttributeSetId()
01458 {
01459 return $this->getResource()->getEntityType()->getDefaultAttributeSetId();
01460 }
01461
01462
01463
01464
01465
01466 public function getImageUrl()
01467 {
01468 return (string)Mage::helper('catalog/image')->init($this, 'image')->resize(265);
01469 }
01470
01471
01472
01473
01474 public function getSmallImageUrl($width = 88, $height = 77)
01475 {
01476 return (string)Mage::helper('catalog/image')->init($this, 'small_image')->resize($width, $height);
01477 }
01478
01479
01480
01481
01482 public function getThumbnailUrl($width = 75, $height = 75)
01483 {
01484 return (string)Mage::helper('catalog/image')->init($this, 'thumbnail')->resize($width, $height);
01485 }
01486
01487
01488
01489
01490
01491
01492 public function getReservedAttributes()
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 }
01511
01512
01513
01514
01515
01516
01517
01518 public function isReservedAttribute ($attribute)
01519 {
01520 return $attribute->getIsUserDefined()
01521 && in_array($attribute->getAttributeCode(), $this->getReservedAttributes());
01522 }
01523
01524
01525
01526
01527
01528
01529
01530
01531 public function setOrigData($key=null, $data=null)
01532 {
01533 if (Mage::app()->getStore()->isAdmin()) {
01534 return parent::setOrigData($key, $data);
01535 }
01536
01537 return $this;
01538 }
01539
01540
01541
01542
01543
01544 protected function _substractQtyFromQuotes()
01545 {
01546
01547 }
01548
01549
01550
01551
01552
01553
01554 public function reset()
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 }
01566 }