oxbasketitem.php

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 
00188     public function init( $sProductID, $dAmount, $aSel = null, $aPersParam = null, $blBundle = null )
00189     {
00190         $this->_setArticle( $sProductID );
00191         $this->setAmount( $dAmount );
00192         $this->_setSelectList( $aSel );
00193         $this->setPersParams( $aPersParam );
00194         $this->setBundle( $blBundle );
00195     }
00196 
00204     public function setAsDiscountArticle( $blIsDiscountArticle )
00205     {
00206         $this->_blIsDiscountArticle = $blIsDiscountArticle;
00207     }
00208 
00220     public function setAmount( $dAmount, $blOverride = true )
00221     {
00222         //validating amount
00223         $oValidator = oxNew( 'oxinputvalidator' );
00224 
00225         try {
00226             $dAmount = $oValidator->validateBasketAmount( $dAmount );
00227         } catch( oxArticleInputException $oEx ) {
00228             $oEx->setArticleNr( $this->getProductId() );
00229             // setting additional information for excp and then rethrowing
00230             throw $oEx;
00231         }
00232 
00233         $oArticle = $this->getArticle();
00234 
00235 
00236         // checking for stock
00237         $iOnStock = $oArticle->checkForStock( $dAmount + $this->_dAmount );
00238 
00239         if ( $iOnStock !== true ) {
00240             if ( $iOnStock === false ) {
00241                 // no stock !
00242                 $dAmount = 0;
00243             } else {
00244                 // limited stock
00245                 $dAmount = $iOnStock;
00246                 $blOverride = true;
00247             }
00248         }
00249 
00250         if ( $blOverride ) {
00251             $this->_dAmount  = $dAmount;
00252         } else {
00253             $this->_dAmount += $dAmount;
00254         }
00255 
00256         // calculating general weight
00257         $this->_dWeight = $oArticle->oxarticles__oxweight->value * $this->_dAmount;
00258 
00259         if ( $iOnStock !== true ) {
00260             $oEx = oxNew( 'oxOutOfStockException' );
00261             $oEx->setMessage( 'EXCEPTION_OUTOFSTOCK_OUTOFSTOCK' );
00262             $oEx->setArticleNr( $oArticle->oxarticles__oxartnum->value );
00263             $oEx->setRemainingAmount( $dAmount );
00264             throw $oEx;
00265         }
00266     }
00267 
00275     public function setPrice( $oPrice )
00276     {
00277         $this->_oPrice = oxNew( 'oxprice' );
00278         $this->_oPrice->setBruttoPriceMode();
00279         $this->_oPrice->setVat( $oPrice->getVAT() );
00280         $this->_oPrice->addPrice( $oPrice );
00281 
00282         $this->_oUnitPrice = oxNew( 'oxprice' );
00283         $this->_oUnitPrice->setBruttoPriceMode();
00284         $this->_oUnitPrice->setVat( $oPrice->getVAT() );
00285         $this->_oUnitPrice->addPrice( $oPrice );
00286 
00287         $this->_setDeprecatedValues();
00288     }
00289 
00295     public function getImageUrl()
00296     {
00297         $blIsSSl = $this->getConfig()->isSsl();
00298         if ( $blIsSSl ) {
00299             return $this->_sDimageDirSsl;
00300         } else {
00301             return $this->_sDimageDirNoSsl;
00302         }
00303     }
00304 
00312     public function getArticle()
00313     {
00314         if ( !$this->_sProductId ) {
00315             //this excpetion may not be caught, anyhow this is a critical exception
00316             $oEx = oxNew( 'oxArticleException' );
00317             $oEx->setMessage( 'EXCEPTION_ARTICLE_NOPRODUCTID' );
00318             throw $oEx;
00319         }
00320 
00321 
00322         if ( $this->_oArticle ) {
00323             return $this->_oArticle;
00324         }
00325 
00326         $this->_oArticle = oxNew( 'oxarticle' );
00327 
00328         // performance:
00329         // - skipping variants loading
00330         // - skipping 'ab' price info
00331         // - load parent field
00332         $this->_oArticle->setNoVariantLoading( true );
00333         $this->_oArticle->setSkipAbPrice( true );
00334         $this->_oArticle->setLoadParentData( true );
00335         $this->_oArticle->load( $this->_sProductId );
00336 
00337         return $this->_oArticle;
00338     }
00339 
00345     public function getdBundledAmount()
00346     {
00347         return $this->isBundle()?$this->_dAmount:0;
00348     }
00349 
00355     public function getPrice()
00356     {
00357         return $this->_oPrice;
00358     }
00359 
00365     public function getUnitPrice()
00366     {
00367         return $this->_oUnitPrice;
00368     }
00369 
00375     public function getAmount()
00376     {
00377         return $this->_dAmount;
00378     }
00379 
00385     public function getWeight()
00386     {
00387         return $this->_dWeight;
00388     }
00389 
00395     public function getTitle()
00396     {
00397         return $this->_sTitle;
00398     }
00399 
00405     public function getIcon()
00406     {
00407         return $this->_sIcon;
00408     }
00409 
00415     public function getLink()
00416     {
00417         return $this->_sLink;
00418     }
00419 
00425     public function getShopId()
00426     {
00427         return $this->_sShopId;
00428     }
00429 
00435     public function getSelList()
00436     {
00437         return $this->_aSelList;
00438     }
00439 
00445     public function getChosenSelList()
00446     {
00447         return $this->_aChosenSelectlist;
00448     }
00449 
00455     public function isBundle()
00456     {
00457         return $this->_blBundle;
00458     }
00459 
00465     public function isDiscountArticle()
00466     {
00467         return $this->_blIsDiscountArticle;
00468     }
00469 
00475     public function isSkipDiscount()
00476     {
00477         return $this->_blSkipDiscounts;
00478     }
00479 
00489     public function __get( $sName )
00490     {
00491         if ( $sName == 'oProduct' ) {
00492             return $this->getArticle();
00493         }
00494     }
00495 
00501     public function __sleep()
00502     {
00503         $aRet = array();
00504         foreach ( get_object_vars( $this ) as $sKey => $sVar ) {
00505             if ( $sKey != '_oArticle' ) {
00506                 $aRet[] = $sKey;
00507             }
00508         }
00509         return $aRet;
00510     }
00511 
00519     protected function _setDeprecatedValues()
00520     {
00521         $oPrice = $this->getPrice();
00522 
00523         // product VAT percent
00524         $this->vatPercent = $this->getVatPercent();
00525 
00526         // VAT value
00527         $this->dvat = $oPrice->getVATValue();
00528 
00529         // unit non formatted price
00530         $this->dprice = $oPrice->getBruttoPrice();
00531 
00532         // formatted unit price
00533         $this->fprice = $this->getFUnitPrice();
00534 
00535         // non formatted unit NETTO price
00536         $this->dnetprice = $oPrice->getNettoPrice();
00537 
00538         $this->_oPrice->multiply( $this->getAmount() );
00539 
00540         // non formatted total NETTO price
00541         $this->dtotalnetprice = $oPrice->getNettoPrice();
00542 
00543         // formatter total NETTO price
00544         $this->ftotalnetprice = oxLang::getInstance()->formatCurrency( $oPrice->getNettoPrice() );
00545 
00546         // non formatted total BRUTTO price
00547         $this->dtotalprice = $oPrice->getBruttoPrice();
00548 
00549         // formatted total BRUTTO price
00550         $this->ftotalprice = $this->getFTotalPrice();
00551 
00552         // total VAT
00553         $this->dtotalvat = $oPrice->getVATValue();
00554 
00555         // formatted title
00556         $this->title = $this->getTitle();
00557 
00558         // icon URL
00559         $this->icon  = $this->getIcon();
00560 
00561         // details URL
00562         $this->link  = $this->getLink();
00563 
00564         // amount of items in basket
00565         $this->dAmount  = $this->getAmount();
00566 
00567         // weight
00568         $this->dWeight  = $this->getWeight();
00569 
00570         // select list
00571         $this->aSelList = $this->getSelList();
00572 
00573         // product id
00574         $this->sProduct = $this->getProductId();
00575 
00576         // product id
00577         $this->varselect = $this->getVarSelect();
00578 
00579         // is bundle ?
00580         $this->blBundle = $this->isBundle();
00581 
00582         // bundle amount
00583         $this->dBundledAmount = $this->getdBundledAmount();
00584 
00585         // skip discounts ?
00586         $this->blSkipDiscounts     = $this->isSkipDiscount();
00587 
00588         // is discount item ?
00589         $this->blIsDiscountArticle = $this->isDiscountArticle();
00590 
00591         // dyn image location
00592         $this->dimagedir = $this->getImageUrl();
00593 
00594         // setting wrapping paper info
00595         $this->wrapping  = $this->getWrappingId();
00596 
00597         $this->oWrap = $this->getWrapping();
00598 
00599         $this->aPersParam = $this->getPersParams();
00600 
00601         //chosen select list
00602         $this->chosen_selectlist = $this->getChosenSelList();
00603     }
00604 
00622     protected function _setArticle( $sProductId )
00623     {
00624         $oArticle = oxNew( 'oxarticle' );
00625 
00626         if ( !$oArticle->load( $sProductId ) ) {
00627             $oEx = oxNew( 'oxNoArticleException' );
00628             $oEx->setMessage( 'EXCEPTION_ARTICLE_ARTICELDOESNOTEXIST' );
00629             $oEx->setArticleNr( $sProductId );
00630             throw $oEx;
00631         }
00632 
00633         // product ID
00634         $this->_sProductId = $sProductId;
00635 
00636         // products title
00637         $this->_sTitle = $oArticle->oxarticles__oxtitle->value;
00638         if ( $oArticle->oxarticles__oxvarselect->value ) {
00639             $this->_sTitle    .= ', '.$oArticle->oxarticles__oxvarselect->value;
00640             $this->_sVarSelect = $oArticle->oxarticles__oxvarselect->value;
00641         }
00642 
00643         // icon and details URL's
00644         $this->_sIcon = $oArticle->oxarticles__oxicon->value;
00645         $this->_sLink = $oArticle->oxdetaillink;
00646 
00647         // shop Ids
00648         $this->_sShopId       = $this->getConfig()->getShopId();
00649         $this->_sNativeShopId = $oArticle->oxarticles__oxshopid->value;
00650 
00651         // SSL/NON SSL image paths
00652         $this->_sDimageDirNoSsl = $oArticle->nossl_dimagedir;
00653         $this->_sDimageDirSsl   = $oArticle->ssl_dimagedir;
00654     }
00655 
00663     protected function _setSelectList( $aSelList )
00664     {
00665         // checking for default select list
00666         $aSelectLists = $this->getArticle()->getSelectLists();
00667         if ( !$aSelList || is_array($aSelList) && count($aSelList) == 0 ) {
00668             if ( $iSelCnt = count( $aSelectLists ) ) {
00669                 $aSelList = array_fill( 0, $iSelCnt, '0' );
00670             }
00671         }
00672 
00673         $this->_aSelList = $aSelList;
00674 
00675         //
00676         if ( count( $this->_aSelList ) && is_array($this->_aSelList) ) {
00677             foreach ( $this->_aSelList as $conkey => $iSel ) {
00678                 $this->_aChosenSelectlist[$conkey] = new Oxstdclass();
00679                 $this->_aChosenSelectlist[$conkey]->name  = $aSelectLists[$conkey]['name'];
00680                 $this->_aChosenSelectlist[$conkey]->value = $aSelectLists[$conkey][$iSel]->name;
00681             }
00682         }
00683     }
00684 
00690     public function getPersParams()
00691     {
00692         return $this->_aPersistentParameters;
00693     }
00694 
00702     public function setPersParams( $aPersParam )
00703     {
00704         $this->_aPersistentParameters = $aPersParam;
00705     }
00706 
00714     public function setBundle( $blBundle )
00715     {
00716         $this->_blBundle = $blBundle;
00717     }
00718 
00726     public function setSkipDiscounts( $blSkip )
00727     {
00728         $this->_blSkipDiscounts = $blSkip;
00729     }
00730 
00736     public function getProductId()
00737     {
00738         return $this->_sProductId;
00739     }
00740 
00748     public function setWrapping( $sWrapId )
00749     {
00750         $this->_sWrappingId = $sWrapId;
00751     }
00752 
00758     public function getWrappingId()
00759     {
00760         return $this->_sWrappingId;
00761     }
00762 
00768     public function getWrapping()
00769     {
00770         $oWrap = null;
00771         if ( $sWrapId = $this->getWrappingId() ) {
00772             $oWrap = oxNew( 'oxwrapping' );
00773             $oWrap->load( $sWrapId );
00774         }
00775         return $oWrap;
00776     }
00777 
00783     public function getWishId()
00784     {
00785         return $this->_sWishId;
00786     }
00787 
00795     public function setWishId( $sWishId )
00796     {
00797         $this->_sWishId = $sWishId;
00798     }
00799 
00807     public function setWishArticleId( $sArticleId )
00808     {
00809         $this->_sWishArticleId = $sArticleId;
00810     }
00811 
00817     public function getWishArticleId()
00818     {
00819         return $this->_sWishArticleId;
00820     }
00821 
00827     public function getFUnitPrice()
00828     {
00829         return oxLang::getInstance()->formatCurrency( $this->getUnitPrice()->getBruttoPrice() );
00830     }
00831 
00837     public function getFTotalPrice()
00838     {
00839         return oxLang::getInstance()->formatCurrency( $this->getPrice()->getBruttoPrice() );
00840     }
00841 
00847     public function getVatPercent()
00848     {
00849         return oxLang::getInstance()->formatVat( $this->getPrice()->getVat() );
00850     }
00851 
00857     public function getVarSelect()
00858     {
00859         return $this->_sVarSelect;
00860     }
00861 }

Generated on Thu Feb 19 15:02:22 2009 for OXID eShop CE by  doxygen 1.5.5