OXID eShop CE  4.9.6
 All Classes Files Functions Variables Pages
pricealarm_main.php
Go to the documentation of this file.
1 <?php
2 
9 {
10 
18  public function render()
19  {
20  $myConfig = $this->getConfig();
21 
22  // #1140 R - price must be checked from the object.
23  $sSql = "select oxarticles.oxid, oxpricealarm.oxprice from oxpricealarm, oxarticles " .
24  "where oxarticles.oxid = oxpricealarm.oxartid and oxpricealarm.oxsended = '000-00-00 00:00:00'";
25  $rs = oxDb::getDb()->Execute($sSql);
26  $iAllCnt = 0;
27 
28  if ($rs != false && $rs->recordCount() > 0) {
29  while (!$rs->EOF) {
30  $oArticle = oxNew("oxarticle");
31  $oArticle->load($rs->fields[0]);
32  if ($oArticle->getPrice()->getBruttoPrice() <= $rs->fields[1]) {
33  $iAllCnt++;
34  }
35  $rs->moveNext();
36  }
37  }
38  $this->_aViewData['iAllCnt'] = $iAllCnt;
39 
40  $soxId = $this->_aViewData["oxid"] = $this->getEditObjectId();
41  if ($soxId != "-1" && isset($soxId)) {
42  // load object
43  $oPricealarm = oxNew("oxpricealarm");
44  $oPricealarm->load($soxId);
45 
46  // customer info
47  $oUser = null;
48  if ($oPricealarm->oxpricealarm__oxuserid->value) {
49  $oUser = oxNew("oxuser");
50  $oUser->load($oPricealarm->oxpricealarm__oxuserid->value);
51  $oPricealarm->oUser = $oUser;
52  }
53 
54  //
55  $oShop = oxNew("oxshop");
56  $oShop->load($myConfig->getShopId());
57  $oShop = $this->addGlobalParams($oShop);
58 
59  if (!($iLang = $oPricealarm->oxpricealarm__oxlang->value)) {
60  $iLang = 0;
61  }
62 
63  $oLang = oxRegistry::getLang();
64  $aLanguages = $oLang->getLanguageNames();
65  $this->_aViewData["edit_lang"] = $aLanguages[$iLang];
66  // rendering mail message text
67  $oLetter = new stdClass();
68  $aParams = oxRegistry::getConfig()->getRequestParameter("editval");
69  if (isset($aParams['oxpricealarm__oxlongdesc']) && $aParams['oxpricealarm__oxlongdesc']) {
70  $oLetter->oxpricealarm__oxlongdesc = new oxField(stripslashes($aParams['oxpricealarm__oxlongdesc']), oxField::T_RAW);
71  } else {
72  /*
73  $smarty = oxRegistry::get("oxUtilsView")->getSmarty();
74  $smarty->assign( "shop", $oShop );
75  $smarty->assign( "product", $oPricealarm->getArticle() );
76  $smarty->assign( "bidprice", $oPricealarm->getFProposedPrice());
77  $smarty->assign( "currency", $oPricealarm->getPriceAlarmCurrency() );
78  $smarty->assign( "currency", $oPricealarm->getPriceAlarmCurrency() );
79  */
80 
81 
82  $oEmail = oxNew("oxEmail");
83  $sDesc = $oEmail->sendPricealarmToCustomer($oPricealarm->oxpricealarm__oxemail->value, $oPricealarm, null, true);
84 
85  $iOldLang = $oLang->getTplLanguage();
86  $oLang->setTplLanguage($iLang);
87  $oLetter->oxpricealarm__oxlongdesc = new oxField($sDesc, oxField::T_RAW);
88  $oLang->setTplLanguage($iOldLang);
89  }
90 
91  $this->_aViewData["editor"] = $this->_generateTextEditor("100%", 300, $oLetter, "oxpricealarm__oxlongdesc", "details.tpl.css");
92  $this->_aViewData["edit"] = $oPricealarm;
93  $this->_aViewData["actshop"] = $myConfig->getShopId();
94  }
95 
97 
98  return "pricealarm_main.tpl";
99  }
100 
104  public function send()
105  {
106  $blError = true;
107 
108  // error
109  if (($sOxid = $this->getEditObjectId())) {
110  $oPricealarm = oxNew("oxpricealarm");
111  $oPricealarm->load($sOxid);
112 
113  $aParams = oxRegistry::getConfig()->getRequestParameter("editval");
114  $sMailBody = isset($aParams['oxpricealarm__oxlongdesc']) ? stripslashes($aParams['oxpricealarm__oxlongdesc']) : '';
115  if ($sMailBody) {
116  $sMailBody = oxRegistry::get("oxUtilsView")->parseThroughSmarty($sMailBody, $oPricealarm->getId());
117  }
118 
119  $sRecipient = $oPricealarm->oxpricealarm__oxemail->value;
120 
121  $oEmail = oxNew('oxemail');
122  $blSuccess = (int) $oEmail->sendPricealarmToCustomer($sRecipient, $oPricealarm, $sMailBody);
123 
124  // setting result message
125  if ($blSuccess) {
126  $oPricealarm->oxpricealarm__oxsended->setValue(date("Y-m-d H:i:s"));
127  $oPricealarm->save();
128  $blError = false;
129  }
130  }
131 
132  if (!$blError) {
133  $this->_aViewData["mail_succ"] = 1;
134  } else {
135  $this->_aViewData["mail_err"] = 1;
136  }
137  }
138 }