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 $_aSeoUrls = array();
00043 
00048     protected $_oUser = null;
00049 
00054     public function __construct()
00055     {
00056         parent::__construct();
00057         $this->_sCacheKey = "simplevariants";
00058         $this->init( 'oxarticles' );
00059     }
00060 
00068     public function __get($sName)
00069     {
00070         $myUtils = oxUtils::getInstance();
00071         switch ($sName) {
00072             case 'aSelectlist' :
00073                 if ( $this->getConfig()->getConfigParam( 'bl_perfLoadSelectLists' ) ) {
00074                     return $this->aSelectlist = $this->getSelectLists();
00075                 }
00076                 return;
00077                 break;
00078         }
00079 
00080         return parent::__get($sName);
00081     }
00082 
00091     public function assign( $aRecord)
00092     {
00093         // load object from database
00094         parent::assign( $aRecord);
00095 
00096     }
00097 
00098 
00105     public function getSelectLists()
00106     {
00107         return null;
00108     }
00109 
00115     public function getArticleUser()
00116     {
00117         if ( $this->_oUser === null ) {
00118             $this->_oUser = $this->getUser();
00119         }
00120         return $this->_oUser;
00121     }
00122 
00128     protected function _getGroupPrice()
00129     {
00130         $dPrice = $this->oxarticles__oxprice->value;
00131         if ( $oUser = $this->getArticleUser() ) {
00132             if ( $oUser->inGroup( 'oxidpricea' ) ) {
00133                 $dPrice = $this->oxarticles__oxpricea->value;
00134             } elseif ( $oUser->inGroup( 'oxidpriceb' ) ) {
00135                 $dPrice = $this->oxarticles__oxpriceb->value;
00136             } elseif ( $oUser->inGroup( 'oxidpricec' ) ) {
00137                 $dPrice = $this->oxarticles__oxpricec->value;
00138             }
00139         }
00140 
00141         // #1437/1436C - added config option, and check for zero A,B,C price values
00142         if ( $this->getConfig()->getConfigParam( 'blOverrideZeroABCPrices' ) && (double) $dPrice == 0 ) {
00143             $dPrice = $this->oxarticles__oxprice->value;
00144         }
00145 
00146         return $dPrice;
00147     }
00148 
00154     public function getPrice()
00155     {
00156         if ( $this->_oPrice === null ) {
00157             $this->_oPrice = oxNew( "oxPrice" );
00158             if ( ( $dPrice = $this->_getGroupPrice() ) ) {
00159                 $this->_oPrice->setPrice( $dPrice, $this->_dVat );
00160 
00161                 $this->_applyParentVat( $this->_oPrice );
00162                 $this->_applyCurrency( $this->_oPrice );
00163                 // apply discounts
00164                 $this->_applyParentDiscounts($this->_oPrice);
00165             } elseif ( ( $oParent = $this->getParent() ) ) {
00166                 $this->_oPrice = $oParent->getPrice();
00167             }
00168         }
00169 
00170         return $this->_oPrice;
00171     }
00172 
00181     protected function _applyCurrency(oxPrice $oPrice, $oCur = null )
00182     {
00183         if ( !$oCur ) {
00184             $oCur = $this->getConfig()->getActShopCurrencyObject();
00185         }
00186 
00187         $oPrice->multiply($oCur->rate);
00188     }
00189 
00197     protected function _applyParentDiscounts( $oPrice )
00198     {
00199         if ( ( $oParent = $this->getParent() ) ) {
00200             $oParent->applyDiscountsForVariant( $oPrice );
00201         }
00202     }
00203 
00211     protected function _applyParentVat( $oPrice )
00212     {
00213         if ( ( $oParent = $this->getParent() ) ) {
00214             $oParent->applyVats($oPrice);
00215         }
00216     }
00217 
00225     public function setPrice($oPrice)
00226     {
00227         $this->_oPrice = $oPrice;
00228     }
00229 
00235     public function getFPrice()
00236     {
00237         $sPrice = null;
00238         if ( ( $oPrice = $this->getPrice() ) ) {
00239             $sPrice = oxLang::getInstance()->formatCurrency( $oPrice->getBruttoPrice() );
00240         }
00241         return $sPrice;
00242     }
00243 
00251     public function setParent($oParent)
00252     {
00253         $this->_oParent = $oParent;
00254     }
00255 
00261     public function getParent()
00262     {
00263         return $this->_oParent;
00264     }
00265 
00273     protected function _getParentPrice()
00274     {
00275         $dPrice = 0;
00276         if (isset($this->_oParent->oxarticles__oxprice->value)) {
00277             $dPrice = $this->_oParent->oxarticles__oxprice->value;
00278         }
00279         return $dPrice;
00280     }
00281 
00287     public function getLinkType()
00288     {
00289         $iLinkType = 0;
00290         if ( ( $oParent = $this->getParent() ) ) {
00291             $iLinkType = $oParent->getLinkType();
00292         }
00293         return $iLinkType;
00294     }
00295 
00303     public function inCategory( $sCatNid )
00304     {
00305         $blIn = false;
00306         if ( ( $oParent = $this->getParent() ) ) {
00307             $blIn = $oParent->inCategory( $sCatNid );
00308         }
00309         return $blIn;
00310     }
00311 
00319     public function inPriceCategory( $sCatNid )
00320     {
00321         $blIn = false;
00322         if ( ( $oParent = $this->getParent() ) ) {
00323             $blIn = $oParent->inPriceCategory( $sCatNid );
00324         }
00325         return $blIn;
00326     }
00327 
00336     public function getStdLink( $iLang = null, $aParams = array() )
00337     {
00338         if ( $iLang === null ) {
00339             $iLang = (int) $this->getLanguage();
00340         }
00341 
00342         $iLinkType = $this->getLinkType();
00343         if ( !isset( $this->_aStdUrls[$iLang][$iLinkType] ) ) {
00344             $oArticle = oxNew( "oxArticle" );
00345             $oArticle->setId( $this->getId() );
00346             $oArticle->setLinkType( $iLinkType );
00347             $this->_aStdUrls[$iLang][$iLinkType] = $oArticle->getStdLink( $iLang, $aParams );
00348         }
00349 
00350         return $this->_aStdUrls[$iLang][$iLinkType];
00351     }
00352 
00360     public function getBaseSeoLink( $iLang )
00361     {
00362         return oxSeoEncoderArticle::getInstance()->getArticleUrl( $this, $iLang, $iLinkType );
00363     }
00364 
00372     public function getLink( $iLang = null )
00373     {
00374         if ( $iLang === null ) {
00375             $iLang = (int) $this->getLanguage();
00376         }
00377 
00378         if ( !oxUtils::getInstance()->seoIsActive() ) {
00379             return $this->getStdLink( $iLang );
00380         }
00381 
00382         $iLinkType = $this->getLinkType();
00383         if ( !isset( $this->_aSeoUrls[$iLang][$iLinkType] ) ) {
00384             $this->_aSeoUrls[$iLang][$iLinkType] = $this->getBaseSeoLink( $iLang );
00385         }
00386         return $this->_aSeoUrls[$iLang][$iLinkType];
00387 
00388     }
00389 }

Generated by  doxygen 1.6.2