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
00269 public function setAmount( $dAmount, $blOverride = true )
00270 {
00271
00272 $oValidator = oxNew( 'oxinputvalidator' );
00273
00274 try {
00275 $dAmount = $oValidator->validateBasketAmount( $dAmount );
00276 } catch( oxArticleInputException $oEx ) {
00277 $oEx->setArticleNr( $this->getProductId() );
00278
00279 throw $oEx;
00280 }
00281
00282 $oArticle = $this->getArticle();
00283
00284
00285
00286 $iOnStock = true;
00287
00288 if ( $blOverride ) {
00289 $this->_dAmount = $dAmount;
00290 } else {
00291 $this->_dAmount += $dAmount;
00292 }
00293
00294
00295 if ( $this->getStockCheckStatus() == true ) {
00296 $iOnStock = $oArticle->checkForStock( $this->_dAmount );
00297 if ( $iOnStock !== true ) {
00298 if ( $iOnStock === false ) {
00299
00300 $this->_dAmount = 0;
00301 } else {
00302
00303 $this->_dAmount = $iOnStock;
00304 $blOverride = true;
00305 }
00306 }
00307 }
00308
00309
00310 $this->_dWeight = $oArticle->oxarticles__oxweight->value * $this->_dAmount;
00311
00312 if ( $iOnStock !== true ) {
00313 $oEx = oxNew( 'oxOutOfStockException' );
00314 $oEx->setMessage( 'EXCEPTION_OUTOFSTOCK_OUTOFSTOCK' );
00315 $oEx->setArticleNr( $oArticle->oxarticles__oxartnum->value );
00316 $oEx->setRemainingAmount( $this->_dAmount );
00317 throw $oEx;
00318 }
00319 }
00320
00328 public function setPrice( $oPrice )
00329 {
00330 $this->_oPrice = oxNew( 'oxprice' );
00331 $this->_oPrice->setBruttoPriceMode();
00332 $this->_oPrice->setVat( $oPrice->getVAT() );
00333 $this->_oPrice->addPrice( $oPrice );
00334
00335 $this->_oUnitPrice = oxNew( 'oxprice' );
00336 $this->_oUnitPrice->setBruttoPriceMode();
00337 $this->_oUnitPrice->setVat( $oPrice->getVAT() );
00338 $this->_oUnitPrice->addPrice( $oPrice );
00339
00340 $this->_setDeprecatedValues();
00341 }
00342
00348 public function getImageUrl()
00349 {
00350 $blIsSSl = $this->getConfig()->isSsl();
00351 if ( $blIsSSl ) {
00352 return $this->_sDimageDirSsl;
00353 } else {
00354 return $this->_sDimageDirNoSsl;
00355 }
00356 }
00357
00367 public function getArticle( $sProductId = null )
00368 {
00369 if ( $this->_oArticle === null ) {
00370 $sProductId = $sProductId ? $sProductId : $this->_sProductId;
00371 if ( !$sProductId ) {
00372
00373 $oEx = oxNew( 'oxArticleException' );
00374 $oEx->setMessage( 'EXCEPTION_ARTICLE_NOPRODUCTID' );
00375 throw $oEx;
00376 }
00377
00378 $this->_oArticle = oxNew( 'oxarticle' );
00379
00380
00381
00382
00383
00384 $this->_oArticle->setNoVariantLoading( true );
00385 $this->_oArticle->setSkipAbPrice( true );
00386 $this->_oArticle->setLoadParentData( true );
00387 if ( !$this->_oArticle->load( $sProductId ) ) {
00388 $oEx = oxNew( 'oxNoArticleException' );
00389 $oEx->setMessage( 'EXCEPTION_ARTICLE_ARTICELDOESNOTEXIST' );
00390 $oEx->setArticleNr( $sProductId );
00391 throw $oEx;
00392 }
00393
00394
00395 if ( !$this->_oArticle->isBuyable() ) {
00396 $oEx = oxNew( 'oxArticleInputException' );
00397 $oEx->setMessage( 'EXCEPTION_ARTICLE_ARTICELNOTBUYABLE' );
00398 $oEx->setArticleNr( $sProductId );
00399 throw $oEx;
00400 }
00401 }
00402
00403 return $this->_oArticle;
00404 }
00405
00411 public function getdBundledAmount()
00412 {
00413 return $this->isBundle()?$this->_dAmount:0;
00414 }
00415
00421 public function getPrice()
00422 {
00423 return $this->_oPrice;
00424 }
00425
00431 public function getUnitPrice()
00432 {
00433 return $this->_oUnitPrice;
00434 }
00435
00441 public function getAmount()
00442 {
00443 return $this->_dAmount;
00444 }
00445
00451 public function getWeight()
00452 {
00453 return $this->_dWeight;
00454 }
00455
00461 public function getTitle()
00462 {
00463 return $this->_sTitle;
00464 }
00465
00471 public function getIcon()
00472 {
00473 return $this->_sIcon;
00474 }
00475
00481 public function getLink()
00482 {
00483 return $this->_sLink;
00484 }
00485
00491 public function getShopId()
00492 {
00493 return $this->_sShopId;
00494 }
00495
00501 public function getSelList()
00502 {
00503 return $this->_aSelList;
00504 }
00505
00511 public function getChosenSelList()
00512 {
00513 return $this->_aChosenSelectlist;
00514 }
00515
00521 public function isBundle()
00522 {
00523 return $this->_blBundle;
00524 }
00525
00531 public function isDiscountArticle()
00532 {
00533 return $this->_blIsDiscountArticle;
00534 }
00535
00541 public function isSkipDiscount()
00542 {
00543 return $this->_blSkipDiscounts;
00544 }
00545
00555 public function __get( $sName )
00556 {
00557 if ( $sName == 'oProduct' ) {
00558 return $this->getArticle();
00559 }
00560 }
00561
00567 public function __sleep()
00568 {
00569 $aRet = array();
00570 foreach ( get_object_vars( $this ) as $sKey => $sVar ) {
00571 if ( $sKey != '_oArticle' ) {
00572 $aRet[] = $sKey;
00573 }
00574 }
00575 return $aRet;
00576 }
00577
00585 protected function _setDeprecatedValues()
00586 {
00587 $oPrice = $this->getPrice();
00588
00589
00590 $this->vatPercent = $this->getVatPercent();
00591
00592
00593 $this->dvat = $oPrice->getVATValue();
00594
00595
00596 $this->dprice = $oPrice->getBruttoPrice();
00597
00598
00599 $this->fprice = $this->getFUnitPrice();
00600
00601
00602 $this->dnetprice = $oPrice->getNettoPrice();
00603
00604 $this->_oPrice->multiply( $this->getAmount() );
00605
00606
00607 $this->dtotalnetprice = $oPrice->getNettoPrice();
00608
00609
00610 $this->ftotalnetprice = oxLang::getInstance()->formatCurrency( $oPrice->getNettoPrice() );
00611
00612
00613 $this->dtotalprice = $oPrice->getBruttoPrice();
00614
00615
00616 $this->ftotalprice = $this->getFTotalPrice();
00617
00618
00619 $this->dtotalvat = $oPrice->getVATValue();
00620
00621
00622 $this->title = $this->getTitle();
00623
00624
00625 $this->icon = $this->getIcon();
00626
00627
00628 $this->link = $this->getLink();
00629
00630
00631 $this->dAmount = $this->getAmount();
00632
00633
00634 $this->dWeight = $this->getWeight();
00635
00636
00637 $this->aSelList = $this->getSelList();
00638
00639
00640 $this->sProduct = $this->getProductId();
00641
00642
00643 $this->varselect = $this->getVarSelect();
00644
00645
00646 $this->blBundle = $this->isBundle();
00647
00648
00649 $this->dBundledAmount = $this->getdBundledAmount();
00650
00651
00652 $this->blSkipDiscounts = $this->isSkipDiscount();
00653
00654
00655 $this->blIsDiscountArticle = $this->isDiscountArticle();
00656
00657
00658 $this->dimagedir = $this->getImageUrl();
00659
00660
00661 $this->wrapping = $this->getWrappingId();
00662
00663 $this->oWrap = $this->getWrapping();
00664
00665 $this->aPersParam = $this->getPersParams();
00666
00667
00668 $this->chosen_selectlist = $this->getChosenSelList();
00669 }
00670
00688 protected function _setArticle( $sProductId )
00689 {
00690 $oArticle = $this->getArticle( $sProductId );
00691
00692
00693 $this->_sProductId = $sProductId;
00694
00695
00696 $this->_sTitle = $oArticle->oxarticles__oxtitle->value;
00697 if ( $oArticle->oxarticles__oxvarselect->value ) {
00698 $this->_sTitle = $this->_sTitle. ', ' . $oArticle->oxarticles__oxvarselect->value;
00699 $this->_sVarSelect = $oArticle->oxarticles__oxvarselect->value;
00700 }
00701
00702
00703 $this->_sIcon = $oArticle->oxarticles__oxicon->value;
00704 $this->_sLink = $oArticle->getLink();
00705
00706
00707 $this->_sShopId = $this->getConfig()->getShopId();
00708 $this->_sNativeShopId = $oArticle->oxarticles__oxshopid->value;
00709
00710
00711 $this->_sDimageDirNoSsl = $oArticle->nossl_dimagedir;
00712 $this->_sDimageDirSsl = $oArticle->ssl_dimagedir;
00713 }
00714
00726 protected function _setFromOrderArticle( $oOrderArticle )
00727 {
00728
00729 $this->_oArticle = $oOrderArticle;
00730
00731
00732 $this->_sProductId = $oOrderArticle->getProductId();
00733
00734
00735 $this->_sTitle = $oOrderArticle->oxarticles__oxtitle->value;
00736
00737
00738 $this->_sShopId = $this->getConfig()->getShopId();
00739 $this->_sNativeShopId = $oOrderArticle->oxarticles__oxshopid->value;
00740 }
00741
00749 protected function _setSelectList( $aSelList )
00750 {
00751
00752 $aSelectLists = $this->getArticle()->getSelectLists();
00753 if ( !$aSelList || is_array($aSelList) && count($aSelList) == 0 ) {
00754 if ( $iSelCnt = count( $aSelectLists ) ) {
00755 $aSelList = array_fill( 0, $iSelCnt, '0' );
00756 }
00757 }
00758
00759 $this->_aSelList = $aSelList;
00760
00761
00762 if ( count( $this->_aSelList ) && is_array($this->_aSelList) ) {
00763 foreach ( $this->_aSelList as $conkey => $iSel ) {
00764 $this->_aChosenSelectlist[$conkey] = new Oxstdclass();
00765 $this->_aChosenSelectlist[$conkey]->name = $aSelectLists[$conkey]['name'];
00766 $this->_aChosenSelectlist[$conkey]->value = $aSelectLists[$conkey][$iSel]->name;
00767 }
00768 }
00769 }
00770
00776 public function getPersParams()
00777 {
00778 return $this->_aPersistentParameters;
00779 }
00780
00788 public function setPersParams( $aPersParam )
00789 {
00790 $this->_aPersistentParameters = $aPersParam;
00791 }
00792
00800 public function setBundle( $blBundle )
00801 {
00802 $this->_blBundle = $blBundle;
00803 }
00804
00812 public function setSkipDiscounts( $blSkip )
00813 {
00814 $this->_blSkipDiscounts = $blSkip;
00815 }
00816
00822 public function getProductId()
00823 {
00824 return $this->_sProductId;
00825 }
00826
00834 public function setWrapping( $sWrapId )
00835 {
00836 $this->_sWrappingId = $sWrapId;
00837 }
00838
00844 public function getWrappingId()
00845 {
00846 return $this->_sWrappingId;
00847 }
00848
00854 public function getWrapping()
00855 {
00856 $oWrap = null;
00857 if ( $sWrapId = $this->getWrappingId() ) {
00858 $oWrap = oxNew( 'oxwrapping' );
00859 $oWrap->load( $sWrapId );
00860 }
00861 return $oWrap;
00862 }
00863
00869 public function getWishId()
00870 {
00871 return $this->_sWishId;
00872 }
00873
00881 public function setWishId( $sWishId )
00882 {
00883 $this->_sWishId = $sWishId;
00884 }
00885
00893 public function setWishArticleId( $sArticleId )
00894 {
00895 $this->_sWishArticleId = $sArticleId;
00896 }
00897
00903 public function getWishArticleId()
00904 {
00905 return $this->_sWishArticleId;
00906 }
00907
00913 public function getFUnitPrice()
00914 {
00915 return oxLang::getInstance()->formatCurrency( $this->getUnitPrice()->getBruttoPrice() );
00916 }
00917
00923 public function getFTotalPrice()
00924 {
00925 return oxLang::getInstance()->formatCurrency( $this->getPrice()->getBruttoPrice() );
00926 }
00927
00933 public function getVatPercent()
00934 {
00935 return oxLang::getInstance()->formatVat( $this->getPrice()->getVat() );
00936 }
00937
00943 public function getVarSelect()
00944 {
00945 return $this->_sVarSelect;
00946 }
00947 }