OXID eShop CE  4.8.12
 All Classes Files Functions Variables Pages
pricealarm.php
Go to the documentation of this file.
1 <?php
2 
11 class Pricealarm extends oxUBase
12 {
17  protected $_sThisTemplate = 'pricealarm.tpl';
18 
23  protected $_oArticle = null;
24 
29  protected $_sBidPrice = null;
30 
35  protected $_iPriceAlarmStatus = null;
36 
46  public function addme()
47  {
48  $myConfig = $this->getConfig();
49  $myUtils = oxRegistry::getUtils();
50 
51  //control captcha
52  $sMac = oxConfig::getParameter( 'c_mac' );
53  $sMacHash = oxConfig::getParameter( 'c_mach' );
54  $oCaptcha = oxNew('oxCaptcha');
55  if ( !$oCaptcha->pass( $sMac, $sMacHash )) {
56  $this->_iPriceAlarmStatus = 2;
57  return;
58  }
59 
60  $aParams = oxConfig::getParameter( 'pa' );
61  if ( !isset( $aParams['email'] ) || !$myUtils->isValidEmail( $aParams['email'] ) ) {
62  $this->_iPriceAlarmStatus = 0;
63  return;
64  }
65 
66  $oCur = $myConfig->getActShopCurrencyObject();
67  // convert currency to default
68  $dPrice = $myUtils->currency2Float( $aParams['price'] );
69 
70  $oAlarm = oxNew( "oxpricealarm" );
71  $oAlarm->oxpricealarm__oxuserid = new oxField( oxSession::getVar( 'usr' ));
72  $oAlarm->oxpricealarm__oxemail = new oxField( $aParams['email']);
73  $oAlarm->oxpricealarm__oxartid = new oxField( $aParams['aid']);
74  $oAlarm->oxpricealarm__oxprice = new oxField( $myUtils->fRound( $dPrice, $oCur ));
75  $oAlarm->oxpricealarm__oxshopid = new oxField( $myConfig->getShopId());
76  $oAlarm->oxpricealarm__oxcurrency = new oxField( $oCur->name);
77 
78  $oAlarm->oxpricealarm__oxlang = new oxField(oxRegistry::getLang()->getBaseLanguage());
79 
80  $oAlarm->save();
81 
82  // Send Email
83  $oEmail = oxNew( 'oxemail' );
84  $this->_iPriceAlarmStatus = (int) $oEmail->sendPricealarmNotification( $aParams, $oAlarm );
85  }
86 
92  public function getBidPrice()
93  {
94  if ( $this->_sBidPrice === null ) {
95  $this->_sBidPrice = false;
96 
97  $aParams = $this->_getParams();
98  $oCur = $this->getConfig()->getActShopCurrencyObject();
99  $iPrice = oxRegistry::getUtils()->currency2Float( $aParams['price'] );
100  $this->_sBidPrice = oxRegistry::getLang()->formatCurrency( $iPrice, $oCur );
101  }
102  return $this->_sBidPrice;
103  }
104 
110  public function getProduct()
111  {
112  if ( $this->_oArticle === null ) {
113  $this->_oArticle = false;
114  $aParams = $this->_getParams();
115  $oArticle = oxNew( 'oxarticle' );
116  $oArticle->load( $aParams['aid'] );
117  $this->_oArticle = $oArticle;
118  }
119  return $this->_oArticle;
120  }
121 
127  private function _getParams()
128  {
129  return oxConfig::getParameter( 'pa' );
130  }
131 
137  public function getPriceAlarmStatus()
138  {
140  }
141 
142 }