OXID eShop CE  4.10.7
 All Classes Namespaces Files Functions Variables Pages
oxpricealarm.php
Go to the documentation of this file.
1 <?php
2 
8 class oxPricealarm extends oxBase
9 {
10 
16  protected $_sClassName = 'oxpricealarm';
17 
23  protected $_oArticle = null;
24 
30  protected $_fPrice = null;
31 
37  protected $_dPrice = null;
38 
44  protected $_sTitle = null;
45 
51  protected $_oCurrency = null;
52 
58  protected $_fProposedPrice = null;
59 
65  protected $_iStatus = null;
66 
71  public function __construct()
72  {
74  $this->init('oxpricealarm');
75  }
76 
82  protected function _insert()
83  {
84  // set oxinsert value
85  $this->oxpricealarm__oxinsert = new oxField(date('Y-m-d', oxRegistry::get("oxUtilsDate")->getTime()));
86 
87  return parent::_insert();
88  }
89 
95  public function getArticle()
96  {
97  if ($this->_oArticle == null) {
98  $this->_oArticle = false;
99  $oArticle = oxNew("oxarticle");
100  if ($oArticle->load($this->oxpricealarm__oxartid->value)) {
101  $this->_oArticle = $oArticle;
102  }
103  }
104 
105  return $this->_oArticle;
106  }
107 
113  public function getFPrice()
114  {
115  if ($this->_fPrice == null) {
116  $this->_fPrice = false;
117  if ($dArtPrice = $this->getPrice()) {
118  $myLang = oxRegistry::getLang();
119  $oThisCurr = $this->getPriceAlarmCurrency();
120  $this->_fPrice = $myLang->formatCurrency($dArtPrice, $oThisCurr);
121  }
122  }
123 
124  return $this->_fPrice;
125  }
126 
132  public function getPrice()
133  {
134  if ($this->_dPrice == null) {
135  $this->_dPrice = false;
136  if ($oArticle = $this->getArticle()) {
137  $myUtils = oxRegistry::getUtils();
138  $oThisCurr = $this->getPriceAlarmCurrency();
139 
140  // #889C - Netto prices in Admin
141  // (we have to call $oArticle->getPrice() to get price with VAT)
142  $dArtPrice = $oArticle->getPrice()->getBruttoPrice() * $oThisCurr->rate;
143  $dArtPrice = $myUtils->fRound($dArtPrice);
144 
145  $this->_dPrice = $dArtPrice;
146  }
147  }
148 
149  return $this->_dPrice;
150  }
151 
157  public function getTitle()
158  {
159  if ($this->_sTitle == null) {
160  $this->_sTitle = false;
161  if ($oArticle = $this->getArticle()) {
162  $this->_sTitle = $oArticle->oxarticles__oxtitle->value;
163  if ($oArticle->oxarticles__oxparentid->value && !$oArticle->oxarticles__oxtitle->value) {
164  $oParent = oxNew("oxarticle");
165  $oParent->load($oArticle->oxarticles__oxparentid->value);
166  $this->_sTitle = $oParent->oxarticles__oxtitle->value . " " . $oArticle->oxarticles__oxvarselect->value;
167  }
168  }
169  }
170 
171  return $this->_sTitle;
172  }
173 
179  public function getPriceAlarmCurrency()
180  {
181  if ($this->_oCurrency == null) {
182  $this->_oCurrency = false;
183  $myConfig = $this->getConfig();
184  $oThisCurr = $myConfig->getCurrencyObject($this->oxpricealarm__oxcurrency->value);
185 
186  // #869A we should perform currency conversion
187  // (older versions doesn't have currency info - assume as it is default - first in currency array)
188  if (!$oThisCurr) {
189  $oDefCurr = $myConfig->getActShopCurrencyObject();
190  $oThisCurr = $myConfig->getCurrencyObject($oDefCurr->name);
191  $this->oxpricealarm__oxcurrency->setValue($oDefCurr->name);
192  }
193  $this->_oCurrency = $oThisCurr;
194  }
195 
196  return $this->_oCurrency;
197  }
198 
204  public function getFProposedPrice()
205  {
206  if ($this->_fProposedPrice == null) {
207  $this->_fProposedPrice = false;
208  if ($oThisCurr = $this->getPriceAlarmCurrency()) {
209  $myLang = oxRegistry::getLang();
210  $this->_fProposedPrice = $myLang->formatCurrency($this->oxpricealarm__oxprice->value, $oThisCurr);
211  }
212  }
213 
214  return $this->_fProposedPrice;
215  }
216 
222  public function getPriceAlarmStatus()
223  {
224  if ($this->_iStatus == null) {
225  // neutral status
226  $this->_iStatus = 0;
227 
228  // shop price is less or equal
229  $dArtPrice = $this->getPrice();
230  if ($this->oxpricealarm__oxprice->value >= $dArtPrice) {
231  $this->_iStatus = 1;
232  }
233 
234  // suggestion to user is sent
235  if ($this->oxpricealarm__oxsended->value != "0000-00-00 00:00:00") {
236  $this->_iStatus = 2;
237  }
238  }
239 
240  return $this->_iStatus;
241  }
242 }