OXID eShop CE  4.10.2
 All Classes Namespaces Files Functions Variables Pages
pricealarm.php
Go to the documentation of this file.
1 <?php
2 
11 class Pricealarm extends oxUBase
12 {
13 
19  protected $_sThisTemplate = 'pricealarm.tpl';
20 
26  protected $_oArticle = null;
27 
33  protected $_sBidPrice = null;
34 
40  protected $_iPriceAlarmStatus = null;
41 
51  public function addme()
52  {
53  $myConfig = $this->getConfig();
54  $myUtils = oxRegistry::getUtils();
55 
56  //control captcha
57  $sMac = oxRegistry::getConfig()->getRequestParameter('c_mac');
58  $sMacHash = oxRegistry::getConfig()->getRequestParameter('c_mach');
59  $oCaptcha = oxNew('oxCaptcha');
60  if (!$oCaptcha->pass($sMac, $sMacHash)) {
61  $this->_iPriceAlarmStatus = 2;
62 
63  return;
64  }
65 
66  $aParams = oxRegistry::getConfig()->getRequestParameter('pa');
67  if (!isset($aParams['email']) || !$myUtils->isValidEmail($aParams['email'])) {
68  $this->_iPriceAlarmStatus = 0;
69 
70  return;
71  }
72 
73  $oCur = $myConfig->getActShopCurrencyObject();
74  // convert currency to default
75  $dPrice = $myUtils->currency2Float($aParams['price']);
76 
77  $oAlarm = oxNew("oxpricealarm");
78  $oAlarm->oxpricealarm__oxuserid = new oxField(oxRegistry::getSession()->getVariable('usr'));
79  $oAlarm->oxpricealarm__oxemail = new oxField($aParams['email']);
80  $oAlarm->oxpricealarm__oxartid = new oxField($aParams['aid']);
81  $oAlarm->oxpricealarm__oxprice = new oxField($myUtils->fRound($dPrice, $oCur));
82  $oAlarm->oxpricealarm__oxshopid = new oxField($myConfig->getShopId());
83  $oAlarm->oxpricealarm__oxcurrency = new oxField($oCur->name);
84 
85  $oAlarm->oxpricealarm__oxlang = new oxField(oxRegistry::getLang()->getBaseLanguage());
86 
87  $oAlarm->save();
88 
89  // Send Email
90  $oEmail = oxNew('oxemail');
91  $this->_iPriceAlarmStatus = (int) $oEmail->sendPricealarmNotification($aParams, $oAlarm);
92  }
93 
99  public function getBidPrice()
100  {
101  if ($this->_sBidPrice === null) {
102  $this->_sBidPrice = false;
103 
104  $aParams = $this->_getParams();
105  $oCur = $this->getConfig()->getActShopCurrencyObject();
106  $iPrice = oxRegistry::getUtils()->currency2Float($aParams['price']);
107  $this->_sBidPrice = oxRegistry::getLang()->formatCurrency($iPrice, $oCur);
108  }
109 
110  return $this->_sBidPrice;
111  }
112 
118  public function getProduct()
119  {
120  if ($this->_oArticle === null) {
121  $this->_oArticle = false;
122  $aParams = $this->_getParams();
123  $oArticle = oxNew('oxarticle');
124  $oArticle->load($aParams['aid']);
125  $this->_oArticle = $oArticle;
126  }
127 
128  return $this->_oArticle;
129  }
130 
136  private function _getParams()
137  {
138  return oxRegistry::getConfig()->getRequestParameter('pa');
139  }
140 
146  public function getPriceAlarmStatus()
147  {
149  }
150 }