OXID eShop CE  4.9.7
 All Classes Files Functions Variables Pages
suggest.php
Go to the documentation of this file.
1 <?php
2 
8 class Suggest extends oxUBase
9 {
10 
16  protected $_sThisTemplate = 'page/info/suggest.tpl';
17 
23  protected $_aReqFields = array('rec_name', 'rec_email', 'send_name', 'send_email', 'send_message', 'send_subject');
24 
30  protected $_oCrossSelling = null;
31 
37  protected $_oSimilarProducts = null;
38 
44  protected $_oRecommList = null;
45 
51  protected $_aSuggestData = null;
52 
58  protected $_oCaptcha = null;
59 
69  public function send()
70  {
71  $aParams = oxRegistry::getConfig()->getRequestParameter('editval', true);
72  if (!is_array($aParams)) {
73  return;
74  }
75 
76  // storing used written values
77  $oParams = (object) $aParams;
78  $this->setSuggestData((object) oxRegistry::getConfig()->getRequestParameter('editval'));
79 
80  // spam spider prevension
81  $sMac = oxRegistry::getConfig()->getRequestParameter('c_mac');
82  $sMacHash = oxRegistry::getConfig()->getRequestParameter('c_mach');
83  $oCaptcha = $this->getCaptcha();
84  $oUtilsView = oxRegistry::get("oxUtilsView");
85 
86  if (!$oCaptcha->pass($sMac, $sMacHash)) {
87  // even if there is no exception, use this as a default display method
88  $oUtilsView->addErrorToDisplay('MESSAGE_WRONG_VERIFICATION_CODE');
89 
90  return false;
91  }
92 
93  // filled not all fields ?
94  foreach ($this->_aReqFields as $sFieldName) {
95  if (!isset($aParams[$sFieldName]) || !$aParams[$sFieldName]) {
96  $oUtilsView->addErrorToDisplay('SUGGEST_COMLETECORRECTLYFIELDS');
97 
98  return;
99  }
100  }
101 
102  $oUtils = oxRegistry::getUtils();
103  if (!$oUtils->isValidEmail($aParams["rec_email"]) || !$oUtils->isValidEmail($aParams["send_email"])) {
104  $oUtilsView->addErrorToDisplay('SUGGEST_INVALIDMAIL');
105 
106  return;
107  }
108 
109  $sReturn = "";
110  // #1834M - specialchar search
111  $sSearchParamForLink = rawurlencode(oxRegistry::getConfig()->getRequestParameter('searchparam', true));
112  if ($sSearchParamForLink) {
113  $sReturn .= "&searchparam=$sSearchParamForLink";
114  }
115 
116  $sSearchCatId = oxRegistry::getConfig()->getRequestParameter('searchcnid');
117  if ($sSearchCatId) {
118  $sReturn .= "&searchcnid=$sSearchCatId";
119  }
120 
121  $sSearchVendor = oxRegistry::getConfig()->getRequestParameter('searchvendor');
122  if ($sSearchVendor) {
123  $sReturn .= "&searchvendor=$sSearchVendor";
124  }
125 
126  if (($sSearchManufacturer = oxRegistry::getConfig()->getRequestParameter('searchmanufacturer'))) {
127  $sReturn .= "&searchmanufacturer=$sSearchManufacturer";
128  }
129 
130  $sListType = oxRegistry::getConfig()->getRequestParameter('listtype');
131  if ($sListType) {
132  $sReturn .= "&listtype=$sListType";
133  }
134 
135  // sending suggest email
136  $oEmail = oxNew('oxemail');
137  $oProduct = $this->getProduct();
138  if ($oProduct && $oEmail->sendSuggestMail($oParams, $oProduct)) {
139  return 'details?anid=' . $oProduct->getId() . $sReturn;
140  } else {
141  $oUtilsView->addErrorToDisplay('SUGGEST_INVALIDMAIL');
142  }
143  }
144 
150  public function getProduct()
151  {
152  if ($this->_oProduct === null) {
153  $this->_oProduct = false;
154 
155  if ($sProductId = $this->getConfig()->getRequestParameter('anid')) {
156  $oProduct = oxNew('oxArticle');
157  $oProduct->load($sProductId);
158  $this->_oProduct = $oProduct;
159  }
160  }
161 
162  return $this->_oProduct;
163  }
164 
170  public function getCrossSelling()
171  {
172  if ($this->_oCrossSelling === null) {
173  $this->_oCrossSelling = false;
174  if ($oProduct = $this->getProduct()) {
175  $this->_oCrossSelling = $oProduct->getCrossSelling();
176  }
177  }
178 
179  return $this->_oCrossSelling;
180  }
181 
187  public function getSimilarProducts()
188  {
189  if ($this->_oSimilarProducts === null) {
190  $this->_oSimilarProducts = false;
191  if ($oProduct = $this->getProduct()) {
192  $this->_oSimilarProducts = $oProduct->getSimilarProducts();
193  }
194  }
195 
197  }
198 
204  public function getRecommList()
205  {
206  if (!$this->getViewConfig()->getShowListmania()) {
207  return false;
208  }
209 
210  if ($this->_oRecommList === null) {
211  $this->_oRecommList = false;
212  if ($oProduct = $this->getProduct()) {
213  $oRecommList = oxNew('oxrecommlist');
214  $this->_oRecommList = $oRecommList->getRecommListsByIds(array($oProduct->getId()));
215  }
216  }
217 
218  return $this->_oRecommList;
219  }
220 
226  public function setSuggestData($oData)
227  {
228  $this->_aSuggestData = $oData;
229  }
230 
236  public function getSuggestData()
237  {
238  return $this->_aSuggestData;
239  }
240 
248  public function getLink($iLang = null)
249  {
250  $sLink = parent::getLink($iLang);
251 
252  // active category
253  if ($sVal = oxRegistry::getConfig()->getRequestParameter('cnid')) {
254  $sLink .= ((strpos($sLink, '?') === false) ? '?' : '&amp;') . "cnid={$sVal}";
255  }
256 
257  // active article
258  if ($sVal = oxRegistry::getConfig()->getRequestParameter('anid')) {
259  $sLink .= ((strpos($sLink, '?') === false) ? '?' : '&amp;') . "anid={$sVal}";
260  }
261 
262  return $sLink;
263  }
264 
270  public function getCaptcha()
271  {
272  if ($this->_oCaptcha === null) {
273  $this->_oCaptcha = oxNew('oxCaptcha');
274  }
275 
276  return $this->_oCaptcha;
277  }
278 
284  public function getBreadCrumb()
285  {
286  $aPaths = array();
287  $aPath = array();
288  $iBaseLanguage = oxRegistry::getLang()->getBaseLanguage();
289  $aPath['title'] = oxRegistry::getLang()->translateString('RECOMMEND_PRODUCT', $iBaseLanguage, false);
290  $aPath['link'] = $this->getLink();
291 
292  $aPaths[] = $aPath;
293 
294  return $aPaths;
295  }
296 }