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 
00210     public function setAsDiscountArticle( $blIsDiscountArticle )
00211     {
00212         $this->_blIsDiscountArticle = $blIsDiscountArticle;
00213     }
00214 
00222     public function setStockCheckStatus( $blStatus )
00223     {
00224         $this->_blCheckArticleStock = $blStatus;
00225     }
00226 
00232     public function getStockCheckStatus()
00233     {
00234         return $this->_blCheckArticleStock;
00235     }
00236 
00248     public function setAmount( $dAmount, $blOverride = true )
00249     {
00250         //validating amount
00251         $oValidator = oxNew( 'oxinputvalidator' );
00252 
00253         try {
00254             $dAmount = $oValidator->validateBasketAmount( $dAmount );
00255         } catch( oxArticleInputException $oEx ) {
00256             $oEx->setArticleNr( $this->getProductId() );
00257             // setting additional information for excp and then rethrowing
00258             throw $oEx;
00259         }
00260 
00261         $oArticle = $this->getArticle();
00262 
00263 
00264         // setting default
00265         $iOnStock = true;
00266 
00267         if ( $blOverride ) {
00268             $this->_dAmount  = $dAmount;
00269         } else {
00270             $this->_dAmount += $dAmount;
00271         }
00272 
00273         // checking for stock
00274         if ( $this->getStockCheckStatus() == true ) {
00275             $iOnStock = $oArticle->checkForStock( $this->_dAmount );
00276             if ( $iOnStock !== true ) {
00277                 if ( $iOnStock === false ) {
00278                     // no stock !
00279                     $this->_dAmount = 0;
00280                 } else {
00281                     // limited stock
00282                     $this->_dAmount = $iOnStock;
00283                     $blOverride = true;
00284                 }
00285             }
00286         }
00287 
00288         // calculating general weight
00289         $this->_dWeight = $oArticle->oxarticles__oxweight->value * $this->_dAmount;
00290 
00291         if ( $iOnStock !== true ) {
00292             $oEx = oxNew( 'oxOutOfStockException' );
00293             $oEx->setMessage( 'EXCEPTION_OUTOFSTOCK_OUTOFSTOCK' );
00294             $oEx->setArticleNr( $oArticle->oxarticles__oxartnum->value );
00295             $oEx->setRemainingAmount( $this->_dAmount );
00296             throw $oEx;
00297         }
00298     }
00299 
00307     public function setPrice( $oPrice )
00308     {
00309         $this->_oPrice = oxNew( 'oxprice' );
00310         $this->_oPrice->setBruttoPriceMode();
00311         $this->_oPrice->setVat( $oPrice->getVAT() );
00312         $this->_oPrice->addPrice( $oPrice );
00313 
00314         $this->_oUnitPrice = oxNew( 'oxprice' );
00315         $this->_oUnitPrice->setBruttoPriceMode();
00316         $this->_oUnitPrice->setVat( $oPrice->getVAT() );
00317         $this->_oUnitPrice->addPrice( $oPrice );
00318 
00319         $this->_setDeprecatedValues();
00320     }
00321 
00327     public function getImageUrl()
00328     {
00329         $blIsSSl = $this->getConfig()->isSsl();
00330         if ( $blIsSSl ) {
00331             return $this->_sDimageDirSsl;
00332         } else {
00333             return $this->_sDimageDirNoSsl;
00334         }
00335     }
00336 
00344     public function getArticle()
00345     {
00346         if ( !$this->_sProductId ) {
00347             //this excpetion may not be caught, anyhow this is a critical exception
00348             $oEx = oxNew( 'oxArticleException' );
00349             $oEx->setMessage( 'EXCEPTION_ARTICLE_NOPRODUCTID' );
00350             throw $oEx;
00351         }
00352 
00353 
00354         if ( $this->_oArticle ) {
00355             return $this->_oArticle;
00356         }
00357 
00358         $this->_oArticle = oxNew( 'oxarticle' );
00359 
00360         // performance:
00361         // - skipping variants loading
00362         // - skipping 'ab' price info
00363         // - load parent field
00364         $this->_oArticle->setNoVariantLoading( true );
00365         $this->_oArticle->setSkipAbPrice( true );
00366         $this->_oArticle->setLoadParentData( true );
00367         $this->_oArticle->load( $this->_sProductId );
00368 
00369         return $this->_oArticle;
00370     }
00371 
00377     public function getdBundledAmount()
00378     {
00379         return $this->isBundle()?$this->_dAmount:0;
00380     }
00381 
00387     public function getPrice()
00388     {
00389         return $this->_oPrice;
00390     }
00391 
00397     public function getUnitPrice()
00398     {
00399         return $this->_oUnitPrice;
00400     }
00401 
00407     public function getAmount()
00408     {
00409         return $this->_dAmount;
00410     }
00411 
00417     public function getWeight()
00418     {
00419         return $this->_dWeight;
00420     }
00421 
00427     public function getTitle()
00428     {
00429         return $this->_sTitle;
00430     }
00431 
00437     public function getIcon()
00438     {
00439         return $this->_sIcon;
00440     }
00441 
00447     public function getLink()
00448     {
00449         return $this->_sLink;
00450     }
00451 
00457     public function getShopId()
00458     {
00459         return $this->_sShopId;
00460     }
00461 
00467     public function getSelList()
00468     {
00469         return $this->_aSelList;
00470     }
00471 
00477     public function getChosenSelList()
00478     {
00479         return $this->_aChosenSelectlist;
00480     }
00481 
00487     public function isBundle()
00488     {
00489         return $this->_blBundle;
00490     }
00491 
00497     public function isDiscountArticle()
00498     {
00499         return $this->_blIsDiscountArticle;
00500     }
00501 
00507     public function isSkipDiscount()
00508     {
00509         return $this->_blSkipDiscounts;
00510     }
00511 
00521     public function __get( $sName )
00522     {
00523         if ( $sName == 'oProduct' ) {
00524             return $this->getArticle();
00525         }
00526     }
00527 
00533     public function __sleep()
00534     {
00535         $aRet = array();
00536         foreach ( get_object_vars( $this ) as $sKey => $sVar ) {
00537             if ( $sKey != '_oArticle' ) {
00538                 $aRet[] = $sKey;
00539             }
00540         }
00541         return $aRet;
00542     }
00543 
00551     protected function _setDeprecatedValues()
00552     {
00553         $oPrice = $this->getPrice();
00554 
00555         // product VAT percent
00556         $this->vatPercent = $this->getVatPercent();
00557 
00558         // VAT value
00559         $this->dvat = $oPrice->getVATValue();
00560 
00561         // unit non formatted price
00562         $this->dprice = $oPrice->getBruttoPrice();
00563 
00564         // formatted unit price
00565         $this->fprice = $this->getFUnitPrice();
00566 
00567         // non formatted unit NETTO price
00568         $this->dnetprice = $oPrice->getNettoPrice();
00569 
00570         $this->_oPrice->multiply( $this->getAmount() );
00571 
00572         // non formatted total NETTO price
00573         $this->dtotalnetprice = $oPrice->getNettoPrice();
00574 
00575         // formatter total NETTO price
00576         $this->ftotalnetprice = oxLang::getInstance()->formatCurrency( $oPrice->getNettoPrice() );
00577 
00578         // non formatted total BRUTTO price
00579         $this->dtotalprice = $oPrice->getBruttoPrice();
00580 
00581         // formatted total BRUTTO price
00582         $this->ftotalprice = $this->getFTotalPrice();
00583 
00584         // total VAT
00585         $this->dtotalvat = $oPrice->getVATValue();
00586 
00587         // formatted title
00588         $this->title = $this->getTitle();
00589 
00590         // icon URL
00591         $this->icon  = $this->getIcon();
00592 
00593         // details URL
00594         $this->link  = $this->getLink();
00595 
00596         // amount of items in basket
00597         $this->dAmount  = $this->getAmount();
00598 
00599         // weight
00600         $this->dWeight  = $this->getWeight();
00601 
00602         // select list
00603         $this->aSelList = $this->getSelList();
00604 
00605         // product id
00606         $this->sProduct = $this->getProductId();
00607 
00608         // product id
00609         $this->varselect = $this->getVarSelect();
00610 
00611         // is bundle ?
00612         $this->blBundle = $this->isBundle();
00613 
00614         // bundle amount
00615         $this->dBundledAmount = $this->getdBundledAmount();
00616 
00617         // skip discounts ?
00618         $this->blSkipDiscounts     = $this->isSkipDiscount();
00619 
00620         // is discount item ?
00621         $this->blIsDiscountArticle = $this->isDiscountArticle();
00622 
00623         // dyn image location
00624         $this->dimagedir = $this->getImageUrl();
00625 
00626         // setting wrapping paper info
00627         $this->wrapping  = $this->getWrappingId();
00628 
00629         $this->oWrap = $this->getWrapping();
00630 
00631         $this->aPersParam = $this->getPersParams();
00632 
00633         //chosen select list
00634         $this->chosen_selectlist = $this->getChosenSelList();
00635     }
00636 
00654     protected function _setArticle( $sProductId )
00655     {
00656         $oArticle = oxNew( 'oxarticle' );
00657 
00658         if ( !$oArticle->load( $sProductId ) ) {
00659             $oEx = oxNew( 'oxNoArticleException' );
00660             $oEx->setMessage( 'EXCEPTION_ARTICLE_ARTICELDOESNOTEXIST' );
00661             $oEx->setArticleNr( $sProductId );
00662             throw $oEx;
00663         }
00664 
00665         // product ID
00666         $this->_sProductId = $sProductId;
00667 
00668         // products title
00669         $this->_sTitle = $oArticle->oxarticles__oxtitle->value;
00670         if ( $oArticle->oxarticles__oxvarselect->value ) {
00671             $this->_sTitle    .= ', '.$oArticle->oxarticles__oxvarselect->value;
00672             $this->_sVarSelect = $oArticle->oxarticles__oxvarselect->value;
00673         }
00674 
00675         // icon and details URL's
00676         $this->_sIcon = $oArticle->oxarticles__oxicon->value;
00677         $this->_sLink = $oArticle->oxdetaillink;
00678 
00679         // shop Ids
00680         $this->_sShopId       = $this->getConfig()->getShopId();
00681         $this->_sNativeShopId = $oArticle->oxarticles__oxshopid->value;
00682 
00683         // SSL/NON SSL image paths
00684         $this->_sDimageDirNoSsl = $oArticle->nossl_dimagedir;
00685         $this->_sDimageDirSsl   = $oArticle->ssl_dimagedir;
00686     }
00687 
00695     protected function _setSelectList( $aSelList )
00696     {
00697         // checking for default select list
00698         $aSelectLists = $this->getArticle()->getSelectLists();
00699         if ( !$aSelList || is_array($aSelList) && count($aSelList) == 0 ) {
00700             if ( $iSelCnt = count( $aSelectLists ) ) {
00701                 $aSelList = array_fill( 0, $iSelCnt, '0' );
00702             }
00703         }
00704 
00705         $this->_aSelList = $aSelList;
00706 
00707         //
00708         if ( count( $this->_aSelList ) && is_array($this->_aSelList) ) {
00709             foreach ( $this->_aSelList as $conkey => $iSel ) {
00710                 $this->_aChosenSelectlist[$conkey] = new Oxstdclass();
00711                 $this->_aChosenSelectlist[$conkey]->name  = $aSelectLists[$conkey]['name'];
00712                 $this->_aChosenSelectlist[$conkey]->value = $aSelectLists[$conkey][$iSel]->name;
00713             }
00714         }
00715     }
00716 
00722     public function getPersParams()
00723     {
00724         return $this->_aPersistentParameters;
00725     }
00726 
00734     public function setPersParams( $aPersParam )
00735     {
00736         $this->_aPersistentParameters = $aPersParam;
00737     }
00738 
00746     public function setBundle( $blBundle )
00747     {
00748         $this->_blBundle = $blBundle;
00749     }
00750 
00758     public function setSkipDiscounts( $blSkip )
00759     {
00760         $this->_blSkipDiscounts = $blSkip;
00761     }
00762 
00768     public function getProductId()
00769     {
00770         return $this->_sProductId;
00771     }
00772 
00780     public function setWrapping( $sWrapId )
00781     {
00782         $this->_sWrappingId = $sWrapId;
00783     }
00784 
00790     public function getWrappingId()
00791     {
00792         return $this->_sWrappingId;
00793     }
00794 
00800     public function getWrapping()
00801     {
00802         $oWrap = null;
00803         if ( $sWrapId = $this->getWrappingId() ) {
00804             $oWrap = oxNew( 'oxwrapping' );
00805             $oWrap->load( $sWrapId );
00806         }
00807         return $oWrap;
00808     }
00809 
00815     public function getWishId()
00816     {
00817         return $this->_sWishId;
00818     }
00819 
00827     public function setWishId( $sWishId )
00828     {
00829         $this->_sWishId = $sWishId;
00830     }
00831 
00839     public function setWishArticleId( $sArticleId )
00840     {
00841         $this->_sWishArticleId = $sArticleId;
00842     }
00843 
00849     public function getWishArticleId()
00850     {
00851         return $this->_sWishArticleId;
00852     }
00853 
00859     public function getFUnitPrice()
00860     {
00861         return oxLang::getInstance()->formatCurrency( $this->getUnitPrice()->getBruttoPrice() );
00862     }
00863 
00869     public function getFTotalPrice()
00870     {
00871         return oxLang::getInstance()->formatCurrency( $this->getPrice()->getBruttoPrice() );
00872     }
00873 
00879     public function getVatPercent()
00880     {
00881         return oxLang::getInstance()->formatVat( $this->getPrice()->getVat() );
00882     }
00883 
00889     public function getVarSelect()
00890     {
00891         return $this->_sVarSelect;
00892     }
00893 }

Generated on Wed May 13 13:25:51 2009 for OXID eShop CE by  doxygen 1.5.5