OXID eShop CE  4.8.12
 All Classes Files Functions Variables Pages
suggest.php
Go to the documentation of this file.
1 <?php
2 
8 class Suggest extends oxUBase
9 {
14  protected $_sThisTemplate = 'page/info/suggest.tpl';
15 
20  protected $_aReqFields = array( 'rec_name', 'rec_email', 'send_name', 'send_email', 'send_message', 'send_subject' );
21 
26  protected $_oCrossSelling = null;
27 
32  protected $_oSimilarProducts = null;
33 
38  protected $_oRecommList = null;
39 
44  protected $_aSuggestData = null;
45 
50  protected $_oCaptcha = null;
51 
61  public function send()
62  {
63  $aParams = oxConfig::getParameter( 'editval', true );
64  if ( !is_array( $aParams ) ) {
65  return;
66  }
67 
68  // storing used written values
69  $oParams = (object) $aParams;
70  $this->setSuggestData( (object) oxConfig::getParameter( 'editval' ) );
71 
72  // spam spider prevension
73  $sMac = oxConfig::getParameter( 'c_mac' );
74  $sMacHash = oxConfig::getParameter( 'c_mach' );
75  $oCaptcha = $this->getCaptcha();
76  $oUtilsView = oxRegistry::get("oxUtilsView");
77 
78  if ( !$oCaptcha->pass( $sMac, $sMacHash ) ) {
79  // even if there is no exception, use this as a default display method
80  $oUtilsView->addErrorToDisplay( 'MESSAGE_WRONG_VERIFICATION_CODE' );
81  return false;
82  }
83 
84  // filled not all fields ?
85  foreach ( $this->_aReqFields as $sFieldName ) {
86  if ( !isset( $aParams[$sFieldName] ) || !$aParams[$sFieldName] ) {
87  $oUtilsView->addErrorToDisplay( 'SUGGEST_COMLETECORRECTLYFIELDS' );
88  return;
89  }
90  }
91 
92  $oUtils = oxRegistry::getUtils();
93  if ( !$oUtils->isValidEmail( $aParams["rec_email"] ) || !$oUtils->isValidEmail( $aParams["send_email"] ) ) {
94  $oUtilsView->addErrorToDisplay( 'SUGGEST_INVALIDMAIL' );
95  return;
96  }
97 
98  $sReturn = "";
99  // #1834M - specialchar search
100  $sSearchParamForLink = rawurlencode( oxConfig::getParameter( 'searchparam', true ) );
101  if ( $sSearchParamForLink ) {
102  $sReturn .= "&searchparam=$sSearchParamForLink";
103  }
104 
105  $sSearchCatId = oxConfig::getParameter( 'searchcnid' );
106  if ( $sSearchCatId ) {
107  $sReturn .= "&searchcnid=$sSearchCatId";
108  }
109 
110  $sSearchVendor = oxConfig::getParameter( 'searchvendor' );
111  if ( $sSearchVendor ) {
112  $sReturn .= "&searchvendor=$sSearchVendor";
113  }
114 
115  if ( ( $sSearchManufacturer = oxConfig::getParameter( 'searchmanufacturer' ) ) ) {
116  $sReturn .= "&searchmanufacturer=$sSearchManufacturer";
117  }
118 
119  $sListType = oxConfig::getParameter( 'listtype' );
120  if ( $sListType ) {
121  $sReturn .= "&listtype=$sListType";
122  }
123 
124  // sending suggest email
125  $oEmail = oxNew( 'oxemail' );
126  $oProduct = $this->getProduct();
127  if ( $oProduct && $oEmail->sendSuggestMail( $oParams, $oProduct ) ) {
128  return 'details?anid='.$oProduct->getId().$sReturn;
129  } else {
130  $oUtilsView->addErrorToDisplay('SUGGEST_INVALIDMAIL');
131  }
132  }
133 
139  public function getProduct()
140  {
141  if ( $this->_oProduct === null ) {
142  $this->_oProduct = false;
143 
144  if ( $sProductId = $this->getConfig()->getRequestParameter( 'anid' ) ) {
145  $oProduct = oxNew( 'oxArticle' );
146  $oProduct->load( $sProductId );
147  $this->_oProduct = $oProduct;
148  }
149  }
150  return $this->_oProduct;
151  }
152 
158  public function getCrossSelling()
159  {
160  if ( $this->_oCrossSelling === null ) {
161  $this->_oCrossSelling = false;
162  if ( $oProduct = $this->getProduct() ) {
163  $this->_oCrossSelling = $oProduct->getCrossSelling();
164  }
165  }
166  return $this->_oCrossSelling;
167  }
168 
174  public function getSimilarProducts()
175  {
176  if ( $this->_oSimilarProducts === null ) {
177  $this->_oSimilarProducts = false;
178  if ( $oProduct = $this->getProduct() ) {
179  $this->_oSimilarProducts = $oProduct->getSimilarProducts();
180  }
181  }
183  }
184 
190  public function getRecommList()
191  {
192  if (!$this->getViewConfig()->getShowListmania()) {
193  return false;
194  }
195 
196  if ( $this->_oRecommList === null ) {
197  $this->_oRecommList = false;
198  if ( $oProduct = $this->getProduct() ) {
199  $oRecommList = oxNew('oxrecommlist');
200  $this->_oRecommList = $oRecommList->getRecommListsByIds( array( $oProduct->getId() ) );
201  }
202  }
203  return $this->_oRecommList;
204  }
205 
213  public function setSuggestData( $oData )
214  {
215  $this->_aSuggestData = $oData;
216  }
217 
223  public function getSuggestData()
224  {
225  return $this->_aSuggestData;
226  }
227 
235  public function getLink( $iLang = null )
236  {
237  $sLink = parent::getLink( $iLang );
238 
239  // active category
240  if ( $sVal = oxConfig::getParameter( 'cnid' ) ) {
241  $sLink .= ( ( strpos( $sLink, '?' ) === false ) ? '?' : '&amp;' ) . "cnid={$sVal}";
242  }
243 
244  // active article
245  if ( $sVal= oxConfig::getParameter( 'anid' ) ) {
246  $sLink .= ( ( strpos( $sLink, '?' ) === false ) ? '?' : '&amp;' ) . "anid={$sVal}";
247  }
248 
249  return $sLink;
250  }
251 
257  public function getCaptcha()
258  {
259  if ( $this->_oCaptcha === null ) {
260  $this->_oCaptcha = oxNew('oxCaptcha');
261  }
262  return $this->_oCaptcha;
263  }
264 
270  public function getBreadCrumb()
271  {
272  $aPaths = array();
273  $aPath = array();
274  $aPath['title'] = oxRegistry::getLang()->translateString( 'RECOMMEND_PRODUCT', oxRegistry::getLang()->getBaseLanguage(), false );
275  $aPath['link'] = $this->getLink();
276 
277  $aPaths[] = $aPath;
278 
279  return $aPaths;
280  }
281 
282 }