OXID eShop CE  4.10.3
 All Classes Namespaces 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 
46  protected $_oRecommList = null;
47 
55  protected $_aSuggestData = null;
56 
64  protected $_oCaptcha = null;
65 
75  public function send()
76  {
77  $aParams = oxRegistry::getConfig()->getRequestParameter('editval', true);
78  if (!is_array($aParams)) {
79  return;
80  }
81 
82  // storing used written values
83  $oParams = (object) $aParams;
84  $this->setSuggestData((object) oxRegistry::getConfig()->getRequestParameter('editval'));
85 
86  // spam spider prevension
87  $sMac = oxRegistry::getConfig()->getRequestParameter('c_mac');
88  $sMacHash = oxRegistry::getConfig()->getRequestParameter('c_mach');
89  $oCaptcha = $this->getCaptcha();
90  $oUtilsView = oxRegistry::get("oxUtilsView");
91 
92  if (!$oCaptcha->pass($sMac, $sMacHash)) {
93  // even if there is no exception, use this as a default display method
94  $oUtilsView->addErrorToDisplay('MESSAGE_WRONG_VERIFICATION_CODE');
95 
96  return false;
97  }
98 
99  // filled not all fields ?
100  foreach ($this->_aReqFields as $sFieldName) {
101  if (!isset($aParams[$sFieldName]) || !$aParams[$sFieldName]) {
102  $oUtilsView->addErrorToDisplay('SUGGEST_COMLETECORRECTLYFIELDS');
103 
104  return;
105  }
106  }
107 
108  $oUtils = oxRegistry::getUtils();
109  if (!$oUtils->isValidEmail($aParams["rec_email"]) || !$oUtils->isValidEmail($aParams["send_email"])) {
110  $oUtilsView->addErrorToDisplay('SUGGEST_INVALIDMAIL');
111 
112  return;
113  }
114 
115  $sReturn = "";
116  // #1834M - specialchar search
117  $sSearchParamForLink = rawurlencode(oxRegistry::getConfig()->getRequestParameter('searchparam', true));
118  if ($sSearchParamForLink) {
119  $sReturn .= "&searchparam=$sSearchParamForLink";
120  }
121 
122  $sSearchCatId = oxRegistry::getConfig()->getRequestParameter('searchcnid');
123  if ($sSearchCatId) {
124  $sReturn .= "&searchcnid=$sSearchCatId";
125  }
126 
127  $sSearchVendor = oxRegistry::getConfig()->getRequestParameter('searchvendor');
128  if ($sSearchVendor) {
129  $sReturn .= "&searchvendor=$sSearchVendor";
130  }
131 
132  if (($sSearchManufacturer = oxRegistry::getConfig()->getRequestParameter('searchmanufacturer'))) {
133  $sReturn .= "&searchmanufacturer=$sSearchManufacturer";
134  }
135 
136  $sListType = oxRegistry::getConfig()->getRequestParameter('listtype');
137  if ($sListType) {
138  $sReturn .= "&listtype=$sListType";
139  }
140 
141  // sending suggest email
142  $oEmail = oxNew('oxemail');
143  $oProduct = $this->getProduct();
144  if ($oProduct && $oEmail->sendSuggestMail($oParams, $oProduct)) {
145  return 'details?anid=' . $oProduct->getId() . $sReturn;
146  } else {
147  $oUtilsView->addErrorToDisplay('SUGGEST_INVALIDMAIL');
148  }
149  }
150 
156  public function getProduct()
157  {
158  if ($this->_oProduct === null) {
159  $this->_oProduct = false;
160 
161  if ($sProductId = $this->getConfig()->getRequestParameter('anid')) {
162  $oProduct = oxNew('oxArticle');
163  $oProduct->load($sProductId);
164  $this->_oProduct = $oProduct;
165  }
166  }
167 
168  return $this->_oProduct;
169  }
170 
176  public function getCrossSelling()
177  {
178  if ($this->_oCrossSelling === null) {
179  $this->_oCrossSelling = false;
180  if ($oProduct = $this->getProduct()) {
181  $this->_oCrossSelling = $oProduct->getCrossSelling();
182  }
183  }
184 
185  return $this->_oCrossSelling;
186  }
187 
193  public function getSimilarProducts()
194  {
195  if ($this->_oSimilarProducts === null) {
196  $this->_oSimilarProducts = false;
197  if ($oProduct = $this->getProduct()) {
198  $this->_oSimilarProducts = $oProduct->getSimilarProducts();
199  }
200  }
201 
203  }
204 
212  public function getRecommList()
213  {
214  if (!$this->getViewConfig()->getShowListmania()) {
215  return false;
216  }
217 
218  if ($this->_oRecommList === null) {
219  $this->_oRecommList = false;
220  if ($oProduct = $this->getProduct()) {
221  $oRecommList = oxNew('oxrecommlist');
222  $this->_oRecommList = $oRecommList->getRecommListsByIds(array($oProduct->getId()));
223  }
224  }
225 
226  return $this->_oRecommList;
227  }
228 
234  public function setSuggestData($oData)
235  {
236  $this->_aSuggestData = $oData;
237  }
238 
244  public function getSuggestData()
245  {
246  return $this->_aSuggestData;
247  }
248 
256  public function getLink($iLang = null)
257  {
258  $sLink = parent::getLink($iLang);
259 
260  // active category
261  if ($sVal = oxRegistry::getConfig()->getRequestParameter('cnid')) {
262  $sLink .= ((strpos($sLink, '?') === false) ? '?' : '&amp;') . "cnid={$sVal}";
263  }
264 
265  // active article
266  if ($sVal = oxRegistry::getConfig()->getRequestParameter('anid')) {
267  $sLink .= ((strpos($sLink, '?') === false) ? '?' : '&amp;') . "anid={$sVal}";
268  }
269 
270  return $sLink;
271  }
272 
280  public function getCaptcha()
281  {
282  if ($this->_oCaptcha === null) {
283  $this->_oCaptcha = oxNew('oxCaptcha');
284  }
285 
286  return $this->_oCaptcha;
287  }
288 
294  public function getBreadCrumb()
295  {
296  $aPaths = array();
297  $aPath = array();
298  $iBaseLanguage = oxRegistry::getLang()->getBaseLanguage();
299  $aPath['title'] = oxRegistry::getLang()->translateString('RECOMMEND_PRODUCT', $iBaseLanguage, false);
300  $aPath['link'] = $this->getLink();
301 
302  $aPaths[] = $aPath;
303 
304  return $aPaths;
305  }
306 }