Go to the documentation of this file.00001 <?php
00002
00007 class oxBasketItem extends oxSuperCfg
00008 {
00014 protected $_sProductId = null;
00015
00021 protected $_sTitle = null;
00022
00028 protected $_sVarSelect = null;
00029
00035 protected $_sIcon = null;
00036
00042 protected $_sLink = null;
00043
00049 protected $_oPrice = null;
00050
00056 protected $_oUnitPrice = null;
00057
00063 protected $_dAmount = 0.0;
00064
00070 protected $_dWeight = 0;
00071
00077 protected $_aSelList = array();
00078
00084 protected $_sShopId = null;
00085
00091 protected $_sNativeShopId = null;
00092
00098 protected $_blSkipDiscounts = false;
00099
00105 protected $_aPersistentParameters = array();
00106
00112 protected $_blBundle = false;
00113
00119 protected $_blIsDiscountArticle = false;
00120
00126 protected $_oArticle = null;
00127
00133 protected $_sDimageDirNoSsl = null;
00134
00140 protected $_sDimageDirSsl = null;
00141
00147 protected $_aChosenSelectlist = array();
00148
00154 protected $_sWrappingId = null;
00155
00161 protected $_sWishId = null;
00162
00168 protected $_sWishArticleId = null;
00169
00175 protected $_blCheckArticleStock = true;
00176
00177
00183 protected $_iLanguageId = null;
00184
00190 protected $_blSsl = null;
00191
00197 protected $_sIconUrl = null;
00198
00199
00205 protected $_oRegularUnitPrice = null;
00206
00207
00213 public function getRegularUnitPrice()
00214 {
00215 return $this->_oRegularUnitPrice;
00216 }
00217
00225 public function setRegularUnitPrice( $oRegularUnitPrice )
00226 {
00227 $this->_oRegularUnitPrice = $oRegularUnitPrice;
00228 }
00229
00230
00249 public function init( $sProductID, $dAmount, $aSel = null, $aPersParam = null, $blBundle = null )
00250 {
00251 $this->_setArticle( $sProductID );
00252 $this->setAmount( $dAmount );
00253 $this->_setSelectList( $aSel );
00254 $this->setPersParams( $aPersParam );
00255 $this->setBundle( $blBundle );
00256 $this->setLanguageId( oxRegistry::getLang()->getBaseLanguage() );
00257 }
00258
00272 public function initFromOrderArticle( $oOrderArticle )
00273 {
00274 $this->_setFromOrderArticle( $oOrderArticle );
00275 $this->setAmount( $oOrderArticle->oxorderarticles__oxamount->value );
00276 $this->_setSelectList( $oOrderArticle->getOrderArticleSelectList() );
00277 $this->setPersParams( $oOrderArticle->getPersParams() );
00278 $this->setBundle( $oOrderArticle->isBundle() );
00279 }
00280
00288 public function setAsDiscountArticle( $blIsDiscountArticle )
00289 {
00290 $this->_blIsDiscountArticle = $blIsDiscountArticle;
00291 }
00292
00300 public function setStockCheckStatus( $blStatus )
00301 {
00302 $this->_blCheckArticleStock = $blStatus;
00303 }
00304
00310 public function getStockCheckStatus()
00311 {
00312 return $this->_blCheckArticleStock;
00313 }
00314
00327 public function setAmount( $dAmount, $blOverride = true, $sItemKey = null )
00328 {
00329 try {
00330
00331 $dAmount = oxRegistry::get("oxInputValidator")->validateBasketAmount( $dAmount );
00332 } catch( oxArticleInputException $oEx ) {
00333 $oEx->setArticleNr( $this->getProductId() );
00334 $oEx->setProductId( $this->getProductId() );
00335
00336 throw $oEx;
00337 }
00338
00339 $oArticle = $this->getArticle( true );
00340
00341
00342
00343 $iOnStock = true;
00344
00345 if ( $blOverride ) {
00346 $this->_dAmount = $dAmount;
00347 } else {
00348 $this->_dAmount += $dAmount;
00349 }
00350
00351
00352 if ( $this->getStockCheckStatus() == true ) {
00353 $dArtStockAmount = $this->getSession()->getBasket()->getArtStockInBasket( $oArticle->getId(), $sItemKey );
00354 $iOnStock = $oArticle->checkForStock( $this->_dAmount, $dArtStockAmount );
00355 if ( $iOnStock !== true ) {
00356 if ( $iOnStock === false ) {
00357
00358 $this->_dAmount = 0;
00359 } else {
00360
00361 $this->_dAmount = $iOnStock;
00362 $blOverride = true;
00363 }
00364 }
00365 }
00366
00367
00368 $this->_dWeight = $oArticle->oxarticles__oxweight->value * $this->_dAmount;
00369
00370 if ( $iOnStock !== true ) {
00371 $oEx = oxNew( 'oxOutOfStockException' );
00372 $oEx->setMessage( 'ERROR_MESSAGE_OUTOFSTOCK_OUTOFSTOCK' );
00373 $oEx->setArticleNr( $oArticle->oxarticles__oxartnum->value );
00374 $oEx->setProductId( $oArticle->getProductId() );
00375 $oEx->setRemainingAmount( $this->_dAmount );
00376 $oEx->setBasketIndex( $sItemKey );
00377 throw $oEx;
00378 }
00379 }
00380
00388 public function setPrice( $oPrice )
00389 {
00390 $this->_oUnitPrice = clone $oPrice;
00391
00392 $this->_oPrice = clone $oPrice;
00393 $this->_oPrice->multiply( $this->getAmount() );
00394 }
00395
00401 public function getIconUrl()
00402 {
00403
00404 if ( $this->_sIconUrl === null || $this->_blSsl != $this->getConfig()->isSsl() ) {
00405 $this->_sIconUrl = $this->getArticle()->getIconUrl();
00406 }
00407 return $this->_sIconUrl;
00408 }
00409
00422 public function getArticle( $blCheckProduct = false, $sProductId = null, $blDisableLazyLoading = false )
00423 {
00424 if ( $this->_oArticle === null || ( !$this->_oArticle->isOrderArticle() && $blDisableLazyLoading ) ) {
00425 $sProductId = $sProductId ? $sProductId : $this->_sProductId;
00426 if ( !$sProductId ) {
00427
00428 $oEx = oxNew( 'oxArticleException' );
00429 $oEx->setMessage( 'EXCEPTION_ARTICLE_NOPRODUCTID' );
00430 throw $oEx;
00431 }
00432
00433 $this->_oArticle = oxNew( 'oxarticle' );
00434
00435 if ( $blDisableLazyLoading ) {
00436 $this->_oArticle->modifyCacheKey('_allviews');
00437 $this->_oArticle->disableLazyLoading();
00438 }
00439
00440
00441
00442
00443
00444 $this->_oArticle->setNoVariantLoading( true );
00445 $this->_oArticle->setLoadParentData( true );
00446 if ( !$this->_oArticle->load( $sProductId ) ) {
00447 $oEx = oxNew( 'oxNoArticleException' );
00448 $oLang = oxRegistry::getLang();
00449 $oEx->setMessage( sprintf($oLang->translateString( 'ERROR_MESSAGE_ARTICLE_ARTICLE_DOES_NOT_EXIST', $oLang->getBaseLanguage() ), $sProductId) );
00450 $oEx->setArticleNr( $sProductId );
00451 $oEx->setProductId( $sProductId );
00452 throw $oEx;
00453 }
00454
00455
00456 if ( $blCheckProduct && !$this->_oArticle->isVisible() ) {
00457 $oEx = oxNew( 'oxNoArticleException' );
00458 $oLang = oxRegistry::getLang();
00459 $oEx->setMessage( sprintf($oLang->translateString( 'ERROR_MESSAGE_ARTICLE_ARTICLE_DOES_NOT_EXIST', $oLang->getBaseLanguage() ), $this->_oArticle->oxarticles__oxartnum->value) );
00460 $oEx->setArticleNr( $sProductId );
00461 $oEx->setProductId( $sProductId );
00462 throw $oEx;
00463 }
00464
00465
00466 if ( $blCheckProduct && !$this->_oArticle->isBuyable() ) {
00467 $oEx = oxNew( 'oxArticleInputException' );
00468 $oEx->setMessage( 'ERROR_MESSAGE_ARTICLE_ARTICLE_NOT_BUYABLE' );
00469 $oEx->setArticleNr( $sProductId );
00470 $oEx->setProductId( $sProductId );
00471 throw $oEx;
00472 }
00473 }
00474
00475 return $this->_oArticle;
00476 }
00477
00483 public function getdBundledAmount()
00484 {
00485 return $this->isBundle()?$this->_dAmount:0;
00486 }
00487
00493 public function getPrice()
00494 {
00495 return $this->_oPrice;
00496 }
00497
00503 public function getUnitPrice()
00504 {
00505 return $this->_oUnitPrice;
00506 }
00507
00513 public function getAmount()
00514 {
00515 return $this->_dAmount;
00516 }
00517
00523 public function getWeight()
00524 {
00525 return $this->_dWeight;
00526 }
00527
00533 public function getTitle()
00534 {
00535 if ( $this->_sTitle === null || $this->getLanguageId() != oxRegistry::getLang()->getBaseLanguage() ) {
00536
00537 $oArticle = $this->getArticle( );
00538 $this->_sTitle = $oArticle->oxarticles__oxtitle->value;
00539
00540 if ( $oArticle->oxarticles__oxvarselect->value ) {
00541 $this->_sTitle = $this->_sTitle. ', ' . $this->getVarSelect();
00542 }
00543 }
00544
00545 return $this->_sTitle;
00546 }
00547
00553 public function getLink()
00554 {
00555 if ( $this->_sLink === null || $this->getLanguageId() != oxRegistry::getLang()->getBaseLanguage() ) {
00556 $this->_sLink = oxRegistry::get("oxUtilsUrl")->cleanUrl( $this->getArticle()->getLink(), array( 'force_sid' ) );
00557 }
00558
00559 return $this->getSession()->processUrl( $this->_sLink );
00560 }
00561
00567 public function getShopId()
00568 {
00569 return $this->_sShopId;
00570 }
00571
00577 public function getSelList()
00578 {
00579 return $this->_aSelList;
00580 }
00581
00587 public function getChosenSelList()
00588 {
00589 return $this->_aChosenSelectlist;
00590 }
00591
00597 public function isBundle()
00598 {
00599 return $this->_blBundle;
00600 }
00601
00607 public function isDiscountArticle()
00608 {
00609 return $this->_blIsDiscountArticle;
00610 }
00611
00617 public function isSkipDiscount()
00618 {
00619 return $this->_blSkipDiscounts;
00620 }
00621
00631 public function __get( $sName )
00632 {
00633 if ( $sName == 'oProduct' ) {
00634 return $this->getArticle();
00635 }
00636 }
00637
00643 public function __sleep()
00644 {
00645 $aRet = array();
00646 foreach ( get_object_vars( $this ) as $sKey => $sVar ) {
00647 if ( $sKey != '_oArticle' ) {
00648 $aRet[] = $sKey;
00649 }
00650 }
00651 return $aRet;
00652 }
00653
00671 protected function _setArticle( $sProductId )
00672 {
00673 $oConfig = $this->getConfig();
00674 $oArticle = $this->getArticle( true, $sProductId );
00675
00676
00677 $this->_sProductId = $sProductId;
00678
00679 $this->_sTitle = null;
00680 $this->_sVarSelect = null;
00681 $this->getTitle();
00682
00683
00684 $this->_sIcon = $oArticle->oxarticles__oxicon->value;
00685 $this->_sIconUrl = $oArticle->getIconUrl();
00686 $this->_blSsl = $oConfig->isSsl();
00687
00688
00689 $this->_sLink = oxRegistry::get("oxUtilsUrl")->cleanUrl( $oArticle->getLink(), array( 'force_sid' ) );
00690
00691
00692 $this->_sShopId = $oConfig->getShopId();
00693 $this->_sNativeShopId = $oArticle->oxarticles__oxshopid->value;
00694
00695
00696 $this->_sDimageDirNoSsl = $oArticle->nossl_dimagedir;
00697 $this->_sDimageDirSsl = $oArticle->ssl_dimagedir;
00698 }
00699
00711 protected function _setFromOrderArticle( $oOrderArticle )
00712 {
00713
00714 $this->_oArticle = $oOrderArticle;
00715
00716
00717 $this->_sProductId = $oOrderArticle->getProductId();
00718
00719
00720 $this->_sTitle = $oOrderArticle->oxarticles__oxtitle->value;
00721
00722
00723 $this->_sShopId = $this->getConfig()->getShopId();
00724 $this->_sNativeShopId = $oOrderArticle->oxarticles__oxshopid->value;
00725 }
00726
00734 protected function _setSelectList( $aSelList )
00735 {
00736
00737 $aSelectLists = $this->getArticle()->getSelectLists();
00738 if ( !$aSelList || is_array($aSelList) && count($aSelList) == 0 ) {
00739 if ( $iSelCnt = count( $aSelectLists ) ) {
00740 $aSelList = array_fill( 0, $iSelCnt, '0' );
00741 }
00742 }
00743
00744 $this->_aSelList = $aSelList;
00745
00746
00747 if ( count( $this->_aSelList ) && is_array($this->_aSelList) ) {
00748 foreach ( $this->_aSelList as $conkey => $iSel ) {
00749 $this->_aChosenSelectlist[$conkey] = new stdClass();
00750 $this->_aChosenSelectlist[$conkey]->name = $aSelectLists[$conkey]['name'];
00751 $this->_aChosenSelectlist[$conkey]->value = $aSelectLists[$conkey][$iSel]->name;
00752 }
00753 }
00754 }
00755
00761 public function getPersParams()
00762 {
00763 return $this->_aPersistentParameters;
00764 }
00765
00773 public function setPersParams( $aPersParam )
00774 {
00775 $this->_aPersistentParameters = $aPersParam;
00776 }
00777
00785 public function setBundle( $blBundle )
00786 {
00787 $this->_blBundle = $blBundle;
00788 }
00789
00797 public function setSkipDiscounts( $blSkip )
00798 {
00799 $this->_blSkipDiscounts = $blSkip;
00800 }
00801
00807 public function getProductId()
00808 {
00809 return $this->_sProductId;
00810 }
00811
00819 public function setWrapping( $sWrapId )
00820 {
00821 $this->_sWrappingId = $sWrapId;
00822 }
00823
00829 public function getWrappingId()
00830 {
00831 return $this->_sWrappingId;
00832 }
00833
00839 public function getWrapping()
00840 {
00841 $oWrap = null;
00842 if ( $sWrapId = $this->getWrappingId() ) {
00843 $oWrap = oxNew( 'oxwrapping' );
00844 $oWrap->load( $sWrapId );
00845 }
00846 return $oWrap;
00847 }
00848
00854 public function getWishId()
00855 {
00856 return $this->_sWishId;
00857 }
00858
00866 public function setWishId( $sWishId )
00867 {
00868 $this->_sWishId = $sWishId;
00869 }
00870
00878 public function setWishArticleId( $sArticleId )
00879 {
00880 $this->_sWishArticleId = $sArticleId;
00881 }
00882
00888 public function getWishArticleId()
00889 {
00890 return $this->_sWishArticleId;
00891 }
00892
00900 public function getFRegularUnitPrice()
00901 {
00902 return oxRegistry::getLang()->formatCurrency( $this->getRegularUnitPrice()->getPrice() );
00903 }
00904
00912 public function getFUnitPrice()
00913 {
00914 return oxRegistry::getLang()->formatCurrency( $this->getUnitPrice()->getPrice() );
00915 }
00916
00924 public function getFTotalPrice()
00925 {
00926 return oxRegistry::getLang()->formatCurrency( $this->getPrice()->getPrice() );
00927 }
00928
00934 public function getVatPercent()
00935 {
00936 return oxRegistry::getLang()->formatVat( $this->getPrice()->getVat() );
00937 }
00938
00944 public function getVarSelect()
00945 {
00946 if ( $this->_sVarSelect === null || $this->getLanguageId() != oxRegistry::getLang()->getBaseLanguage() ) {
00947 $oArticle = $this->getArticle( );
00948 $this->_sVarSelect = $oArticle->oxarticles__oxvarselect->value ? $oArticle->oxarticles__oxvarselect->value : '';
00949 }
00950
00951 return $this->_sVarSelect;
00952 }
00953
00959 public function getLanguageId()
00960 {
00961 return $this->_iLanguageId;
00962 }
00963
00971 public function setLanguageId( $iLanguageId )
00972 {
00973 $iOldLang = $this->_iLanguageId;
00974 $this->_iLanguageId = $iLanguageId;
00975
00976
00977 if ($iOldLang !== null && $iOldLang != $iLanguageId) {
00978 $this->_setArticle($this->getProductId());
00979 }
00980 }
00981 }