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 $_sDetailLink = null;
00036
00042 protected $_sStdLink = null;
00043
00044
00049 public function __construct()
00050 {
00051 parent::__construct();
00052 $this->_sCacheKey = "simplevariants";
00053 $this->init( 'oxarticles' );
00054 }
00055
00063 public function __get($sName)
00064 {
00065 $myUtils = oxUtils::getInstance();
00066 switch ($sName) {
00067 case 'aSelectlist' :
00068 if ( $this->getConfig()->getConfigParam( 'bl_perfLoadSelectLists' ) ) {
00069 return $this->aSelectlist = $this->getSelectLists();
00070 }
00071 return;
00072 break;
00073 }
00074
00075 return parent::__get($sName);
00076 }
00077
00084 public function getSelectLists()
00085 {
00086 return null;
00087 }
00088
00094 public function getPrice()
00095 {
00096 if (!is_null($this->_oPrice)) {
00097 return $this->_oPrice;
00098 }
00099
00100 $this->_oPrice = oxNew("oxPrice");
00101 $dPrice = $this->oxarticles__oxprice->value;
00102 if (!$dPrice) {
00103 $dPrice = $this->_getParentPrice();
00104 }
00105
00106 $this->_oPrice->setPrice($dPrice, $this->_dVat);
00107
00108 $this->_applyParentVat($this->_oPrice);
00109 $this->_applyCurrency($this->_oPrice);
00110
00111 $this->_applyParentDiscounts($this->_oPrice);
00112
00113 return $this->_oPrice;
00114 }
00115
00124 protected function _applyCurrency(oxPrice $oPrice, $oCur = null )
00125 {
00126 if ( !$oCur ) {
00127 $oCur = $this->getConfig()->getActShopCurrencyObject();
00128 }
00129
00130 $oPrice->multiply($oCur->rate);
00131 }
00132
00140 protected function _applyParentDiscounts( $oPrice )
00141 {
00142 $oParent = $this->getParent();
00143 if (!($oParent instanceof oxarticle)) {
00144 return;
00145 }
00146
00147 $oParent->applyDiscountsForVariant( $oPrice );
00148
00149 }
00150
00158 protected function _applyParentVat($oPrice)
00159 {
00160 $oParent = $this->getParent();
00161 if (!($oParent instanceof oxarticle)) {
00162 return;
00163 }
00164
00165 $oParent->applyVats($oPrice);
00166 }
00167
00175 public function setPrice($oPrice)
00176 {
00177 $this->_oPrice = $oPrice;
00178 }
00179
00185 public function getFPrice()
00186 {
00187 if ( $oPrice = $this->getPrice() ) {
00188 return oxLang::getInstance()->formatCurrency( $oPrice->getBruttoPrice() );
00189 } else {
00190 return null;
00191 }
00192 }
00193
00201 public function setParent($oParent)
00202 {
00203 $this->_oParent = $oParent;
00204 }
00205
00211 public function getParent()
00212 {
00213 return $this->_oParent;
00214 }
00215
00221 protected function _getParentPrice()
00222 {
00223 if (isset($this->_oParent->oxarticles__oxprice->value)) {
00224 return $this->_oParent->oxarticles__oxprice->value;
00225 }
00226
00227 return 0;
00228 }
00229
00235 public function getLinkType()
00236 {
00237 $oParent = $this->getParent();
00238 if (!($oParent instanceof oxarticle)) {
00239 return 0;
00240 }
00241
00242 return $oParent->getLinkType();
00243 }
00244
00252 public function inCategory( $sCatNid )
00253 {
00254 $oParent = $this->getParent();
00255 if (!($oParent instanceof oxarticle)) {
00256 return;
00257 }
00258
00259 return $oParent->inCategory( $sCatNid );
00260 }
00261
00269 public function inPriceCategory( $sCatNid )
00270 {
00271 $oParent = $this->getParent();
00272 if (!($oParent instanceof oxarticle)) {
00273 return;
00274 }
00275
00276 return $oParent->inPriceCategory( $sCatNid );
00277 }
00278
00287 public function getStdLink( $iLang = null, $aParams = array() )
00288 {
00289 if ( $this->_sStdLink === null ) {
00290 $oArticle = oxNew( "oxArticle" );
00291 $oArticle->setId( $this->getId() );
00292 $oArticle->setLinkType( $this->getLinkType() );
00293 $this->_sStdLink = $oArticle->getStdLink( $iLang );
00294 }
00295
00296 return $this->_sStdLink;
00297 }
00298
00306 public function getLink( $iLang = null )
00307 {
00308 if ( isset($iLang) ) {
00309 $iLang = (int) $iLang;
00310 if ($iLang == (int) $this->getLanguage() ) {
00311 $iLang = null;
00312 }
00313 }
00314 if ( $this->_sDetailLink === null || isset($iLang) ) {
00315 if ( oxUtils::getInstance()->seoIsActive() ) {
00316 $oxdetaillink = oxSeoEncoderArticle::getInstance()->getArticleUrl( $this, $iLang, $this->getLinkType() );
00317 } else {
00318 $oxdetaillink = $this->getStdLink( $iLang );
00319 }
00320
00321 if ( isset($iLang) ) {
00322 return $oxdetaillink;
00323 } else {
00324 $this->_sDetailLink = $oxdetaillink;
00325 }
00326 }
00327
00328 return $this->_sDetailLink;
00329 }
00330 }