OXID eShop CE  4.8.12
 All Classes Files Functions Variables Pages
oxsimplevariant.php
Go to the documentation of this file.
1 <?php
2 
7 class oxSimpleVariant extends oxI18n implements oxIUrl
8 {
14  protected $_blUseLazyLoading = true;
15 
21  protected $_oPrice = null;
22 
28  protected $_oParent = null;
29 
35  protected $_aStdUrls = array();
36 
42  protected $_aBaseStdUrls = array();
43 
49  protected $_aSeoUrls = array();
50 
55  protected $_oUser = null;
56 
61  public function __construct()
62  {
64  $this->_sCacheKey = "simplevariants";
65  $this->init( 'oxarticles' );
66  }
67 
76  public function assign( $aRecord)
77  {
78  // load object from database
79  parent::assign( $aRecord);
80 
81  }
82 
83 
90  public function getSelectLists()
91  {
92  return null;
93  }
94 
100  public function getArticleUser()
101  {
102  if ( $this->_oUser === null ) {
103  $this->_oUser = $this->getUser();
104  }
105  return $this->_oUser;
106  }
107 
113  protected function _getGroupPrice()
114  {
115  $dPrice = $this->oxarticles__oxprice->value;
116  if ( $oUser = $this->getArticleUser() ) {
117  if ( $oUser->inGroup( 'oxidpricea' ) ) {
118  $dPrice = $this->oxarticles__oxpricea->value;
119  } elseif ( $oUser->inGroup( 'oxidpriceb' ) ) {
120  $dPrice = $this->oxarticles__oxpriceb->value;
121  } elseif ( $oUser->inGroup( 'oxidpricec' ) ) {
122  $dPrice = $this->oxarticles__oxpricec->value;
123  }
124  }
125 
126  // #1437/1436C - added config option, and check for zero A,B,C price values
127  if ( $this->getConfig()->getConfigParam( 'blOverrideZeroABCPrices' ) && (double) $dPrice == 0 ) {
128  $dPrice = $this->oxarticles__oxprice->value;
129  }
130 
131  return $dPrice;
132  }
133 
134 
140  public function getPrice()
141  {
142  $myConfig = $this->getConfig();
143  // 0002030 No need to return price if it disabled for better performance.
144  if ( !$myConfig->getConfigParam( 'bl_perfLoadPrice' ) ) {
145  return;
146  }
147 
148  if ( $this->_oPrice === null ) {
149  $this->_oPrice = oxNew( "oxPrice" );
150  if ( ( $dPrice = $this->_getGroupPrice() ) ) {
151  $this->_oPrice->setPrice( $dPrice, $this->_dVat );
152 
153  $this->_applyParentVat( $this->_oPrice );
154  $this->_applyCurrency( $this->_oPrice );
155  // apply discounts
156  $this->_applyParentDiscounts($this->_oPrice);
157  } elseif ( ( $oParent = $this->getParent() ) ) {
158  $this->_oPrice = $oParent->getPrice();
159  }
160  }
161 
162  return $this->_oPrice;
163  }
164 
173  protected function _applyCurrency(oxPrice $oPrice, $oCur = null )
174  {
175  if ( !$oCur ) {
176  $oCur = $this->getConfig()->getActShopCurrencyObject();
177  }
178 
179  $oPrice->multiply($oCur->rate);
180  }
181 
189  protected function _applyParentDiscounts( $oPrice )
190  {
191  if ( ( $oParent = $this->getParent() ) ) {
192  $oParent->applyDiscountsForVariant( $oPrice );
193  }
194  }
195 
203  protected function _applyParentVat( $oPrice )
204  {
205  if ( ( $oParent = $this->getParent() ) && !$this->getConfig()->getConfigParam( 'bl_perfCalcVatOnlyForBasketOrder' ) ) {
206  $oParent->applyVats($oPrice);
207  }
208  }
209 
217  public function setPrice($oPrice)
218  {
219  $this->_oPrice = $oPrice;
220  }
221 
227  public function getFPrice()
228  {
229  $sPrice = null;
230  if ( ( $oPrice = $this->getPrice() ) ) {
231  $sPrice = oxRegistry::getLang()->formatCurrency( $oPrice->getBruttoPrice() );
232  }
233  return $sPrice;
234  }
235 
243  public function setParent($oParent)
244  {
245  $this->_oParent = $oParent;
246  }
247 
253  public function getParent()
254  {
255  return $this->_oParent;
256  }
257 
263  public function getLinkType()
264  {
265  $iLinkType = 0;
266  if ( ( $oParent = $this->getParent() ) ) {
267  $iLinkType = $oParent->getLinkType();
268  }
269  return $iLinkType;
270  }
271 
279  public function inCategory( $sCatNid )
280  {
281  $blIn = false;
282  if ( ( $oParent = $this->getParent() ) ) {
283  $blIn = $oParent->inCategory( $sCatNid );
284  }
285  return $blIn;
286  }
287 
295  public function inPriceCategory( $sCatNid )
296  {
297  $blIn = false;
298  if ( ( $oParent = $this->getParent() ) ) {
299  $blIn = $oParent->inPriceCategory( $sCatNid );
300  }
301  return $blIn;
302  }
303 
313  public function getBaseStdLink( $iLang, $blAddId = true, $blFull = true )
314  {
315  if ( !isset( $this->_aBaseStdUrls[$iLang][$iLinkType] ) ) {
316  $oArticle = oxNew( "oxArticle" );
317  $oArticle->setId( $this->getId() );
318  $oArticle->setLinkType( $iLinkType );
319  $this->_aBaseStdUrls[$iLang][$iLinkType] = $oArticle->getBaseStdLink( $iLang, $blAddId, $blFull );
320  }
321 
322  return $this->_aBaseStdUrls[$iLang][$iLinkType];
323  }
324 
333  public function getStdLink( $iLang = null, $aParams = array() )
334  {
335  if ( $iLang === null ) {
336  $iLang = (int) $this->getLanguage();
337  }
338 
339  $iLinkType = $this->getLinkType();
340  if ( !isset( $this->_aStdUrls[$iLang][$iLinkType] ) ) {
341  $oArticle = oxNew( "oxArticle" );
342  $oArticle->setId( $this->getId() );
343  $oArticle->setLinkType( $iLinkType );
344  $this->_aStdUrls[$iLang][$iLinkType] = $oArticle->getStdLink( $iLang, $aParams );
345  }
346 
347  return $this->_aStdUrls[$iLang][$iLinkType];
348  }
349 
357  public function getBaseSeoLink( $iLang )
358  {
359  return oxRegistry::get("oxSeoEncoderArticle")->getArticleUrl( $this, $iLang, $iLinkType );
360  }
361 
369  public function getLink( $iLang = null )
370  {
371  if ( $iLang === null ) {
372  $iLang = (int) $this->getLanguage();
373  }
374 
375  if ( !oxRegistry::getUtils()->seoIsActive() ) {
376  return $this->getStdLink( $iLang );
377  }
378 
379  $iLinkType = $this->getLinkType();
380  if ( !isset( $this->_aSeoUrls[$iLang][$iLinkType] ) ) {
381  $this->_aSeoUrls[$iLang][$iLinkType] = $this->getBaseSeoLink( $iLang );
382  }
383  return $this->_aSeoUrls[$iLang][$iLinkType];
384 
385  }
386 }