00001 <?php
00002
00008 class Suggest extends oxUBase
00009 {
00014 protected $_sThisTemplate = 'suggest.tpl';
00015
00020 protected $_aReqFields = array( 'rec_name', 'rec_email', 'send_name', 'send_email', 'send_message', 'send_subject' );
00021
00026 protected $_oCrossSelling = null;
00027
00032 protected $_oSimilarProducts = null;
00033
00038 protected $_oRecommList = null;
00039
00044 protected $_aSuggestData = null;
00045
00058 public function render()
00059 {
00060 parent::render();
00061
00062 $this->_aViewData['product'] = $this->getProduct();
00063 $this->_aViewData['crossselllist'] = $this->getCrossSelling();
00064 $this->_aViewData['similarlist'] = $this->getSimilarProducts();
00065 $this->_aViewData['similarrecommlist'] = $this->getRecommList();
00066
00067 $this->_aViewData['editval'] = $this->getSuggestData();
00068
00069 return $this->_sThisTemplate;
00070 }
00071
00081 public function send()
00082 {
00083 $aParams = oxConfig::getParameter( 'editval' );
00084 if ( !is_array( $aParams ) ) {
00085 return;
00086 }
00087
00088
00089 $oParams = new Oxstdclass();
00090 reset( $aParams );
00091 while ( list( $sName, $sValue ) = each( $aParams ) ) {
00092 $oParams->$sName = $sValue;
00093 }
00094 $this->_aSuggestData = $oParams;
00095
00096 $oUtilsView = oxUtilsView::getInstance();
00097
00098 foreach ( $this->_aReqFields as $sFieldName ) {
00099 if ( !isset( $aParams[$sFieldName] ) || !$aParams[$sFieldName] ) {
00100 $oUtilsView->addErrorToDisplay('SUGGEST_COMLETECORRECTLYFIELDS');
00101 return;
00102 }
00103 }
00104
00105 $sReturn = "";
00106
00107 $sSearchParamForLink = rawurlencode( oxConfig::getParameter( 'searchparam', true ) );
00108 if ( $sSearchParamForLink ) {
00109 $sReturn .= "&searchparam=$sSearchParamForLink";
00110 }
00111
00112 $sSearchCatId = oxConfig::getParameter( 'searchcnid' );
00113 if ( $sSearchCatId ) {
00114 $sReturn .= "&searchcnid=$sSearchCatId";
00115 }
00116
00117 $sSearchVendor = oxConfig::getParameter( 'searchvendor' );
00118 if ( $sSearchVendor ) {
00119 $sReturn .= "&searchvendor=$sSearchVendor";
00120 }
00121
00122 if ( ( $sSearchManufacturer = oxConfig::getParameter( 'searchmanufacturer' ) ) ) {
00123 $sReturn .= "&searchmanufacturer=$sSearchManufacturer";
00124 }
00125
00126 $sListType = oxConfig::getParameter( 'listtype' );
00127 if ( $sListType ) {
00128 $sReturn .= "&listtype=$sListType";
00129 }
00130
00131
00132 $oEmail = oxNew( 'oxemail' );
00133 $oProduct = $this->getProduct();
00134 if ( $oProduct && $oEmail->sendSuggestMail( $oParams, $oProduct ) ) {
00135 return 'details?anid='.$oProduct->getId().$sReturn;
00136 } else {
00137 oxUtilsView::getInstance()->addErrorToDisplay('SUGGEST_INVALIDMAIL');
00138 }
00139 }
00140
00146 public function getProduct()
00147 {
00148 if ( $this->_oProduct === null ) {
00149 $this->_oProduct = false;
00150
00151 if ( $sAnid = oxConfig::getParameter( 'anid' ) ) {
00152 $this->_oProduct = oxNewArticle( $sAnid );
00153 }
00154 }
00155 return $this->_oProduct;
00156 }
00157
00163 public function getCrossSelling()
00164 {
00165 if ( $this->_oCrossSelling === null ) {
00166 $this->_oCrossSelling = false;
00167 if ( $oProduct = $this->getProduct() ) {
00168 $this->_oCrossSelling = $oProduct->getCrossSelling();
00169 }
00170 }
00171 return $this->_oCrossSelling;
00172 }
00173
00179 public function getSimilarProducts()
00180 {
00181 if ( $this->_oSimilarProducts === null ) {
00182 $this->_oSimilarProducts = false;
00183 if ( $oProduct = $this->getProduct() ) {
00184 $this->_oSimilarProducts = $oProduct->getSimilarProducts();
00185 }
00186 }
00187 return $this->_oSimilarProducts;
00188 }
00189
00195 public function getRecommList()
00196 {
00197 if ( $this->_oRecommList === null ) {
00198 $this->_oRecommList = false;
00199 if ( $oProduct = $this->getProduct() ) {
00200 $oRecommList = oxNew('oxrecommlist');
00201 $this->_oRecommList = $oRecommList->getRecommListsByIds( array( $oProduct->getId() ) );
00202 }
00203 }
00204 return $this->_oRecommList;
00205 }
00206
00212 public function getSuggestData()
00213 {
00214 return $this->_aSuggestData;
00215 }
00216
00217 }