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

Generated on Thu Dec 4 12:04:56 2008 for OXID eShop CE by  doxygen 1.5.5