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