oxbasketitem.php
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
00194 public function init( $sProductID, $dAmount, $aSel = null, $aPersParam = null, $blBundle = null )
00195 {
00196 $this->_setArticle( $sProductID );
00197 $this->setAmount( $dAmount );
00198 $this->_setSelectList( $aSel );
00199 $this->setPersParams( $aPersParam );
00200 $this->setBundle( $blBundle );
00201 }
00202
00216 public function initFromOrderArticle( $oOrderArticle )
00217 {
00218 $this->_setFromOrderArticle( $oOrderArticle );
00219 $this->setAmount( $oOrderArticle->oxorderarticles__oxamount->value );
00220 $this->_setSelectList( $oOrderArticle->getOrderArticleSelectList() );
00221 $this->setPersParams( $oOrderArticle->getPersParams() );
00222 }
00223
00231 public function setAsDiscountArticle( $blIsDiscountArticle )
00232 {
00233 $this->_blIsDiscountArticle = $blIsDiscountArticle;
00234 }
00235
00243 public function setStockCheckStatus( $blStatus )
00244 {
00245 $this->_blCheckArticleStock = $blStatus;
00246 }
00247
00253 public function getStockCheckStatus()
00254 {
00255 return $this->_blCheckArticleStock;
00256 }
00257
00270 public function setAmount( $dAmount, $blOverride = true, $sItemKey = null )
00271 {
00272
00273 $oValidator = oxNew( 'oxinputvalidator' );
00274
00275 try {
00276 $dAmount = $oValidator->validateBasketAmount( $dAmount );
00277 } catch( oxArticleInputException $oEx ) {
00278 $oEx->setArticleNr( $this->getProductId() );
00279 $oEx->setProductId( $this->getProductId() );
00280
00281 throw $oEx;
00282 }
00283
00284 $oArticle = $this->getArticle();
00285
00286
00287
00288 $iOnStock = true;
00289
00290 if ( $blOverride ) {
00291 $this->_dAmount = $dAmount;
00292 } else {
00293 $this->_dAmount += $dAmount;
00294 }
00295
00296
00297 if ( $this->getStockCheckStatus() == true ) {
00298 $dArtStockAmount = $this->getSession()->getBasket()->getArtStockInBasket( $oArticle->getId(), $sItemKey );
00299 $iOnStock = $oArticle->checkForStock( $this->_dAmount, $dArtStockAmount );
00300 if ( $iOnStock !== true ) {
00301 if ( $iOnStock === false ) {
00302
00303 $this->_dAmount = 0;
00304 } else {
00305
00306 $this->_dAmount = $iOnStock;
00307 $blOverride = true;
00308 }
00309 }
00310 }
00311
00312
00313 $this->_dWeight = $oArticle->oxarticles__oxweight->value * $this->_dAmount;
00314
00315 if ( $iOnStock !== true ) {
00316 $oEx = oxNew( 'oxOutOfStockException' );
00317 $oEx->setMessage( 'EXCEPTION_OUTOFSTOCK_OUTOFSTOCK' );
00318 $oEx->setArticleNr( $oArticle->oxarticles__oxartnum->value );
00319 $oEx->setProductId( $oArticle->getProductId() );
00320 $oEx->setRemainingAmount( $this->_dAmount );
00321 throw $oEx;
00322 }
00323 }
00324
00332 public function setPrice( $oPrice )
00333 {
00334 $this->_oPrice = oxNew( 'oxprice' );
00335 $this->_oPrice->setBruttoPriceMode();
00336 $this->_oPrice->setVat( $oPrice->getVAT() );
00337 $this->_oPrice->addPrice( $oPrice );
00338 $this->_oPrice->multiply( $this->getAmount() );
00339
00340 $this->_oUnitPrice = oxNew( 'oxprice' );
00341 $this->_oUnitPrice->setBruttoPriceMode();
00342 $this->_oUnitPrice->setVat( $oPrice->getVAT() );
00343 $this->_oUnitPrice->addPrice( $oPrice );
00344
00345 $this->_setDeprecatedValues();
00346 }
00347
00353 public function getImageUrl()
00354 {
00355 $blIsSSl = $this->getConfig()->isSsl();
00356 if ( $blIsSSl ) {
00357 return $this->_sDimageDirSsl;
00358 } else {
00359 return $this->_sDimageDirNoSsl;
00360 }
00361 }
00362
00368 public function getIconUrl()
00369 {
00370 $sIconUrl = $this->getImageUrl() . $this->getIcon();
00371
00372 return $sIconUrl;
00373 }
00374
00387 public function getArticle( $blCheckProduct = true, $sProductId = null, $blDisableLazyLoading = false )
00388 {
00389 if ( $this->_oArticle === null || ( !$this->_oArticle->isOrderArticle() && $blDisableLazyLoading ) ) {
00390 $sProductId = $sProductId ? $sProductId : $this->_sProductId;
00391 if ( !$sProductId ) {
00392
00393 $oEx = oxNew( 'oxArticleException' );
00394 $oEx->setMessage( 'EXCEPTION_ARTICLE_NOPRODUCTID' );
00395 throw $oEx;
00396 }
00397
00398 $this->_oArticle = oxNew( 'oxarticle' );
00399
00400 if ( $blDisableLazyLoading ) {
00401 $this->_oArticle->modifyCacheKey('_allviews');
00402 $this->_oArticle->disableLazyLoading();
00403 }
00404
00405
00406
00407
00408
00409 $this->_oArticle->setNoVariantLoading( true );
00410 $this->_oArticle->setSkipAbPrice( true );
00411 $this->_oArticle->setLoadParentData( true );
00412 if ( !$this->_oArticle->load( $sProductId ) ) {
00413 $oEx = oxNew( 'oxNoArticleException' );
00414 $oLang = oxLang::getInstance();
00415 $oEx->setMessage( sprintf($oLang->translateString( 'EXCEPTION_ARTICLE_ARTICELDOESNOTEXIST', $oLang->getBaseLanguage() ), $sProductId) );
00416 $oEx->setArticleNr( $sProductId );
00417 $oEx->setProductId( $sProductId );
00418 throw $oEx;
00419 }
00420
00421
00422 if ( $blCheckProduct && !$this->_oArticle->isVisible() ) {
00423 $oEx = oxNew( 'oxNoArticleException' );
00424 $oLang = oxLang::getInstance();
00425 $oEx->setMessage( sprintf($oLang->translateString( 'EXCEPTION_ARTICLE_ARTICELDOESNOTEXIST', $oLang->getBaseLanguage() ), $this->_oArticle->oxarticles__oxartnum->value) );
00426 $oEx->setArticleNr( $sProductId );
00427 $oEx->setProductId( $sProductId );
00428 throw $oEx;
00429 }
00430
00431
00432 if ( $blCheckProduct && !$this->_oArticle->isBuyable() ) {
00433 $oEx = oxNew( 'oxArticleInputException' );
00434 $oEx->setMessage( 'EXCEPTION_ARTICLE_ARTICELNOTBUYABLE' );
00435 $oEx->setArticleNr( $sProductId );
00436 $oEx->setProductId( $sProductId );
00437 throw $oEx;
00438 }
00439 }
00440
00441 return $this->_oArticle;
00442 }
00443
00449 public function getdBundledAmount()
00450 {
00451 return $this->isBundle()?$this->_dAmount:0;
00452 }
00453
00459 public function getPrice()
00460 {
00461 return $this->_oPrice;
00462 }
00463
00469 public function getUnitPrice()
00470 {
00471 return $this->_oUnitPrice;
00472 }
00473
00479 public function getAmount()
00480 {
00481 return $this->_dAmount;
00482 }
00483
00489 public function getWeight()
00490 {
00491 return $this->_dWeight;
00492 }
00493
00499 public function getTitle()
00500 {
00501 return $this->_sTitle;
00502 }
00503
00509 public function getIcon()
00510 {
00511 return $this->_sIcon;
00512 }
00513
00519 public function getLink()
00520 {
00521 return $this->_sLink;
00522 }
00523
00529 public function getShopId()
00530 {
00531 return $this->_sShopId;
00532 }
00533
00539 public function getSelList()
00540 {
00541 return $this->_aSelList;
00542 }
00543
00549 public function getChosenSelList()
00550 {
00551 return $this->_aChosenSelectlist;
00552 }
00553
00559 public function isBundle()
00560 {
00561 return $this->_blBundle;
00562 }
00563
00569 public function isDiscountArticle()
00570 {
00571 return $this->_blIsDiscountArticle;
00572 }
00573
00579 public function isSkipDiscount()
00580 {
00581 return $this->_blSkipDiscounts;
00582 }
00583
00593 public function __get( $sName )
00594 {
00595 if ( $sName == 'oProduct' ) {
00596 return $this->getArticle();
00597 }
00598 }
00599
00605 public function __sleep()
00606 {
00607 $aRet = array();
00608 foreach ( get_object_vars( $this ) as $sKey => $sVar ) {
00609 if ( $sKey != '_oArticle' ) {
00610 $aRet[] = $sKey;
00611 }
00612 }
00613 return $aRet;
00614 }
00615
00623 protected function _setDeprecatedValues()
00624 {
00625 $oUnitPrice = $this->getUnitPrice();
00626 $oPrice = $this->getPrice();
00627
00628
00629 $this->vatPercent = $this->getVatPercent();
00630
00631
00632 $this->dvat = $oUnitPrice->getVATValue();
00633
00634
00635 $this->dprice = $oUnitPrice->getBruttoPrice();
00636
00637
00638 $this->fprice = $this->getFUnitPrice();
00639
00640
00641 $this->dnetprice = $oUnitPrice->getNettoPrice();
00642
00643
00644 $this->dtotalnetprice = $oPrice->getNettoPrice();
00645
00646
00647 $this->ftotalnetprice = oxLang::getInstance()->formatCurrency( $oPrice->getNettoPrice() );
00648
00649
00650 $this->dtotalprice = $oPrice->getBruttoPrice();
00651
00652
00653 $this->ftotalprice = $this->getFTotalPrice();
00654
00655
00656 $this->dtotalvat = $oPrice->getVATValue();
00657
00658
00659 $this->title = $this->getTitle();
00660
00661
00662 $this->icon = $this->getIcon();
00663
00664
00665 $this->link = $this->getLink();
00666
00667
00668 $this->dAmount = $this->getAmount();
00669
00670
00671 $this->dWeight = $this->getWeight();
00672
00673
00674 $this->aSelList = $this->getSelList();
00675
00676
00677 $this->sProduct = $this->getProductId();
00678
00679
00680 $this->varselect = $this->getVarSelect();
00681
00682
00683 $this->blBundle = $this->isBundle();
00684
00685
00686 $this->dBundledAmount = $this->getdBundledAmount();
00687
00688
00689 $this->blSkipDiscounts = $this->isSkipDiscount();
00690
00691
00692 $this->blIsDiscountArticle = $this->isDiscountArticle();
00693
00694
00695 $this->dimagedir = $this->getImageUrl();
00696
00697
00698 $this->wrapping = $this->getWrappingId();
00699
00700 $this->oWrap = $this->getWrapping();
00701
00702 $this->aPersParam = $this->getPersParams();
00703
00704
00705 $this->chosen_selectlist = $this->getChosenSelList();
00706 }
00707
00725 protected function _setArticle( $sProductId )
00726 {
00727 $oArticle = $this->getArticle( true, $sProductId );
00728
00729
00730 $this->_sProductId = $sProductId;
00731
00732
00733 $this->_sTitle = $oArticle->oxarticles__oxtitle->value;
00734 if ( $oArticle->oxarticles__oxvarselect->value ) {
00735 $this->_sTitle = $this->_sTitle. ', ' . $oArticle->oxarticles__oxvarselect->value;
00736 $this->_sVarSelect = $oArticle->oxarticles__oxvarselect->value;
00737 }
00738
00739
00740 $this->_sIcon = $oArticle->oxarticles__oxicon->value;
00741 $this->_sLink = $oArticle->getLink();
00742
00743
00744 $this->_sShopId = $this->getConfig()->getShopId();
00745 $this->_sNativeShopId = $oArticle->oxarticles__oxshopid->value;
00746
00747
00748 $this->_sDimageDirNoSsl = $oArticle->nossl_dimagedir;
00749 $this->_sDimageDirSsl = $oArticle->ssl_dimagedir;
00750 }
00751
00763 protected function _setFromOrderArticle( $oOrderArticle )
00764 {
00765
00766 $this->_oArticle = $oOrderArticle;
00767
00768
00769 $this->_sProductId = $oOrderArticle->getProductId();
00770
00771
00772 $this->_sTitle = $oOrderArticle->oxarticles__oxtitle->value;
00773
00774
00775 $this->_sShopId = $this->getConfig()->getShopId();
00776 $this->_sNativeShopId = $oOrderArticle->oxarticles__oxshopid->value;
00777 }
00778
00786 protected function _setSelectList( $aSelList )
00787 {
00788
00789 $aSelectLists = $this->getArticle()->getSelectLists();
00790 if ( !$aSelList || is_array($aSelList) && count($aSelList) == 0 ) {
00791 if ( $iSelCnt = count( $aSelectLists ) ) {
00792 $aSelList = array_fill( 0, $iSelCnt, '0' );
00793 }
00794 }
00795
00796 $this->_aSelList = $aSelList;
00797
00798
00799 if ( count( $this->_aSelList ) && is_array($this->_aSelList) ) {
00800 foreach ( $this->_aSelList as $conkey => $iSel ) {
00801 $this->_aChosenSelectlist[$conkey] = new Oxstdclass();
00802 $this->_aChosenSelectlist[$conkey]->name = $aSelectLists[$conkey]['name'];
00803 $this->_aChosenSelectlist[$conkey]->value = $aSelectLists[$conkey][$iSel]->name;
00804 }
00805 }
00806 }
00807
00813 public function getPersParams()
00814 {
00815 return $this->_aPersistentParameters;
00816 }
00817
00825 public function setPersParams( $aPersParam )
00826 {
00827 $this->_aPersistentParameters = $aPersParam;
00828 }
00829
00837 public function setBundle( $blBundle )
00838 {
00839 $this->_blBundle = $blBundle;
00840 }
00841
00849 public function setSkipDiscounts( $blSkip )
00850 {
00851 $this->_blSkipDiscounts = $blSkip;
00852 }
00853
00859 public function getProductId()
00860 {
00861 return $this->_sProductId;
00862 }
00863
00871 public function setWrapping( $sWrapId )
00872 {
00873 $this->_sWrappingId = $sWrapId;
00874 }
00875
00881 public function getWrappingId()
00882 {
00883 return $this->_sWrappingId;
00884 }
00885
00891 public function getWrapping()
00892 {
00893 $oWrap = null;
00894 if ( $sWrapId = $this->getWrappingId() ) {
00895 $oWrap = oxNew( 'oxwrapping' );
00896 $oWrap->load( $sWrapId );
00897 }
00898 return $oWrap;
00899 }
00900
00906 public function getWishId()
00907 {
00908 return $this->_sWishId;
00909 }
00910
00918 public function setWishId( $sWishId )
00919 {
00920 $this->_sWishId = $sWishId;
00921 }
00922
00930 public function setWishArticleId( $sArticleId )
00931 {
00932 $this->_sWishArticleId = $sArticleId;
00933 }
00934
00940 public function getWishArticleId()
00941 {
00942 return $this->_sWishArticleId;
00943 }
00944
00950 public function getFUnitPrice()
00951 {
00952 return oxLang::getInstance()->formatCurrency( $this->getUnitPrice()->getBruttoPrice() );
00953 }
00954
00960 public function getFTotalPrice()
00961 {
00962 return oxLang::getInstance()->formatCurrency( $this->getPrice()->getBruttoPrice() );
00963 }
00964
00970 public function getVatPercent()
00971 {
00972 return oxLang::getInstance()->formatVat( $this->getPrice()->getVat() );
00973 }
00974
00980 public function getVarSelect()
00981 {
00982 return $this->_sVarSelect;
00983 }
00984 }