oxsimplevariant.php

Go to the documentation of this file.
00001 <?php
00002 
00007 class oxSimpleVariant extends oxI18n implements oxIUrl
00008 {
00014     protected $_blUseLazyLoading = true;
00015 
00021     protected $_oPrice = null;
00022 
00028     protected $_oParent = null;
00029 
00035     protected $_aStdUrls = array();
00036 
00042     protected $_aBaseStdUrls = array();
00043 
00049     protected $_aSeoUrls = array();
00050 
00055     protected $_oUser = null;
00056 
00061     public function __construct()
00062     {
00063         parent::__construct();
00064         $this->_sCacheKey = "simplevariants";
00065         $this->init( 'oxarticles' );
00066     }
00067 
00075     public function __get($sName)
00076     {
00077         $myUtils = oxUtils::getInstance();
00078         switch ($sName) {
00079             case 'aSelectlist' :
00080                 if ( $this->getConfig()->getConfigParam( 'bl_perfLoadSelectLists' ) ) {
00081                     return $this->aSelectlist = $this->getSelectLists();
00082                 }
00083                 return;
00084                 break;
00085         }
00086 
00087         return parent::__get($sName);
00088     }
00089 
00098     public function assign( $aRecord)
00099     {
00100         // load object from database
00101         parent::assign( $aRecord);
00102 
00103     }
00104 
00105 
00112     public function getSelectLists()
00113     {
00114         return null;
00115     }
00116 
00122     public function getArticleUser()
00123     {
00124         if ( $this->_oUser === null ) {
00125             $this->_oUser = $this->getUser();
00126         }
00127         return $this->_oUser;
00128     }
00129 
00135     protected function _getGroupPrice()
00136     {
00137         $dPrice = $this->oxarticles__oxprice->value;
00138         if ( $oUser = $this->getArticleUser() ) {
00139             if ( $oUser->inGroup( 'oxidpricea' ) ) {
00140                 $dPrice = $this->oxarticles__oxpricea->value;
00141             } elseif ( $oUser->inGroup( 'oxidpriceb' ) ) {
00142                 $dPrice = $this->oxarticles__oxpriceb->value;
00143             } elseif ( $oUser->inGroup( 'oxidpricec' ) ) {
00144                 $dPrice = $this->oxarticles__oxpricec->value;
00145             }
00146         }
00147 
00148         // #1437/1436C - added config option, and check for zero A,B,C price values
00149         if ( $this->getConfig()->getConfigParam( 'blOverrideZeroABCPrices' ) && (double) $dPrice == 0 ) {
00150             $dPrice = $this->oxarticles__oxprice->value;
00151         }
00152 
00153         return $dPrice;
00154     }
00155 
00161     public function getPrice()
00162     {
00163         if ( $this->_oPrice === null ) {
00164             $this->_oPrice = oxNew( "oxPrice" );
00165             if ( ( $dPrice = $this->_getGroupPrice() ) ) {
00166                 $this->_oPrice->setPrice( $dPrice, $this->_dVat );
00167 
00168                 $this->_applyParentVat( $this->_oPrice );
00169                 $this->_applyCurrency( $this->_oPrice );
00170                 // apply discounts
00171                 $this->_applyParentDiscounts($this->_oPrice);
00172             } elseif ( ( $oParent = $this->getParent() ) ) {
00173                 $this->_oPrice = $oParent->getPrice();
00174             }
00175         }
00176 
00177         return $this->_oPrice;
00178     }
00179 
00188     protected function _applyCurrency(oxPrice $oPrice, $oCur = null )
00189     {
00190         if ( !$oCur ) {
00191             $oCur = $this->getConfig()->getActShopCurrencyObject();
00192         }
00193 
00194         $oPrice->multiply($oCur->rate);
00195     }
00196 
00204     protected function _applyParentDiscounts( $oPrice )
00205     {
00206         if ( ( $oParent = $this->getParent() ) ) {
00207             $oParent->applyDiscountsForVariant( $oPrice );
00208         }
00209     }
00210 
00218     protected function _applyParentVat( $oPrice )
00219     {
00220         if ( ( $oParent = $this->getParent() ) ) {
00221             $oParent->applyVats($oPrice);
00222         }
00223     }
00224 
00232     public function setPrice($oPrice)
00233     {
00234         $this->_oPrice = $oPrice;
00235     }
00236 
00242     public function getFPrice()
00243     {
00244         $sPrice = null;
00245         if ( ( $oPrice = $this->getPrice() ) ) {
00246             $sPrice = oxLang::getInstance()->formatCurrency( $oPrice->getBruttoPrice() );
00247         }
00248         return $sPrice;
00249     }
00250 
00258     public function setParent($oParent)
00259     {
00260         $this->_oParent = $oParent;
00261     }
00262 
00268     public function getParent()
00269     {
00270         return $this->_oParent;
00271     }
00272 
00280     protected function _getParentPrice()
00281     {
00282         $dPrice = 0;
00283         if (isset($this->_oParent->oxarticles__oxprice->value)) {
00284             $dPrice = $this->_oParent->oxarticles__oxprice->value;
00285         }
00286         return $dPrice;
00287     }
00288 
00294     public function getLinkType()
00295     {
00296         $iLinkType = 0;
00297         if ( ( $oParent = $this->getParent() ) ) {
00298             $iLinkType = $oParent->getLinkType();
00299         }
00300         return $iLinkType;
00301     }
00302 
00310     public function inCategory( $sCatNid )
00311     {
00312         $blIn = false;
00313         if ( ( $oParent = $this->getParent() ) ) {
00314             $blIn = $oParent->inCategory( $sCatNid );
00315         }
00316         return $blIn;
00317     }
00318 
00326     public function inPriceCategory( $sCatNid )
00327     {
00328         $blIn = false;
00329         if ( ( $oParent = $this->getParent() ) ) {
00330             $blIn = $oParent->inPriceCategory( $sCatNid );
00331         }
00332         return $blIn;
00333     }
00334 
00344     public function getBaseStdLink( $iLang, $blAddId = true, $blFull = true )
00345     {
00346         if ( !isset( $this->_aBaseStdUrls[$iLang][$iLinkType] ) ) {
00347             $oArticle = oxNew( "oxArticle" );
00348             $oArticle->setId( $this->getId() );
00349             $oArticle->setLinkType( $iLinkType );
00350             $this->_aBaseStdUrls[$iLang][$iLinkType] = $oArticle->getBaseStdLink( $iLang, $blAddId, $blFull );
00351         }
00352 
00353         return $this->_aBaseStdUrls[$iLang][$iLinkType];
00354     }
00355 
00364     public function getStdLink( $iLang = null, $aParams = array() )
00365     {
00366         if ( $iLang === null ) {
00367             $iLang = (int) $this->getLanguage();
00368         }
00369 
00370         $iLinkType = $this->getLinkType();
00371         if ( !isset( $this->_aStdUrls[$iLang][$iLinkType] ) ) {
00372             $oArticle = oxNew( "oxArticle" );
00373             $oArticle->setId( $this->getId() );
00374             $oArticle->setLinkType( $iLinkType );
00375             $this->_aStdUrls[$iLang][$iLinkType] = $oArticle->getStdLink( $iLang, $aParams );
00376         }
00377 
00378         return $this->_aStdUrls[$iLang][$iLinkType];
00379     }
00380 
00388     public function getBaseSeoLink( $iLang )
00389     {
00390         return oxSeoEncoderArticle::getInstance()->getArticleUrl( $this, $iLang, $iLinkType );
00391     }
00392 
00400     public function getLink( $iLang = null )
00401     {
00402         if ( $iLang === null ) {
00403             $iLang = (int) $this->getLanguage();
00404         }
00405 
00406         if ( !oxUtils::getInstance()->seoIsActive() ) {
00407             return $this->getStdLink( $iLang );
00408         }
00409 
00410         $iLinkType = $this->getLinkType();
00411         if ( !isset( $this->_aSeoUrls[$iLang][$iLinkType] ) ) {
00412             $this->_aSeoUrls[$iLang][$iLinkType] = $this->getBaseSeoLink( $iLang );
00413         }
00414         return $this->_aSeoUrls[$iLang][$iLinkType];
00415 
00416     }
00417 }

Generated by  doxygen 1.6.2