Go to the documentation of this file.00001 <?php
00002
00007 class oxBasketItem extends oxSuperCfg
00008 {
00009
00015 protected $_sProductId = null;
00016
00022 protected $_sTitle = null;
00023
00029 protected $_sVarSelect = null;
00030
00036 protected $_sIcon = null;
00037
00043 protected $_sLink = null;
00044
00050 protected $_oPrice = null;
00051
00057 protected $_oUnitPrice = null;
00058
00064 protected $_dAmount = 0.0;
00065
00071 protected $_dWeight = 0;
00072
00078 protected $_aSelList = array();
00079
00085 protected $_sShopId = null;
00086
00092 protected $_sNativeShopId = null;
00093
00099 protected $_blSkipDiscounts = false;
00100
00106 protected $_aPersistentParameters = array();
00107
00113 protected $_blBundle = false;
00114
00120 protected $_blIsDiscountArticle = false;
00121
00127 protected $_oArticle = null;
00128
00134 protected $_sDimageDirNoSsl = null;
00135
00141 protected $_sDimageDirSsl = null;
00142
00148 protected $_aChosenSelectlist = array();
00149
00155 protected $_sWrappingId = null;
00156
00162 protected $_sWishId = null;
00163
00169 protected $_sWishArticleId = null;
00170
00176 protected $_blCheckArticleStock = true;
00177
00178
00184 protected $_iLanguageId = null;
00185
00191 protected $_blSsl = null;
00192
00198 protected $_sIconUrl = null;
00199
00200
00206 protected $_oRegularUnitPrice = null;
00207
00208
00214 public function getRegularUnitPrice()
00215 {
00216 return $this->_oRegularUnitPrice;
00217 }
00218
00224 public function setRegularUnitPrice($oRegularUnitPrice)
00225 {
00226 $this->_oRegularUnitPrice = $oRegularUnitPrice;
00227 }
00228
00229
00246 public function init($sProductID, $dAmount, $aSel = null, $aPersParam = null, $blBundle = null)
00247 {
00248 $this->_setArticle($sProductID);
00249 $this->setAmount($dAmount);
00250 $this->_setSelectList($aSel);
00251 $this->setPersParams($aPersParam);
00252 $this->setBundle($blBundle);
00253 $this->setLanguageId(oxRegistry::getLang()->getBaseLanguage());
00254 }
00255
00267 public function initFromOrderArticle($oOrderArticle)
00268 {
00269 $this->_setFromOrderArticle($oOrderArticle);
00270 $this->setAmount($oOrderArticle->oxorderarticles__oxamount->value);
00271 $this->_setSelectList($oOrderArticle->getOrderArticleSelectList());
00272 $this->setPersParams($oOrderArticle->getPersParams());
00273 $this->setBundle($oOrderArticle->isBundle());
00274 }
00275
00281 public function setAsDiscountArticle($blIsDiscountArticle)
00282 {
00283 $this->_blIsDiscountArticle = $blIsDiscountArticle;
00284 }
00285
00291 public function setStockCheckStatus($blStatus)
00292 {
00293 $this->_blCheckArticleStock = $blStatus;
00294 }
00295
00301 public function getStockCheckStatus()
00302 {
00303 return $this->_blCheckArticleStock;
00304 }
00305
00317 public function setAmount($dAmount, $blOverride = true, $sItemKey = null)
00318 {
00319 try {
00320
00321 $dAmount = oxRegistry::get("oxInputValidator")->validateBasketAmount($dAmount);
00322 } catch (oxArticleInputException $oEx) {
00323 $oEx->setArticleNr($this->getProductId());
00324 $oEx->setProductId($this->getProductId());
00325
00326 throw $oEx;
00327 }
00328
00329 $oArticle = $this->getArticle(true);
00330
00331
00332
00333 $iOnStock = true;
00334
00335 if ($blOverride) {
00336 $this->_dAmount = $dAmount;
00337 } else {
00338 $this->_dAmount += $dAmount;
00339 }
00340
00341
00342 if ($this->getStockCheckStatus() == true) {
00343 $dArtStockAmount = $this->getSession()->getBasket()->getArtStockInBasket($oArticle->getId(), $sItemKey);
00344 $iOnStock = $oArticle->checkForStock($this->_dAmount, $dArtStockAmount);
00345 if ($iOnStock !== true) {
00346 if ($iOnStock === false) {
00347
00348 $this->_dAmount = 0;
00349 } else {
00350
00351 $this->_dAmount = $iOnStock;
00352 $blOverride = true;
00353 }
00354 }
00355 }
00356
00357
00358 $this->_dWeight = $oArticle->oxarticles__oxweight->value * $this->_dAmount;
00359
00360 if ($iOnStock !== true) {
00362 $oEx = oxNew('oxOutOfStockException');
00363 $oEx->setMessage('ERROR_MESSAGE_OUTOFSTOCK_OUTOFSTOCK');
00364 $oEx->setArticleNr($oArticle->oxarticles__oxartnum->value);
00365 $oEx->setProductId($oArticle->getProductId());
00366 $oEx->setRemainingAmount($this->_dAmount);
00367 $oEx->setBasketIndex($sItemKey);
00368 throw $oEx;
00369 }
00370 }
00371
00377 public function setPrice($oPrice)
00378 {
00379 $this->_oUnitPrice = clone $oPrice;
00380
00381 $this->_oPrice = clone $oPrice;
00382 $this->_oPrice->multiply($this->getAmount());
00383 }
00384
00390 public function getIconUrl()
00391 {
00392
00393 if ($this->_sIconUrl === null || $this->_blSsl != $this->getConfig()->isSsl()) {
00394 $this->_sIconUrl = $this->getArticle()->getIconUrl();
00395 }
00396
00397 return $this->_sIconUrl;
00398 }
00399
00414 public function getArticle($blCheckProduct = false, $sProductId = null, $blDisableLazyLoading = false)
00415 {
00416 if ($this->_oArticle === null || (!$this->_oArticle->isOrderArticle() && $blDisableLazyLoading)) {
00417 $sProductId = $sProductId ? $sProductId : $this->_sProductId;
00418 if (!$sProductId) {
00419
00421 $oEx = oxNew('oxArticleException');
00422 $oEx->setMessage('EXCEPTION_ARTICLE_NOPRODUCTID');
00423 throw $oEx;
00424 }
00425
00426 $this->_oArticle = oxNew('oxarticle');
00427
00428 if ($blDisableLazyLoading) {
00429 $this->_oArticle->modifyCacheKey('_allviews');
00430 $this->_oArticle->disableLazyLoading();
00431 }
00432
00433
00434
00435
00436
00437 $this->_oArticle->setNoVariantLoading(true);
00438 $this->_oArticle->setLoadParentData(true);
00439 if (!$this->_oArticle->load($sProductId)) {
00441 $oEx = oxNew('oxNoArticleException');
00442 $oLang = oxRegistry::getLang();
00443 $oEx->setMessage(sprintf($oLang->translateString('ERROR_MESSAGE_ARTICLE_ARTICLE_DOES_NOT_EXIST', $oLang->getBaseLanguage()), $sProductId));
00444 $oEx->setArticleNr($sProductId);
00445 $oEx->setProductId($sProductId);
00446 throw $oEx;
00447 }
00448
00449
00450 if ($blCheckProduct && !$this->_oArticle->isVisible()) {
00452 $oEx = oxNew('oxNoArticleException');
00453 $oLang = oxRegistry::getLang();
00454 $oEx->setMessage(sprintf($oLang->translateString('ERROR_MESSAGE_ARTICLE_ARTICLE_DOES_NOT_EXIST', $oLang->getBaseLanguage()), $this->_oArticle->oxarticles__oxartnum->value));
00455 $oEx->setArticleNr($sProductId);
00456 $oEx->setProductId($sProductId);
00457 throw $oEx;
00458 }
00459
00460
00461 if ($blCheckProduct && !$this->_oArticle->isBuyable()) {
00463 $oEx = oxNew('oxArticleInputException');
00464 $oEx->setMessage('ERROR_MESSAGE_ARTICLE_ARTICLE_NOT_BUYABLE');
00465 $oEx->setArticleNr($sProductId);
00466 $oEx->setProductId($sProductId);
00467 throw $oEx;
00468 }
00469 }
00470
00471 return $this->_oArticle;
00472 }
00473
00479 public function getdBundledAmount()
00480 {
00481 return $this->isBundle() ? $this->_dAmount : 0;
00482 }
00483
00489 public function getPrice()
00490 {
00491 return $this->_oPrice;
00492 }
00493
00499 public function getUnitPrice()
00500 {
00501 return $this->_oUnitPrice;
00502 }
00503
00509 public function getAmount()
00510 {
00511 return $this->_dAmount;
00512 }
00513
00519 public function getWeight()
00520 {
00521 return $this->_dWeight;
00522 }
00523
00529 public function getTitle()
00530 {
00531 if ($this->_sTitle === null || $this->getLanguageId() != oxRegistry::getLang()->getBaseLanguage()) {
00532
00533 $oArticle = $this->getArticle();
00534 $this->_sTitle = $oArticle->oxarticles__oxtitle->value;
00535
00536 if ($oArticle->oxarticles__oxvarselect->value) {
00537 $this->_sTitle = $this->_sTitle . ', ' . $this->getVarSelect();
00538 }
00539 }
00540
00541 return $this->_sTitle;
00542 }
00543
00549 public function getLink()
00550 {
00551 if ($this->_sLink === null || $this->getLanguageId() != oxRegistry::getLang()->getBaseLanguage()) {
00552 $this->_sLink = oxRegistry::get("oxUtilsUrl")->cleanUrl($this->getArticle()->getLink(), array('force_sid'));
00553 }
00554
00555 return $this->getSession()->processUrl($this->_sLink);
00556 }
00557
00563 public function getShopId()
00564 {
00565 return $this->_sShopId;
00566 }
00567
00573 public function getSelList()
00574 {
00575 return $this->_aSelList;
00576 }
00577
00583 public function getChosenSelList()
00584 {
00585 return $this->_aChosenSelectlist;
00586 }
00587
00593 public function isBundle()
00594 {
00595 return $this->_blBundle;
00596 }
00597
00603 public function isDiscountArticle()
00604 {
00605 return $this->_blIsDiscountArticle;
00606 }
00607
00613 public function isSkipDiscount()
00614 {
00615 return $this->_blSkipDiscounts;
00616 }
00617
00627 public function __get($sName)
00628 {
00629 if ($sName == 'oProduct') {
00630 return $this->getArticle();
00631 }
00632 }
00633
00639 public function __sleep()
00640 {
00641 $aRet = array();
00642 foreach (get_object_vars($this) as $sKey => $sVar) {
00643 if ($sKey != '_oArticle') {
00644 $aRet[] = $sKey;
00645 }
00646 }
00647
00648 return $aRet;
00649 }
00650
00666 protected function _setArticle($sProductId)
00667 {
00668 $oConfig = $this->getConfig();
00669 $oArticle = $this->getArticle(true, $sProductId);
00670
00671
00672 $this->_sProductId = $sProductId;
00673
00674 $this->_sTitle = null;
00675 $this->_sVarSelect = null;
00676 $this->getTitle();
00677
00678
00679 $this->_sIcon = $oArticle->oxarticles__oxicon->value;
00680 $this->_sIconUrl = $oArticle->getIconUrl();
00681 $this->_blSsl = $oConfig->isSsl();
00682
00683
00684 $this->_sLink = oxRegistry::get("oxUtilsUrl")->cleanUrl($oArticle->getLink(), array('force_sid'));
00685
00686
00687 $this->_sShopId = $oConfig->getShopId();
00688 $this->_sNativeShopId = $oArticle->oxarticles__oxshopid->value;
00689
00690
00691 $this->_sDimageDirNoSsl = $oArticle->nossl_dimagedir;
00692 $this->_sDimageDirSsl = $oArticle->ssl_dimagedir;
00693 }
00694
00704 protected function _setFromOrderArticle($oOrderArticle)
00705 {
00706
00707 $this->_oArticle = $oOrderArticle;
00708
00709
00710 $this->_sProductId = $oOrderArticle->getProductId();
00711
00712
00713 $this->_sTitle = $oOrderArticle->oxarticles__oxtitle->value;
00714
00715
00716 $this->_sShopId = $this->getConfig()->getShopId();
00717 $this->_sNativeShopId = $oOrderArticle->oxarticles__oxshopid->value;
00718 }
00719
00725 protected function _setSelectList($aSelList)
00726 {
00727
00728 $aSelectLists = $this->getArticle()->getSelectLists();
00729 if (!$aSelList || is_array($aSelList) && count($aSelList) == 0) {
00730 if ($iSelCnt = count($aSelectLists)) {
00731 $aSelList = array_fill(0, $iSelCnt, '0');
00732 }
00733 }
00734
00735 $this->_aSelList = $aSelList;
00736
00737
00738 if (count($this->_aSelList) && is_array($this->_aSelList)) {
00739 foreach ($this->_aSelList as $conkey => $iSel) {
00740 $this->_aChosenSelectlist[$conkey] = new stdClass();
00741 $this->_aChosenSelectlist[$conkey]->name = $aSelectLists[$conkey]['name'];
00742 $this->_aChosenSelectlist[$conkey]->value = $aSelectLists[$conkey][$iSel]->name;
00743 }
00744 }
00745 }
00746
00752 public function getPersParams()
00753 {
00754 return $this->_aPersistentParameters;
00755 }
00756
00762 public function setPersParams($aPersParam)
00763 {
00764 $this->_aPersistentParameters = $aPersParam;
00765 }
00766
00772 public function setBundle($blBundle)
00773 {
00774 $this->_blBundle = $blBundle;
00775 }
00776
00782 public function setSkipDiscounts($blSkip)
00783 {
00784 $this->_blSkipDiscounts = $blSkip;
00785 }
00786
00792 public function getProductId()
00793 {
00794 return $this->_sProductId;
00795 }
00796
00802 public function setWrapping($sWrapId)
00803 {
00804 $this->_sWrappingId = $sWrapId;
00805 }
00806
00812 public function getWrappingId()
00813 {
00814 return $this->_sWrappingId;
00815 }
00816
00822 public function getWrapping()
00823 {
00824 $oWrap = null;
00825 if ($sWrapId = $this->getWrappingId()) {
00826 $oWrap = oxNew('oxwrapping');
00827 $oWrap->load($sWrapId);
00828 }
00829
00830 return $oWrap;
00831 }
00832
00838 public function getWishId()
00839 {
00840 return $this->_sWishId;
00841 }
00842
00848 public function setWishId($sWishId)
00849 {
00850 $this->_sWishId = $sWishId;
00851 }
00852
00858 public function setWishArticleId($sArticleId)
00859 {
00860 $this->_sWishArticleId = $sArticleId;
00861 }
00862
00868 public function getWishArticleId()
00869 {
00870 return $this->_sWishArticleId;
00871 }
00872
00880 public function getFRegularUnitPrice()
00881 {
00882 return oxRegistry::getLang()->formatCurrency($this->getRegularUnitPrice()->getPrice());
00883 }
00884
00892 public function getFUnitPrice()
00893 {
00894 return oxRegistry::getLang()->formatCurrency($this->getUnitPrice()->getPrice());
00895 }
00896
00904 public function getFTotalPrice()
00905 {
00906 return oxRegistry::getLang()->formatCurrency($this->getPrice()->getPrice());
00907 }
00908
00914 public function getVatPercent()
00915 {
00916 return oxRegistry::getLang()->formatVat($this->getPrice()->getVat());
00917 }
00918
00924 public function getVarSelect()
00925 {
00926 if ($this->_sVarSelect === null || $this->getLanguageId() != oxRegistry::getLang()->getBaseLanguage()) {
00927 $oArticle = $this->getArticle();
00928 $this->_sVarSelect = $oArticle->oxarticles__oxvarselect->value ? $oArticle->oxarticles__oxvarselect->value : '';
00929 }
00930
00931 return $this->_sVarSelect;
00932 }
00933
00939 public function getLanguageId()
00940 {
00941 return $this->_iLanguageId;
00942 }
00943
00949 public function setLanguageId($iLanguageId)
00950 {
00951 $iOldLang = $this->_iLanguageId;
00952 $this->_iLanguageId = $iLanguageId;
00953
00954
00955 if ($iOldLang !== null && $iOldLang != $iLanguageId) {
00956 try {
00957 $this->_setArticle($this->getProductId());
00958 } catch (oxNoArticleException $oEx) {
00959 oxRegistry::get("oxUtilsView")->addErrorToDisplay($oEx);
00960 } catch (oxArticleInputException $oEx) {
00961 oxRegistry::get("oxUtilsView")->addErrorToDisplay($oEx);
00962 }
00963 }
00964 }
00965 }