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 
00269     public function setAmount( $dAmount, $blOverride = true )
00270     {
00271         //validating amount
00272         $oValidator = oxNew( 'oxinputvalidator' );
00273 
00274         try {
00275             $dAmount = $oValidator->validateBasketAmount( $dAmount );
00276         } catch( oxArticleInputException $oEx ) {
00277             $oEx->setArticleNr( $this->getProductId() );
00278             $oEx->setProductId( $this->getProductId() );
00279             // setting additional information for excp and then rethrowing
00280             throw $oEx;
00281         }
00282 
00283         $oArticle = $this->getArticle();
00284 
00285 
00286         // setting default
00287         $iOnStock = true;
00288 
00289         if ( $blOverride ) {
00290             $this->_dAmount  = $dAmount;
00291         } else {
00292             $this->_dAmount += $dAmount;
00293         }
00294 
00295         // checking for stock
00296         if ( $this->getStockCheckStatus() == true ) {
00297             $iOnStock = $oArticle->checkForStock( $this->_dAmount );
00298             if ( $iOnStock !== true ) {
00299                 if ( $iOnStock === false ) {
00300                     // no stock !
00301                     $this->_dAmount = 0;
00302                 } else {
00303                     // limited stock
00304                     $this->_dAmount = $iOnStock;
00305                     $blOverride = true;
00306                 }
00307             }
00308         }
00309 
00310         // calculating general weight
00311         $this->_dWeight = $oArticle->oxarticles__oxweight->value * $this->_dAmount;
00312 
00313         if ( $iOnStock !== true ) {
00314             $oEx = oxNew( 'oxOutOfStockException' );
00315             $oEx->setMessage( 'EXCEPTION_OUTOFSTOCK_OUTOFSTOCK' );
00316             $oEx->setArticleNr( $oArticle->oxarticles__oxartnum->value );
00317             $oEx->setProductId( $oArticle->getProductId() );
00318             $oEx->setRemainingAmount( $this->_dAmount );
00319             throw $oEx;
00320         }
00321     }
00322 
00330     public function setPrice( $oPrice )
00331     {
00332         $this->_oPrice = oxNew( 'oxprice' );
00333         $this->_oPrice->setBruttoPriceMode();
00334         $this->_oPrice->setVat( $oPrice->getVAT() );
00335         $this->_oPrice->addPrice( $oPrice );
00336 
00337         $this->_oUnitPrice = oxNew( 'oxprice' );
00338         $this->_oUnitPrice->setBruttoPriceMode();
00339         $this->_oUnitPrice->setVat( $oPrice->getVAT() );
00340         $this->_oUnitPrice->addPrice( $oPrice );
00341 
00342         $this->_setDeprecatedValues();
00343     }
00344 
00350     public function getImageUrl()
00351     {
00352         $blIsSSl = $this->getConfig()->isSsl();
00353         if ( $blIsSSl ) {
00354             return $this->_sDimageDirSsl;
00355         } else {
00356             return $this->_sDimageDirNoSsl;
00357         }
00358     }
00359 
00372     public function getArticle( $blCheckProduct = true, $sProductId = null, $blDisableLazyLoading = false )
00373     {
00374         if ( $this->_oArticle === null || ( !$this->_oArticle->isOrderArticle() && $blDisableLazyLoading ) ) {
00375             $sProductId = $sProductId ? $sProductId : $this->_sProductId;
00376             if ( !$sProductId ) {
00377                 //this excpetion may not be caught, anyhow this is a critical exception
00378                 $oEx = oxNew( 'oxArticleException' );
00379                 $oEx->setMessage( 'EXCEPTION_ARTICLE_NOPRODUCTID' );
00380                 throw $oEx;
00381             }
00382 
00383             $this->_oArticle = oxNew( 'oxarticle' );
00384             // #M773 Do not use article lazy loading on order save
00385             if ( $blDisableLazyLoading ) {
00386                 $this->_oArticle->modifyCacheKey('_allviews');
00387                 $this->_oArticle->disableLazyLoading();
00388             }
00389 
00390             // performance:
00391             // - skipping variants loading
00392             // - skipping 'ab' price info
00393             // - load parent field
00394             $this->_oArticle->setNoVariantLoading( true );
00395             $this->_oArticle->setSkipAbPrice( true );
00396             $this->_oArticle->setLoadParentData( true );
00397             if ( !$this->_oArticle->load( $sProductId ) ) {
00398                 $oEx = oxNew( 'oxNoArticleException' );
00399                 $oLang = oxLang::getInstance();
00400                 $oEx->setMessage( sprintf($oLang->translateString( 'EXCEPTION_ARTICLE_ARTICELDOESNOTEXIST', $oLang->getBaseLanguage() ), $sProductId) );
00401                 $oEx->setArticleNr( $sProductId );
00402                 $oEx->setProductId( $sProductId );
00403                 throw $oEx;
00404             }
00405 
00406             // cant put not visible product to basket (M:1286)
00407             if ( $blCheckProduct && !$this->_oArticle->isVisible() ) {
00408                 $oEx = oxNew( 'oxNoArticleException' );
00409                 $oLang = oxLang::getInstance();
00410                 $oEx->setMessage( sprintf($oLang->translateString( 'EXCEPTION_ARTICLE_ARTICELDOESNOTEXIST', $oLang->getBaseLanguage() ), $this->_oArticle->oxarticles__oxartnum->value) );
00411                 $oEx->setArticleNr( $sProductId );
00412                 $oEx->setProductId( $sProductId );
00413                 throw $oEx;
00414             }
00415 
00416             // cant put not buyable product to basket
00417             if ( $blCheckProduct && !$this->_oArticle->isBuyable() ) {
00418                 $oEx = oxNew( 'oxArticleInputException' );
00419                 $oEx->setMessage( 'EXCEPTION_ARTICLE_ARTICELNOTBUYABLE' );
00420                 $oEx->setArticleNr( $sProductId );
00421                 $oEx->setProductId( $sProductId );
00422                 throw $oEx;
00423             }
00424         }
00425 
00426         return $this->_oArticle;
00427     }
00428 
00434     public function getdBundledAmount()
00435     {
00436         return $this->isBundle()?$this->_dAmount:0;
00437     }
00438 
00444     public function getPrice()
00445     {
00446         return $this->_oPrice;
00447     }
00448 
00454     public function getUnitPrice()
00455     {
00456         return $this->_oUnitPrice;
00457     }
00458 
00464     public function getAmount()
00465     {
00466         return $this->_dAmount;
00467     }
00468 
00474     public function getWeight()
00475     {
00476         return $this->_dWeight;
00477     }
00478 
00484     public function getTitle()
00485     {
00486         return $this->_sTitle;
00487     }
00488 
00494     public function getIcon()
00495     {
00496         return $this->_sIcon;
00497     }
00498 
00504     public function getLink()
00505     {
00506         return $this->_sLink;
00507     }
00508 
00514     public function getShopId()
00515     {
00516         return $this->_sShopId;
00517     }
00518 
00524     public function getSelList()
00525     {
00526         return $this->_aSelList;
00527     }
00528 
00534     public function getChosenSelList()
00535     {
00536         return $this->_aChosenSelectlist;
00537     }
00538 
00544     public function isBundle()
00545     {
00546         return $this->_blBundle;
00547     }
00548 
00554     public function isDiscountArticle()
00555     {
00556         return $this->_blIsDiscountArticle;
00557     }
00558 
00564     public function isSkipDiscount()
00565     {
00566         return $this->_blSkipDiscounts;
00567     }
00568 
00578     public function __get( $sName )
00579     {
00580         if ( $sName == 'oProduct' ) {
00581             return $this->getArticle();
00582         }
00583     }
00584 
00590     public function __sleep()
00591     {
00592         $aRet = array();
00593         foreach ( get_object_vars( $this ) as $sKey => $sVar ) {
00594             if ( $sKey != '_oArticle' ) {
00595                 $aRet[] = $sKey;
00596             }
00597         }
00598         return $aRet;
00599     }
00600 
00608     protected function _setDeprecatedValues()
00609     {
00610         $oPrice = $this->getPrice();
00611 
00612         // product VAT percent
00613         $this->vatPercent = $this->getVatPercent();
00614 
00615         // VAT value
00616         $this->dvat = $oPrice->getVATValue();
00617 
00618         // unit non formatted price
00619         $this->dprice = $oPrice->getBruttoPrice();
00620 
00621         // formatted unit price
00622         $this->fprice = $this->getFUnitPrice();
00623 
00624         // non formatted unit NETTO price
00625         $this->dnetprice = $oPrice->getNettoPrice();
00626 
00627         $this->_oPrice->multiply( $this->getAmount() );
00628 
00629         // non formatted total NETTO price
00630         $this->dtotalnetprice = $oPrice->getNettoPrice();
00631 
00632         // formatter total NETTO price
00633         $this->ftotalnetprice = oxLang::getInstance()->formatCurrency( $oPrice->getNettoPrice() );
00634 
00635         // non formatted total BRUTTO price
00636         $this->dtotalprice = $oPrice->getBruttoPrice();
00637 
00638         // formatted total BRUTTO price
00639         $this->ftotalprice = $this->getFTotalPrice();
00640 
00641         // total VAT
00642         $this->dtotalvat = $oPrice->getVATValue();
00643 
00644         // formatted title
00645         $this->title = $this->getTitle();
00646 
00647         // icon URL
00648         $this->icon  = $this->getIcon();
00649 
00650         // details URL
00651         $this->link  = $this->getLink();
00652 
00653         // amount of items in basket
00654         $this->dAmount  = $this->getAmount();
00655 
00656         // weight
00657         $this->dWeight  = $this->getWeight();
00658 
00659         // select list
00660         $this->aSelList = $this->getSelList();
00661 
00662         // product id
00663         $this->sProduct = $this->getProductId();
00664 
00665         // product id
00666         $this->varselect = $this->getVarSelect();
00667 
00668         // is bundle ?
00669         $this->blBundle = $this->isBundle();
00670 
00671         // bundle amount
00672         $this->dBundledAmount = $this->getdBundledAmount();
00673 
00674         // skip discounts ?
00675         $this->blSkipDiscounts     = $this->isSkipDiscount();
00676 
00677         // is discount item ?
00678         $this->blIsDiscountArticle = $this->isDiscountArticle();
00679 
00680         // dyn image location
00681         $this->dimagedir = $this->getImageUrl();
00682 
00683         // setting wrapping paper info
00684         $this->wrapping  = $this->getWrappingId();
00685 
00686         $this->oWrap = $this->getWrapping();
00687 
00688         $this->aPersParam = $this->getPersParams();
00689 
00690         //chosen select list
00691         $this->chosen_selectlist = $this->getChosenSelList();
00692     }
00693 
00711     protected function _setArticle( $sProductId )
00712     {
00713         $oArticle = $this->getArticle( true, $sProductId );
00714 
00715         // product ID
00716         $this->_sProductId = $sProductId;
00717 
00718         // products title
00719         $this->_sTitle = $oArticle->oxarticles__oxtitle->value;
00720         if ( $oArticle->oxarticles__oxvarselect->value ) {
00721             $this->_sTitle     = $this->_sTitle. ', ' . $oArticle->oxarticles__oxvarselect->value;
00722             $this->_sVarSelect = $oArticle->oxarticles__oxvarselect->value;
00723         }
00724 
00725         // icon and details URL's
00726         $this->_sIcon = $oArticle->oxarticles__oxicon->value;
00727         $this->_sLink = $oArticle->getLink();
00728 
00729         // shop Ids
00730         $this->_sShopId       = $this->getConfig()->getShopId();
00731         $this->_sNativeShopId = $oArticle->oxarticles__oxshopid->value;
00732 
00733         // SSL/NON SSL image paths
00734         $this->_sDimageDirNoSsl = $oArticle->nossl_dimagedir;
00735         $this->_sDimageDirSsl   = $oArticle->ssl_dimagedir;
00736     }
00737 
00749     protected function _setFromOrderArticle( $oOrderArticle )
00750     {
00751         // overriding whole article
00752         $this->_oArticle = $oOrderArticle;
00753 
00754         // product ID
00755         $this->_sProductId = $oOrderArticle->getProductId();
00756 
00757         // products title
00758         $this->_sTitle = $oOrderArticle->oxarticles__oxtitle->value;
00759 
00760         // shop Ids
00761         $this->_sShopId       = $this->getConfig()->getShopId();
00762         $this->_sNativeShopId = $oOrderArticle->oxarticles__oxshopid->value;
00763     }
00764 
00772     protected function _setSelectList( $aSelList )
00773     {
00774         // checking for default select list
00775         $aSelectLists = $this->getArticle()->getSelectLists();
00776         if ( !$aSelList || is_array($aSelList) && count($aSelList) == 0 ) {
00777             if ( $iSelCnt = count( $aSelectLists ) ) {
00778                 $aSelList = array_fill( 0, $iSelCnt, '0' );
00779             }
00780         }
00781 
00782         $this->_aSelList = $aSelList;
00783 
00784         //
00785         if ( count( $this->_aSelList ) && is_array($this->_aSelList) ) {
00786             foreach ( $this->_aSelList as $conkey => $iSel ) {
00787                 $this->_aChosenSelectlist[$conkey] = new Oxstdclass();
00788                 $this->_aChosenSelectlist[$conkey]->name  = $aSelectLists[$conkey]['name'];
00789                 $this->_aChosenSelectlist[$conkey]->value = $aSelectLists[$conkey][$iSel]->name;
00790             }
00791         }
00792     }
00793 
00799     public function getPersParams()
00800     {
00801         return $this->_aPersistentParameters;
00802     }
00803 
00811     public function setPersParams( $aPersParam )
00812     {
00813         $this->_aPersistentParameters = $aPersParam;
00814     }
00815 
00823     public function setBundle( $blBundle )
00824     {
00825         $this->_blBundle = $blBundle;
00826     }
00827 
00835     public function setSkipDiscounts( $blSkip )
00836     {
00837         $this->_blSkipDiscounts = $blSkip;
00838     }
00839 
00845     public function getProductId()
00846     {
00847         return $this->_sProductId;
00848     }
00849 
00857     public function setWrapping( $sWrapId )
00858     {
00859         $this->_sWrappingId = $sWrapId;
00860     }
00861 
00867     public function getWrappingId()
00868     {
00869         return $this->_sWrappingId;
00870     }
00871 
00877     public function getWrapping()
00878     {
00879         $oWrap = null;
00880         if ( $sWrapId = $this->getWrappingId() ) {
00881             $oWrap = oxNew( 'oxwrapping' );
00882             $oWrap->load( $sWrapId );
00883         }
00884         return $oWrap;
00885     }
00886 
00892     public function getWishId()
00893     {
00894         return $this->_sWishId;
00895     }
00896 
00904     public function setWishId( $sWishId )
00905     {
00906         $this->_sWishId = $sWishId;
00907     }
00908 
00916     public function setWishArticleId( $sArticleId )
00917     {
00918         $this->_sWishArticleId = $sArticleId;
00919     }
00920 
00926     public function getWishArticleId()
00927     {
00928         return $this->_sWishArticleId;
00929     }
00930 
00936     public function getFUnitPrice()
00937     {
00938         return oxLang::getInstance()->formatCurrency( $this->getUnitPrice()->getBruttoPrice() );
00939     }
00940 
00946     public function getFTotalPrice()
00947     {
00948         return oxLang::getInstance()->formatCurrency( $this->getPrice()->getBruttoPrice() );
00949     }
00950 
00956     public function getVatPercent()
00957     {
00958         return oxLang::getInstance()->formatVat( $this->getPrice()->getVat() );
00959     }
00960 
00966     public function getVarSelect()
00967     {
00968         return $this->_sVarSelect;
00969     }
00970 }

Generated on Mon Oct 26 20:07:16 2009 for OXID eShop CE by  doxygen 1.5.5