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 public function __construct()
00049 {
00050 parent::__construct();
00051 $this->_sCacheKey = "simplevariants";
00052 $this->init( 'oxarticles' );
00053 }
00054
00062 public function __get($sName)
00063 {
00064 $myUtils = oxUtils::getInstance();
00065 switch ($sName) {
00066 case 'aSelectlist' :
00067 if ( $this->getConfig()->getConfigParam( 'bl_perfLoadSelectLists' ) ) {
00068 return $this->aSelectlist = $this->getSelectLists();
00069 }
00070 return;
00071 break;
00072 }
00073
00074 return parent::__get($sName);
00075 }
00076
00083 public function getSelectLists()
00084 {
00085 return null;
00086 }
00087
00093 public function getPrice()
00094 {
00095 if (!is_null($this->_oPrice)) {
00096 return $this->_oPrice;
00097 }
00098
00099 $this->_oPrice = oxNew("oxPrice");
00100 $dPrice = $this->oxarticles__oxprice->value;
00101 if (!$dPrice) {
00102 $dPrice = $this->_getParentPrice();
00103 }
00104
00105 $this->_oPrice->setPrice($dPrice, $this->_dVat);
00106
00107 $this->_applyParentVat($this->_oPrice);
00108 $this->_applyCurrency($this->_oPrice);
00109
00110 $this->_applyParentDiscounts($this->_oPrice);
00111
00112 return $this->_oPrice;
00113 }
00114
00123 protected function _applyCurrency(oxPrice $oPrice, $oCur = null )
00124 {
00125 if ( !$oCur ) {
00126 $oCur = $this->getConfig()->getActShopCurrencyObject();
00127 }
00128
00129 $oPrice->multiply($oCur->rate);
00130 }
00131
00139 protected function _applyParentDiscounts( $oPrice )
00140 {
00141 $oParent = $this->getParent();
00142 if (!($oParent instanceof oxarticle)) {
00143 return;
00144 }
00145
00146 $oParent->applyDiscountsForVariant( $oPrice );
00147
00148 }
00149
00157 protected function _applyParentVat($oPrice)
00158 {
00159 $oParent = $this->getParent();
00160 if (!($oParent instanceof oxarticle)) {
00161 return;
00162 }
00163
00164 $oParent->applyVats($oPrice);
00165 }
00166
00174 public function setPrice($oPrice)
00175 {
00176 $this->_oPrice = $oPrice;
00177 }
00178
00184 public function getFPrice()
00185 {
00186 if ( ( $oPrice = $this->getPrice() ) ) {
00187 return oxLang::getInstance()->formatCurrency( $oPrice->getBruttoPrice() );
00188 }
00189 }
00190
00198 public function setParent($oParent)
00199 {
00200 $this->_oParent = $oParent;
00201 }
00202
00208 public function getParent()
00209 {
00210 return $this->_oParent;
00211 }
00212
00218 protected function _getParentPrice()
00219 {
00220 if (isset($this->_oParent->oxarticles__oxprice->value)) {
00221 return $this->_oParent->oxarticles__oxprice->value;
00222 }
00223
00224 return 0;
00225 }
00226
00232 public function getLinkType()
00233 {
00234 $oParent = $this->getParent();
00235 if (!($oParent instanceof oxarticle)) {
00236 return 0;
00237 }
00238
00239 return $oParent->getLinkType();
00240 }
00241
00249 public function inCategory( $sCatNid )
00250 {
00251 $oParent = $this->getParent();
00252 if ( ( $oParent instanceof oxarticle ) ) {
00253 return $oParent->inCategory( $sCatNid );
00254 }
00255 }
00256
00264 public function inPriceCategory( $sCatNid )
00265 {
00266 $oParent = $this->getParent();
00267 if ( ( $oParent instanceof oxarticle ) ) {
00268 return $oParent->inPriceCategory( $sCatNid );
00269 }
00270 }
00271
00280 public function getStdLink( $iLang = null, $aParams = array() )
00281 {
00282 if ( $iLang === null ) {
00283 $iLang = (int) $this->getLanguage();
00284 }
00285
00286 $iLinkType = $this->getLinkType();
00287 if ( !isset( $this->_aStdUrls[$iLang][$iLinkType] ) ) {
00288 $oArticle = oxNew( "oxArticle" );
00289 $oArticle->setId( $this->getId() );
00290 $oArticle->setLinkType( $iLinkType );
00291 $this->_aStdUrls[$iLang][$iLinkType] = $oArticle->getStdLink( $iLang, $aParams );
00292 }
00293
00294 return $this->_aStdUrls[$iLang][$iLinkType];
00295 }
00296
00304 public function getBaseSeoLink( $iLang )
00305 {
00306 return oxSeoEncoderArticle::getInstance()->getArticleUrl( $this, $iLang, $iLinkType );
00307 }
00308
00316 public function getLink( $iLang = null )
00317 {
00318 if ( $iLang === null ) {
00319 $iLang = (int) $this->getLanguage();
00320 }
00321
00322 if ( !oxUtils::getInstance()->seoIsActive() ) {
00323 return $this->getStdLink( $iLang );
00324 }
00325
00326 $iLinkType = $this->getLinkType();
00327 if ( !isset( $this->_aSeoUrls[$iLang][$iLinkType] ) ) {
00328 $this->_aSeoUrls[$iLang][$iLinkType] = $this->getBaseSeoLink( $iLang );
00329 }
00330 return $this->_aSeoUrls[$iLang][$iLinkType];
00331
00332 }
00333 }