Go to the documentation of this file.00001 <?php
00002
00006 class oxBasketItem extends oxSuperCfg
00007 {
00013 protected $_sProductId = null;
00014
00020 protected $_sTitle = null;
00021
00027 protected $_sVarSelect = null;
00028
00034 protected $_sIcon = null;
00035
00041 protected $_sLink = null;
00042
00048 protected $_oPrice = null;
00049
00055 protected $_oUnitPrice = null;
00056
00062 protected $_dAmount = 0.0;
00063
00069 protected $_dWeight = 0;
00070
00076 protected $_aSelList = array();
00077
00083 protected $_sShopId = null;
00084
00090 protected $_sNativeShopId = null;
00091
00097 protected $_blSkipDiscounts = false;
00098
00104 protected $_aPersistentParameters = array();
00105
00111 protected $_blBundle = false;
00112
00118 protected $_blIsDiscountArticle = false;
00119
00125 protected $_oArticle = null;
00126
00132 protected $_sDimageDirNoSsl = null;
00133
00139 protected $_sDimageDirSsl = null;
00140
00146 protected $_aChosenSelectlist = array();
00147
00153 protected $_sWrappingId = null;
00154
00160 protected $_sWishId = null;
00161
00167 protected $_sWishArticleId = null;
00168
00174 protected $_blCheckArticleStock = true;
00175
00176
00182 protected $_iLanguageId = null;
00183
00189 protected $_blSsl = null;
00190
00196 protected $_sIconUrl = null;
00197
00216 public function init( $sProductID, $dAmount, $aSel = null, $aPersParam = null, $blBundle = null )
00217 {
00218 $this->_setArticle( $sProductID );
00219 $this->setAmount( $dAmount );
00220 $this->_setSelectList( $aSel );
00221 $this->setPersParams( $aPersParam );
00222 $this->setBundle( $blBundle );
00223 $this->setLanguageId( oxLang::getInstance()->getBaseLanguage() );
00224 }
00225
00239 public function initFromOrderArticle( $oOrderArticle )
00240 {
00241 $this->_setFromOrderArticle( $oOrderArticle );
00242 $this->setAmount( $oOrderArticle->oxorderarticles__oxamount->value );
00243 $this->_setSelectList( $oOrderArticle->getOrderArticleSelectList() );
00244 $this->setPersParams( $oOrderArticle->getPersParams() );
00245 $this->setBundle( $oOrderArticle->isBundle() );
00246 }
00247
00255 public function setAsDiscountArticle( $blIsDiscountArticle )
00256 {
00257 $this->_blIsDiscountArticle = $blIsDiscountArticle;
00258 }
00259
00267 public function setStockCheckStatus( $blStatus )
00268 {
00269 $this->_blCheckArticleStock = $blStatus;
00270 }
00271
00277 public function getStockCheckStatus()
00278 {
00279 return $this->_blCheckArticleStock;
00280 }
00281
00294 public function setAmount( $dAmount, $blOverride = true, $sItemKey = null )
00295 {
00296 try {
00297
00298 $dAmount = oxInputValidator::getInstance()->validateBasketAmount( $dAmount );
00299 } catch( oxArticleInputException $oEx ) {
00300 $oEx->setArticleNr( $this->getProductId() );
00301 $oEx->setProductId( $this->getProductId() );
00302
00303 throw $oEx;
00304 }
00305
00306 $oArticle = $this->getArticle( true );
00307
00308
00309
00310 $iOnStock = true;
00311
00312 if ( $blOverride ) {
00313 $this->_dAmount = $dAmount;
00314 } else {
00315 $this->_dAmount += $dAmount;
00316 }
00317
00318
00319 if ( $this->getStockCheckStatus() == true ) {
00320 $dArtStockAmount = $this->getSession()->getBasket()->getArtStockInBasket( $oArticle->getId(), $sItemKey );
00321 $iOnStock = $oArticle->checkForStock( $this->_dAmount, $dArtStockAmount );
00322 if ( $iOnStock !== true ) {
00323 if ( $iOnStock === false ) {
00324
00325 $this->_dAmount = 0;
00326 } else {
00327
00328 $this->_dAmount = $iOnStock;
00329 $blOverride = true;
00330 }
00331 }
00332 }
00333
00334
00335 $this->_dWeight = $oArticle->oxarticles__oxweight->value * $this->_dAmount;
00336
00337 if ( $iOnStock !== true ) {
00338 $oEx = oxNew( 'oxOutOfStockException' );
00339 $oEx->setMessage( 'EXCEPTION_OUTOFSTOCK_OUTOFSTOCK' );
00340 $oEx->setArticleNr( $oArticle->oxarticles__oxartnum->value );
00341 $oEx->setProductId( $oArticle->getProductId() );
00342 $oEx->setRemainingAmount( $this->_dAmount );
00343 $oEx->setBasketIndex( $sItemKey );
00344 throw $oEx;
00345 }
00346 }
00347
00355 public function setPrice( $oPrice )
00356 {
00357 $this->_oPrice = oxNew( 'oxprice' );
00358 $this->_oPrice->setBruttoPriceMode();
00359 $this->_oPrice->setVat( $oPrice->getVAT() );
00360 $this->_oPrice->addPrice( $oPrice );
00361 $this->_oPrice->multiply( $this->getAmount() );
00362
00363 $this->_oUnitPrice = oxNew( 'oxprice' );
00364 $this->_oUnitPrice->setBruttoPriceMode();
00365 $this->_oUnitPrice->setVat( $oPrice->getVAT() );
00366 $this->_oUnitPrice->addPrice( $oPrice );
00367 }
00368
00376 public function getImageUrl()
00377 {
00378 $blIsSSl = $this->getConfig()->isSsl();
00379 if ( $blIsSSl ) {
00380 return $this->_sDimageDirSsl;
00381 } else {
00382 return $this->_sDimageDirNoSsl;
00383 }
00384 }
00385
00391 public function getIconUrl()
00392 {
00393
00394 if ( $this->_sIconUrl === null || $this->_blSsl != $this->getConfig()->isSsl() ) {
00395 $this->_sIconUrl = $this->getArticle()->getIconUrl();
00396 }
00397 return $this->_sIconUrl;
00398 }
00399
00412 public function getArticle( $blCheckProduct = true, $sProductId = null, $blDisableLazyLoading = false )
00413 {
00414 if ( $this->_oArticle === null || ( !$this->_oArticle->isOrderArticle() && $blDisableLazyLoading ) ) {
00415 $sProductId = $sProductId ? $sProductId : $this->_sProductId;
00416 if ( !$sProductId ) {
00417
00418 $oEx = oxNew( 'oxArticleException' );
00419 $oEx->setMessage( 'EXCEPTION_ARTICLE_NOPRODUCTID' );
00420 throw $oEx;
00421 }
00422
00423 $this->_oArticle = oxNew( 'oxarticle' );
00424
00425 if ( $blDisableLazyLoading ) {
00426 $this->_oArticle->modifyCacheKey('_allviews');
00427 $this->_oArticle->disableLazyLoading();
00428 }
00429
00430
00431
00432
00433
00434 $this->_oArticle->setNoVariantLoading( true );
00435 $this->_oArticle->setSkipAbPrice( true );
00436 $this->_oArticle->setLoadParentData( true );
00437 if ( !$this->_oArticle->load( $sProductId ) ) {
00438 $oEx = oxNew( 'oxNoArticleException' );
00439 $oLang = oxLang::getInstance();
00440 $oEx->setMessage( sprintf($oLang->translateString( 'EXCEPTION_ARTICLE_ARTICELDOESNOTEXIST', $oLang->getBaseLanguage() ), $sProductId) );
00441 $oEx->setArticleNr( $sProductId );
00442 $oEx->setProductId( $sProductId );
00443 throw $oEx;
00444 }
00445
00446
00447 if ( $blCheckProduct && !$this->_oArticle->isVisible() ) {
00448 $oEx = oxNew( 'oxNoArticleException' );
00449 $oLang = oxLang::getInstance();
00450 $oEx->setMessage( sprintf($oLang->translateString( 'EXCEPTION_ARTICLE_ARTICELDOESNOTEXIST', $oLang->getBaseLanguage() ), $this->_oArticle->oxarticles__oxartnum->value) );
00451 $oEx->setArticleNr( $sProductId );
00452 $oEx->setProductId( $sProductId );
00453 throw $oEx;
00454 }
00455
00456
00457 if ( $blCheckProduct && !$this->_oArticle->isBuyable() ) {
00458 $oEx = oxNew( 'oxArticleInputException' );
00459 $oEx->setMessage( 'EXCEPTION_ARTICLE_ARTICELNOTBUYABLE' );
00460 $oEx->setArticleNr( $sProductId );
00461 $oEx->setProductId( $sProductId );
00462 throw $oEx;
00463 }
00464 }
00465
00466 return $this->_oArticle;
00467 }
00468
00474 public function getdBundledAmount()
00475 {
00476 return $this->isBundle()?$this->_dAmount:0;
00477 }
00478
00484 public function getPrice()
00485 {
00486 return $this->_oPrice;
00487 }
00488
00494 public function getUnitPrice()
00495 {
00496 return $this->_oUnitPrice;
00497 }
00498
00504 public function getAmount()
00505 {
00506 return $this->_dAmount;
00507 }
00508
00514 public function getWeight()
00515 {
00516 return $this->_dWeight;
00517 }
00518
00524 public function getTitle()
00525 {
00526 if ( $this->_sTitle === null || $this->getLanguageId() != oxLang::getInstance()->getBaseLanguage() ) {
00527
00528 $oArticle = $this->getArticle( );
00529 $this->_sTitle = $oArticle->oxarticles__oxtitle->value;
00530
00531 if ( $oArticle->oxarticles__oxvarselect->value ) {
00532 $this->_sTitle = $this->_sTitle. ', ' . $this->getVarSelect();
00533 }
00534 }
00535
00536 return $this->_sTitle;
00537 }
00538
00546 public function getIcon()
00547 {
00548 return $this->_sIcon;
00549 }
00550
00556 public function getLink()
00557 {
00558 if ( $this->_sLink === null || $this->getLanguageId() != oxLang::getInstance()->getBaseLanguage() ) {
00559 $this->_sLink = oxUtilsUrl::getInstance()->cleanUrl( $this->getArticle()->getLink(), array( 'force_sid' ) );
00560 }
00561
00562 return $this->getSession()->processUrl( $this->_sLink );
00563 }
00564
00570 public function getShopId()
00571 {
00572 return $this->_sShopId;
00573 }
00574
00580 public function getSelList()
00581 {
00582 return $this->_aSelList;
00583 }
00584
00590 public function getChosenSelList()
00591 {
00592 return $this->_aChosenSelectlist;
00593 }
00594
00600 public function isBundle()
00601 {
00602 return $this->_blBundle;
00603 }
00604
00610 public function isDiscountArticle()
00611 {
00612 return $this->_blIsDiscountArticle;
00613 }
00614
00620 public function isSkipDiscount()
00621 {
00622 return $this->_blSkipDiscounts;
00623 }
00624
00634 public function __get( $sName )
00635 {
00636 if ( $sName == 'oProduct' ) {
00637 return $this->getArticle();
00638 }
00639 }
00640
00646 public function __sleep()
00647 {
00648 $aRet = array();
00649 foreach ( get_object_vars( $this ) as $sKey => $sVar ) {
00650 if ( $sKey != '_oArticle' ) {
00651 $aRet[] = $sKey;
00652 }
00653 }
00654 return $aRet;
00655 }
00656
00674 protected function _setArticle( $sProductId )
00675 {
00676 $oConfig = $this->getConfig();
00677 $oArticle = $this->getArticle( true, $sProductId );
00678
00679
00680 $this->_sProductId = $sProductId;
00681
00682 $this->_sTitle = null;
00683 $this->_sVarSelect = null;
00684 $this->getTitle();
00685
00686
00687 $this->_sIcon = $oArticle->oxarticles__oxicon->value;
00688 $this->_sIconUrl = $oArticle->getIconUrl();
00689 $this->_blSsl = $oConfig->isSsl();
00690
00691
00692 $this->_sLink = oxUtilsUrl::getInstance()->cleanUrl( $oArticle->getLink(), array( 'force_sid' ) );
00693
00694
00695 $this->_sShopId = $oConfig->getShopId();
00696 $this->_sNativeShopId = $oArticle->oxarticles__oxshopid->value;
00697
00698
00699 $this->_sDimageDirNoSsl = $oArticle->nossl_dimagedir;
00700 $this->_sDimageDirSsl = $oArticle->ssl_dimagedir;
00701 }
00702
00714 protected function _setFromOrderArticle( $oOrderArticle )
00715 {
00716
00717 $this->_oArticle = $oOrderArticle;
00718
00719
00720 $this->_sProductId = $oOrderArticle->getProductId();
00721
00722
00723 $this->_sTitle = $oOrderArticle->oxarticles__oxtitle->value;
00724
00725
00726 $this->_sShopId = $this->getConfig()->getShopId();
00727 $this->_sNativeShopId = $oOrderArticle->oxarticles__oxshopid->value;
00728 }
00729
00737 protected function _setSelectList( $aSelList )
00738 {
00739
00740 $aSelectLists = $this->getArticle()->getSelectLists();
00741 if ( !$aSelList || is_array($aSelList) && count($aSelList) == 0 ) {
00742 if ( $iSelCnt = count( $aSelectLists ) ) {
00743 $aSelList = array_fill( 0, $iSelCnt, '0' );
00744 }
00745 }
00746
00747 $this->_aSelList = $aSelList;
00748
00749
00750 if ( count( $this->_aSelList ) && is_array($this->_aSelList) ) {
00751 foreach ( $this->_aSelList as $conkey => $iSel ) {
00752 $this->_aChosenSelectlist[$conkey] = new Oxstdclass();
00753 $this->_aChosenSelectlist[$conkey]->name = $aSelectLists[$conkey]['name'];
00754 $this->_aChosenSelectlist[$conkey]->value = $aSelectLists[$conkey][$iSel]->name;
00755 }
00756 }
00757 }
00758
00764 public function getPersParams()
00765 {
00766 return $this->_aPersistentParameters;
00767 }
00768
00776 public function setPersParams( $aPersParam )
00777 {
00778 $this->_aPersistentParameters = $aPersParam;
00779 }
00780
00788 public function setBundle( $blBundle )
00789 {
00790 $this->_blBundle = $blBundle;
00791 }
00792
00800 public function setSkipDiscounts( $blSkip )
00801 {
00802 $this->_blSkipDiscounts = $blSkip;
00803 }
00804
00810 public function getProductId()
00811 {
00812 return $this->_sProductId;
00813 }
00814
00822 public function setWrapping( $sWrapId )
00823 {
00824 $this->_sWrappingId = $sWrapId;
00825 }
00826
00832 public function getWrappingId()
00833 {
00834 return $this->_sWrappingId;
00835 }
00836
00842 public function getWrapping()
00843 {
00844 $oWrap = null;
00845 if ( $sWrapId = $this->getWrappingId() ) {
00846 $oWrap = oxNew( 'oxwrapping' );
00847 $oWrap->load( $sWrapId );
00848 }
00849 return $oWrap;
00850 }
00851
00857 public function getWishId()
00858 {
00859 return $this->_sWishId;
00860 }
00861
00869 public function setWishId( $sWishId )
00870 {
00871 $this->_sWishId = $sWishId;
00872 }
00873
00881 public function setWishArticleId( $sArticleId )
00882 {
00883 $this->_sWishArticleId = $sArticleId;
00884 }
00885
00891 public function getWishArticleId()
00892 {
00893 return $this->_sWishArticleId;
00894 }
00895
00901 public function getFUnitPrice()
00902 {
00903 return oxLang::getInstance()->formatCurrency( $this->getUnitPrice()->getBruttoPrice() );
00904 }
00905
00911 public function getFTotalPrice()
00912 {
00913 return oxLang::getInstance()->formatCurrency( $this->getPrice()->getBruttoPrice() );
00914 }
00915
00921 public function getVatPercent()
00922 {
00923 return oxLang::getInstance()->formatVat( $this->getPrice()->getVat() );
00924 }
00925
00931 public function getVarSelect()
00932 {
00933 if ( $this->_sVarSelect === null || $this->getLanguageId() != oxLang::getInstance()->getBaseLanguage() ) {
00934 $oArticle = $this->getArticle( );
00935 $this->_sVarSelect = $oArticle->oxarticles__oxvarselect->value ? $oArticle->oxarticles__oxvarselect->value : '';
00936 }
00937
00938 return $this->_sVarSelect;
00939 }
00940
00946 public function getLanguageId()
00947 {
00948 return $this->_iLanguageId;
00949 }
00950
00958 public function setLanguageId( $iLanguageId )
00959 {
00960 $iOldLang = $this->_iLanguageId;
00961 $this->_iLanguageId = $iLanguageId;
00962
00963
00964 if ($iOldLang !== null && $iOldLang != $iLanguageId) {
00965 $this->_setArticle($this->getProductId());
00966 }
00967 }
00968 }