OXID eShop CE  4.8.12
 All Classes Files Functions Variables Pages
oxpricealarm.php
Go to the documentation of this file.
1 <?php
2 
8 class oxPricealarm extends oxBase
9 {
15  protected $_sClassName = 'oxpricealarm';
16 
22  protected $_oArticle = null;
23 
29  protected $_fPrice = null;
30 
36  protected $_dPrice = null;
37 
43  protected $_sTitle = null;
44 
50  protected $_oCurrency = null;
51 
57  protected $_fProposedPrice = null;
58 
64  protected $_iStatus = null;
65 
70  public function __construct()
71  {
73  $this->init( 'oxpricealarm' );
74  }
75 
81  protected function _insert()
82  {
83  // set oxinsert value
84  $this->oxpricealarm__oxinsert = new oxField(date( 'Y-m-d', oxRegistry::get("oxUtilsDate")->getTime() ));
85 
86  return parent::_insert();
87  }
88 
94  public function getArticle()
95  {
96  if ( $this->_oArticle == null ) {
97  $this->_oArticle = false;
98  $oArticle = oxNew( "oxarticle" );
99  if ( $oArticle->load($this->oxpricealarm__oxartid->value) ) {
100  $this->_oArticle = $oArticle;
101  }
102  }
103  return $this->_oArticle;
104  }
105 
111  public function getFPrice()
112  {
113  if ( $this->_fPrice == null ) {
114  $this->_fPrice = false;
115  if ( $dArtPrice = $this->getPrice() ) {
116  $myLang = oxRegistry::getLang();
117  $oThisCurr = $this->getPriceAlarmCurrency();
118  $this->_fPrice = $myLang->formatCurrency( $dArtPrice, $oThisCurr );
119  }
120  }
121  return $this->_fPrice;
122  }
123 
129  public function getPrice()
130  {
131  if ( $this->_dPrice == null ) {
132  $this->_dPrice = false;
133  if ( $oArticle = $this->getArticle() ) {
134  $myUtils = oxRegistry::getUtils();
135  $oThisCurr = $this->getPriceAlarmCurrency();
136 
137  // #889C - Netto prices in Admin
138  // (we have to call $oArticle->getPrice() to get price with VAT)
139  $dArtPrice = $oArticle->getPrice()->getBruttoPrice() * $oThisCurr->rate;
140  $dArtPrice = $myUtils->fRound( $dArtPrice );
141 
142  $this->_dPrice = $dArtPrice;
143  }
144  }
145  return $this->_dPrice;
146  }
147 
153  public function getTitle()
154  {
155  if ( $this->_sTitle == null ) {
156  $this->_sTitle = false;
157  if ( $oArticle = $this->getArticle() ) {
158  $this->_sTitle = $oArticle->oxarticles__oxtitle->value;
159  if ( $oArticle->oxarticles__oxparentid->value && !$oArticle->oxarticles__oxtitle->value) {
160  $oParent = oxNew( "oxarticle" );
161  $oParent->load( $oArticle->oxarticles__oxparentid->value );
162  $this->_sTitle = $oParent->oxarticles__oxtitle->value . " " . $oArticle->oxarticles__oxvarselect->value;
163  }
164  }
165  }
166  return $this->_sTitle;
167  }
168 
174  public function getPriceAlarmCurrency()
175  {
176  if ( $this->_oCurrency == null ) {
177  $this->_oCurrency = false;
178  $myConfig = $this->getConfig();
179  $oThisCurr = $myConfig->getCurrencyObject( $this->oxpricealarm__oxcurrency->value );
180 
181  // #869A we should perform currency conversion
182  // (older versions doesn't have currency info - assume as it is default - first in currency array)
183  if ( !$oThisCurr ) {
184  $oDefCurr = $myConfig->getActShopCurrencyObject();
185  $oThisCurr = $myConfig->getCurrencyObject( $oDefCurr->name );
186  $this->oxpricealarm__oxcurrency->setValue($oDefCurr->name);
187  }
188  $this->_oCurrency = $oThisCurr;
189  }
190  return $this->_oCurrency;
191  }
192 
198  public function getFProposedPrice()
199  {
200  if ( $this->_fProposedPrice == null ) {
201  $this->_fProposedPrice = false;
202  if ( $oThisCurr = $this->getPriceAlarmCurrency() ) {
203  $myLang = oxRegistry::getLang();
204  $this->_fProposedPrice = $myLang->formatCurrency( $this->oxpricealarm__oxprice->value, $oThisCurr);
205  }
206  }
207  return $this->_fProposedPrice;
208  }
209 
215  public function getPriceAlarmStatus()
216  {
217  if ( $this->_iStatus == null ) {
218  // neutral status
219  $this->_iStatus = 0;
220 
221  // shop price is less or equal
222  $dArtPrice = $this->getPrice();
223  if ( $this->oxpricealarm__oxprice->value >= $dArtPrice) {
224  $this->_iStatus = 1;
225  }
226 
227  // suggestion to user is sent
228  if ( $this->oxpricealarm__oxsended->value != "0000-00-00 00:00:00") {
229  $this->_iStatus = 2;
230  }
231  }
232  return $this->_iStatus;
233  }
234 }