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
00202 public function init( $sProductID, $dAmount, $aSel = null, $aPersParam = null, $blBundle = null )
00203 {
00204 $this->_setArticle( $sProductID );
00205 $this->setAmount( $dAmount );
00206 $this->_setSelectList( $aSel );
00207 $this->setPersParams( $aPersParam );
00208 $this->setBundle( $blBundle );
00209 $this->setLanguageId( oxLang::getInstance()->getBaseLanguage() );
00210 }
00211
00225 public function initFromOrderArticle( $oOrderArticle )
00226 {
00227 $this->_setFromOrderArticle( $oOrderArticle );
00228 $this->setAmount( $oOrderArticle->oxorderarticles__oxamount->value );
00229 $this->_setSelectList( $oOrderArticle->getOrderArticleSelectList() );
00230 $this->setPersParams( $oOrderArticle->getPersParams() );
00231 $this->setBundle( $oOrderArticle->isBundle() );
00232 }
00233
00241 public function setAsDiscountArticle( $blIsDiscountArticle )
00242 {
00243 $this->_blIsDiscountArticle = $blIsDiscountArticle;
00244 }
00245
00253 public function setStockCheckStatus( $blStatus )
00254 {
00255 $this->_blCheckArticleStock = $blStatus;
00256 }
00257
00263 public function getStockCheckStatus()
00264 {
00265 return $this->_blCheckArticleStock;
00266 }
00267
00280 public function setAmount( $dAmount, $blOverride = true, $sItemKey = null )
00281 {
00282 try {
00283
00284 $dAmount = oxInputValidator::getInstance()->validateBasketAmount( $dAmount );
00285 } catch( oxArticleInputException $oEx ) {
00286 $oEx->setArticleNr( $this->getProductId() );
00287 $oEx->setProductId( $this->getProductId() );
00288
00289 throw $oEx;
00290 }
00291
00292 $oArticle = $this->getArticle();
00293
00294
00295
00296 $iOnStock = true;
00297
00298 if ( $blOverride ) {
00299 $this->_dAmount = $dAmount;
00300 } else {
00301 $this->_dAmount += $dAmount;
00302 }
00303
00304
00305 if ( $this->getStockCheckStatus() == true ) {
00306 $dArtStockAmount = $this->getSession()->getBasket()->getArtStockInBasket( $oArticle->getId(), $sItemKey );
00307 $iOnStock = $oArticle->checkForStock( $this->_dAmount, $dArtStockAmount );
00308 if ( $iOnStock !== true ) {
00309 if ( $iOnStock === false ) {
00310
00311 $this->_dAmount = 0;
00312 } else {
00313
00314 $this->_dAmount = $iOnStock;
00315 $blOverride = true;
00316 }
00317 }
00318 }
00319
00320
00321 $this->_dWeight = $oArticle->oxarticles__oxweight->value * $this->_dAmount;
00322
00323 if ( $iOnStock !== true ) {
00324 $oEx = oxNew( 'oxOutOfStockException' );
00325 $oEx->setMessage( 'EXCEPTION_OUTOFSTOCK_OUTOFSTOCK' );
00326 $oEx->setArticleNr( $oArticle->oxarticles__oxartnum->value );
00327 $oEx->setProductId( $oArticle->getProductId() );
00328 $oEx->setRemainingAmount( $this->_dAmount );
00329 throw $oEx;
00330 }
00331 }
00332
00340 public function setPrice( $oPrice )
00341 {
00342 $this->_oPrice = oxNew( 'oxprice' );
00343 $this->_oPrice->setBruttoPriceMode();
00344 $this->_oPrice->setVat( $oPrice->getVAT() );
00345 $this->_oPrice->addPrice( $oPrice );
00346 $this->_oPrice->multiply( $this->getAmount() );
00347
00348 $this->_oUnitPrice = oxNew( 'oxprice' );
00349 $this->_oUnitPrice->setBruttoPriceMode();
00350 $this->_oUnitPrice->setVat( $oPrice->getVAT() );
00351 $this->_oUnitPrice->addPrice( $oPrice );
00352 }
00353
00359 public function getImageUrl()
00360 {
00361 $blIsSSl = $this->getConfig()->isSsl();
00362 if ( $blIsSSl ) {
00363 return $this->_sDimageDirSsl;
00364 } else {
00365 return $this->_sDimageDirNoSsl;
00366 }
00367 }
00368
00374 public function getIconUrl()
00375 {
00376 return $this->getConfig()->getIconUrl( $this->getIcon() );
00377 }
00378
00391 public function getArticle( $blCheckProduct = true, $sProductId = null, $blDisableLazyLoading = false )
00392 {
00393 if ( $this->_oArticle === null || ( !$this->_oArticle->isOrderArticle() && $blDisableLazyLoading ) ) {
00394 $sProductId = $sProductId ? $sProductId : $this->_sProductId;
00395 if ( !$sProductId ) {
00396
00397 $oEx = oxNew( 'oxArticleException' );
00398 $oEx->setMessage( 'EXCEPTION_ARTICLE_NOPRODUCTID' );
00399 throw $oEx;
00400 }
00401
00402 $this->_oArticle = oxNew( 'oxarticle' );
00403
00404 if ( $blDisableLazyLoading ) {
00405 $this->_oArticle->modifyCacheKey('_allviews');
00406 $this->_oArticle->disableLazyLoading();
00407 }
00408
00409
00410
00411
00412
00413 $this->_oArticle->setNoVariantLoading( true );
00414 $this->_oArticle->setSkipAbPrice( true );
00415 $this->_oArticle->setLoadParentData( true );
00416 if ( !$this->_oArticle->load( $sProductId ) ) {
00417 $oEx = oxNew( 'oxNoArticleException' );
00418 $oLang = oxLang::getInstance();
00419 $oEx->setMessage( sprintf($oLang->translateString( 'EXCEPTION_ARTICLE_ARTICELDOESNOTEXIST', $oLang->getBaseLanguage() ), $sProductId) );
00420 $oEx->setArticleNr( $sProductId );
00421 $oEx->setProductId( $sProductId );
00422 throw $oEx;
00423 }
00424
00425
00426 if ( $blCheckProduct && !$this->_oArticle->isVisible() ) {
00427 $oEx = oxNew( 'oxNoArticleException' );
00428 $oLang = oxLang::getInstance();
00429 $oEx->setMessage( sprintf($oLang->translateString( 'EXCEPTION_ARTICLE_ARTICELDOESNOTEXIST', $oLang->getBaseLanguage() ), $this->_oArticle->oxarticles__oxartnum->value) );
00430 $oEx->setArticleNr( $sProductId );
00431 $oEx->setProductId( $sProductId );
00432 throw $oEx;
00433 }
00434
00435
00436 if ( $blCheckProduct && !$this->_oArticle->isBuyable() ) {
00437 $oEx = oxNew( 'oxArticleInputException' );
00438 $oEx->setMessage( 'EXCEPTION_ARTICLE_ARTICELNOTBUYABLE' );
00439 $oEx->setArticleNr( $sProductId );
00440 $oEx->setProductId( $sProductId );
00441 throw $oEx;
00442 }
00443 }
00444
00445 return $this->_oArticle;
00446 }
00447
00453 public function getdBundledAmount()
00454 {
00455 return $this->isBundle()?$this->_dAmount:0;
00456 }
00457
00463 public function getPrice()
00464 {
00465 return $this->_oPrice;
00466 }
00467
00473 public function getUnitPrice()
00474 {
00475 return $this->_oUnitPrice;
00476 }
00477
00483 public function getAmount()
00484 {
00485 return $this->_dAmount;
00486 }
00487
00493 public function getWeight()
00494 {
00495 return $this->_dWeight;
00496 }
00497
00503 public function getTitle()
00504 {
00505 if ( $this->_sTitle === null || $this->getLanguageId() != oxLang::getInstance()->getBaseLanguage() ) {
00506
00507 $this->setLanguageId( oxLang::getInstance()->getBaseLanguage() );
00508
00509 $oArticle = $this->getArticle( );
00510 $this->_sTitle = $oArticle->oxarticles__oxtitle->value;
00511
00512 if ( $oArticle->oxarticles__oxvarselect->value ) {
00513 $this->_sTitle = $this->_sTitle. ', ' . $this->getVarSelect();
00514 }
00515 }
00516
00517 return $this->_sTitle;
00518 }
00519
00525 public function getIcon()
00526 {
00527 return $this->_sIcon;
00528 }
00529
00535 public function getLink()
00536 {
00537 return $this->_sLink;
00538 }
00539
00545 public function getShopId()
00546 {
00547 return $this->_sShopId;
00548 }
00549
00555 public function getSelList()
00556 {
00557 return $this->_aSelList;
00558 }
00559
00565 public function getChosenSelList()
00566 {
00567 return $this->_aChosenSelectlist;
00568 }
00569
00575 public function isBundle()
00576 {
00577 return $this->_blBundle;
00578 }
00579
00585 public function isDiscountArticle()
00586 {
00587 return $this->_blIsDiscountArticle;
00588 }
00589
00595 public function isSkipDiscount()
00596 {
00597 return $this->_blSkipDiscounts;
00598 }
00599
00609 public function __get( $sName )
00610 {
00611 if ( $sName == 'oProduct' ) {
00612 return $this->getArticle();
00613 }
00614 }
00615
00621 public function __sleep()
00622 {
00623 $aRet = array();
00624 foreach ( get_object_vars( $this ) as $sKey => $sVar ) {
00625 if ( $sKey != '_oArticle' ) {
00626 $aRet[] = $sKey;
00627 }
00628 }
00629 return $aRet;
00630 }
00631
00649 protected function _setArticle( $sProductId )
00650 {
00651 $oArticle = $this->getArticle( true, $sProductId );
00652
00653
00654 $this->_sProductId = $sProductId;
00655
00656 $this->getTitle();
00657
00658
00659 $this->_sIcon = $oArticle->oxarticles__oxicon->value;
00660 $this->_sLink = $oArticle->getLink();
00661
00662
00663 $this->_sShopId = $this->getConfig()->getShopId();
00664 $this->_sNativeShopId = $oArticle->oxarticles__oxshopid->value;
00665
00666
00667 $this->_sDimageDirNoSsl = $oArticle->nossl_dimagedir;
00668 $this->_sDimageDirSsl = $oArticle->ssl_dimagedir;
00669 }
00670
00682 protected function _setFromOrderArticle( $oOrderArticle )
00683 {
00684
00685 $this->_oArticle = $oOrderArticle;
00686
00687
00688 $this->_sProductId = $oOrderArticle->getProductId();
00689
00690
00691 $this->_sTitle = $oOrderArticle->oxarticles__oxtitle->value;
00692
00693
00694 $this->_sShopId = $this->getConfig()->getShopId();
00695 $this->_sNativeShopId = $oOrderArticle->oxarticles__oxshopid->value;
00696 }
00697
00705 protected function _setSelectList( $aSelList )
00706 {
00707
00708 $aSelectLists = $this->getArticle()->getSelectLists();
00709 if ( !$aSelList || is_array($aSelList) && count($aSelList) == 0 ) {
00710 if ( $iSelCnt = count( $aSelectLists ) ) {
00711 $aSelList = array_fill( 0, $iSelCnt, '0' );
00712 }
00713 }
00714
00715 $this->_aSelList = $aSelList;
00716
00717
00718 if ( count( $this->_aSelList ) && is_array($this->_aSelList) ) {
00719 foreach ( $this->_aSelList as $conkey => $iSel ) {
00720 $this->_aChosenSelectlist[$conkey] = new Oxstdclass();
00721 $this->_aChosenSelectlist[$conkey]->name = $aSelectLists[$conkey]['name'];
00722 $this->_aChosenSelectlist[$conkey]->value = $aSelectLists[$conkey][$iSel]->name;
00723 }
00724 }
00725 }
00726
00732 public function getPersParams()
00733 {
00734 return $this->_aPersistentParameters;
00735 }
00736
00744 public function setPersParams( $aPersParam )
00745 {
00746 $this->_aPersistentParameters = $aPersParam;
00747 }
00748
00756 public function setBundle( $blBundle )
00757 {
00758 $this->_blBundle = $blBundle;
00759 }
00760
00768 public function setSkipDiscounts( $blSkip )
00769 {
00770 $this->_blSkipDiscounts = $blSkip;
00771 }
00772
00778 public function getProductId()
00779 {
00780 return $this->_sProductId;
00781 }
00782
00790 public function setWrapping( $sWrapId )
00791 {
00792 $this->_sWrappingId = $sWrapId;
00793 }
00794
00800 public function getWrappingId()
00801 {
00802 return $this->_sWrappingId;
00803 }
00804
00810 public function getWrapping()
00811 {
00812 $oWrap = null;
00813 if ( $sWrapId = $this->getWrappingId() ) {
00814 $oWrap = oxNew( 'oxwrapping' );
00815 $oWrap->load( $sWrapId );
00816 }
00817 return $oWrap;
00818 }
00819
00825 public function getWishId()
00826 {
00827 return $this->_sWishId;
00828 }
00829
00837 public function setWishId( $sWishId )
00838 {
00839 $this->_sWishId = $sWishId;
00840 }
00841
00849 public function setWishArticleId( $sArticleId )
00850 {
00851 $this->_sWishArticleId = $sArticleId;
00852 }
00853
00859 public function getWishArticleId()
00860 {
00861 return $this->_sWishArticleId;
00862 }
00863
00869 public function getFUnitPrice()
00870 {
00871 return oxLang::getInstance()->formatCurrency( $this->getUnitPrice()->getBruttoPrice() );
00872 }
00873
00879 public function getFTotalPrice()
00880 {
00881 return oxLang::getInstance()->formatCurrency( $this->getPrice()->getBruttoPrice() );
00882 }
00883
00889 public function getVatPercent()
00890 {
00891 return oxLang::getInstance()->formatVat( $this->getPrice()->getVat() );
00892 }
00893
00899 public function getVarSelect()
00900 {
00901 if ( $this->_sVarSelect === null || $this->getLanguageId() != oxLang::getInstance()->getBaseLanguage() ) {
00902 $oArticle = $this->getArticle( );
00903 $this->_sVarSelect = $oArticle->oxarticles__oxvarselect->value ? $oArticle->oxarticles__oxvarselect->value : '';
00904 }
00905
00906 return $this->_sVarSelect;
00907 }
00908
00914 public function getLanguageId()
00915 {
00916 return $this->_iLanguageId;
00917 }
00918
00926 public function setLanguageId( $iLanguageId )
00927 {
00928 $this->_iLanguageId = $iLanguageId;
00929 }
00930 }