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
00101 parent::assign( $aRecord);
00102
00103 }
00104
00105
00117 protected function _setLongDesc($sDbValue)
00118 {
00119 }
00120
00127 public function getSelectLists()
00128 {
00129 return null;
00130 }
00131
00137 public function getArticleUser()
00138 {
00139 if ( $this->_oUser === null ) {
00140 $this->_oUser = $this->getUser();
00141 }
00142 return $this->_oUser;
00143 }
00144
00150 protected function _getGroupPrice()
00151 {
00152 $dPrice = $this->oxarticles__oxprice->value;
00153 if ( $oUser = $this->getArticleUser() ) {
00154 if ( $oUser->inGroup( 'oxidpricea' ) ) {
00155 $dPrice = $this->oxarticles__oxpricea->value;
00156 } elseif ( $oUser->inGroup( 'oxidpriceb' ) ) {
00157 $dPrice = $this->oxarticles__oxpriceb->value;
00158 } elseif ( $oUser->inGroup( 'oxidpricec' ) ) {
00159 $dPrice = $this->oxarticles__oxpricec->value;
00160 }
00161 }
00162
00163
00164 if ( $this->getConfig()->getConfigParam( 'blOverrideZeroABCPrices' ) && (double) $dPrice == 0 ) {
00165 $dPrice = $this->oxarticles__oxprice->value;
00166 }
00167
00168 return $dPrice;
00169 }
00170
00176 public function getPrice()
00177 {
00178 if ( $this->_oPrice === null ) {
00179 $this->_oPrice = oxNew( "oxPrice" );
00180 if ( ( $dPrice = $this->_getGroupPrice() ) ) {
00181 $this->_oPrice->setPrice( $dPrice, $this->_dVat );
00182
00183 $this->_applyParentVat( $this->_oPrice );
00184 $this->_applyCurrency( $this->_oPrice );
00185
00186 $this->_applyParentDiscounts($this->_oPrice);
00187 } elseif ( ( $oParent = $this->getParent() ) ) {
00188 $this->_oPrice = $oParent->getPrice();
00189 }
00190 }
00191
00192 return $this->_oPrice;
00193 }
00194
00203 protected function _applyCurrency(oxPrice $oPrice, $oCur = null )
00204 {
00205 if ( !$oCur ) {
00206 $oCur = $this->getConfig()->getActShopCurrencyObject();
00207 }
00208
00209 $oPrice->multiply($oCur->rate);
00210 }
00211
00219 protected function _applyParentDiscounts( $oPrice )
00220 {
00221 if ( ( $oParent = $this->getParent() ) ) {
00222 $oParent->applyDiscountsForVariant( $oPrice );
00223 }
00224 }
00225
00233 protected function _applyParentVat( $oPrice )
00234 {
00235 if ( ( $oParent = $this->getParent() ) ) {
00236 $oParent->applyVats($oPrice);
00237 }
00238 }
00239
00247 public function setPrice($oPrice)
00248 {
00249 $this->_oPrice = $oPrice;
00250 }
00251
00257 public function getFPrice()
00258 {
00259 $sPrice = null;
00260 if ( ( $oPrice = $this->getPrice() ) ) {
00261 $sPrice = oxLang::getInstance()->formatCurrency( $oPrice->getBruttoPrice() );
00262 }
00263 return $sPrice;
00264 }
00265
00273 public function setParent($oParent)
00274 {
00275 $this->_oParent = $oParent;
00276 }
00277
00283 public function getParent()
00284 {
00285 return $this->_oParent;
00286 }
00287
00295 protected function _getParentPrice()
00296 {
00297 $dPrice = 0;
00298 if (isset($this->_oParent->oxarticles__oxprice->value)) {
00299 $dPrice = $this->_oParent->oxarticles__oxprice->value;
00300 }
00301 return $dPrice;
00302 }
00303
00309 public function getLinkType()
00310 {
00311 $iLinkType = 0;
00312 if ( ( $oParent = $this->getParent() ) ) {
00313 $iLinkType = $oParent->getLinkType();
00314 }
00315 return $iLinkType;
00316 }
00317
00325 public function inCategory( $sCatNid )
00326 {
00327 $blIn = false;
00328 if ( ( $oParent = $this->getParent() ) ) {
00329 $blIn = $oParent->inCategory( $sCatNid );
00330 }
00331 return $blIn;
00332 }
00333
00341 public function inPriceCategory( $sCatNid )
00342 {
00343 $blIn = false;
00344 if ( ( $oParent = $this->getParent() ) ) {
00345 $blIn = $oParent->inPriceCategory( $sCatNid );
00346 }
00347 return $blIn;
00348 }
00349
00359 public function getBaseStdLink( $iLang, $blAddId = true, $blFull = true )
00360 {
00361 if ( !isset( $this->_aBaseStdUrls[$iLang][$iLinkType] ) ) {
00362 $oArticle = oxNew( "oxArticle" );
00363 $oArticle->setId( $this->getId() );
00364 $oArticle->setLinkType( $iLinkType );
00365 $this->_aBaseStdUrls[$iLang][$iLinkType] = $oArticle->getBaseStdLink( $iLang, $blAddId, $blFull );
00366 }
00367
00368 return $this->_aBaseStdUrls[$iLang][$iLinkType];
00369 }
00370
00379 public function getStdLink( $iLang = null, $aParams = array() )
00380 {
00381 if ( $iLang === null ) {
00382 $iLang = (int) $this->getLanguage();
00383 }
00384
00385 $iLinkType = $this->getLinkType();
00386 if ( !isset( $this->_aStdUrls[$iLang][$iLinkType] ) ) {
00387 $oArticle = oxNew( "oxArticle" );
00388 $oArticle->setId( $this->getId() );
00389 $oArticle->setLinkType( $iLinkType );
00390 $this->_aStdUrls[$iLang][$iLinkType] = $oArticle->getStdLink( $iLang, $aParams );
00391 }
00392
00393 return $this->_aStdUrls[$iLang][$iLinkType];
00394 }
00395
00403 public function getBaseSeoLink( $iLang )
00404 {
00405 return oxSeoEncoderArticle::getInstance()->getArticleUrl( $this, $iLang, $iLinkType );
00406 }
00407
00415 public function getLink( $iLang = null )
00416 {
00417 if ( $iLang === null ) {
00418 $iLang = (int) $this->getLanguage();
00419 }
00420
00421 if ( !oxUtils::getInstance()->seoIsActive() ) {
00422 return $this->getStdLink( $iLang );
00423 }
00424
00425 $iLinkType = $this->getLinkType();
00426 if ( !isset( $this->_aSeoUrls[$iLang][$iLinkType] ) ) {
00427 $this->_aSeoUrls[$iLang][$iLinkType] = $this->getBaseSeoLink( $iLang );
00428 }
00429 return $this->_aSeoUrls[$iLang][$iLinkType];
00430
00431 }
00432 }