34 if (!isset($iLanguage)) {
37 $this->_iLanguage = $iLanguage;
52 public function getSearchArticles($sSearchParamForQuery =
false, $sInitialSearchCat =
false, $sInitialSearchVendor =
false, $sInitialSearchManufacturer =
false, $sSortBy =
false)
56 $this->iActPage = ($this->iActPage < 0) ? 0 : $this->iActPage;
60 $iNrofCatArticles = $this->
getConfig()->getConfigParam(
'iNrofCatArticles');
61 $iNrofCatArticles = $iNrofCatArticles ? $iNrofCatArticles : 10;
63 $oArtList =
oxNew(
'oxarticlelist');
64 $oArtList->setSqlLimit($iNrofCatArticles * $this->iActPage, $iNrofCatArticles);
66 $sSelect = $this->
_getSearchSelect($sSearchParamForQuery, $sInitialSearchCat, $sInitialSearchVendor, $sInitialSearchManufacturer, $sSortBy);
68 $oArtList->selectString($sSelect);
84 public function getSearchArticleCount($sSearchParamForQuery =
false, $sInitialSearchCat =
false, $sInitialSearchVendor =
false, $sInitialSearchManufacturer =
false)
87 $sSelect = $this->
_getSearchSelect($sSearchParamForQuery, $sInitialSearchCat, $sInitialSearchVendor, $sInitialSearchManufacturer,
false);
90 $sPartial = substr($sSelect, strpos($sSelect,
' from '));
91 $sSelect =
"select count( " . getViewName(
'oxarticles', $this->_iLanguage) .
".oxid ) $sPartial ";
110 protected function _getSearchSelect($sSearchParamForQuery =
false, $sInitialSearchCat =
false, $sInitialSearchVendor =
false, $sInitialSearchManufacturer =
false, $sSortBy =
false)
115 if ($sInitialSearchCat) {
117 $oCategory =
oxNew(
'oxcategory');
118 $sCatTable = $oCategory->getViewName();
120 $sQ =
"select 1 from $sCatTable where $sCatTable.oxid = " . $oDb->quote($sInitialSearchCat) .
" ";
121 $sQ .=
"and " . $oCategory->getSqlActiveSnippet();
122 if (!$oDb->getOne($sQ)) {
128 if ($sInitialSearchVendor) {
130 $oVendor =
oxNew(
'oxvendor');
131 $sVndTable = $oVendor->getViewName();
133 $sQ =
"select 1 from $sVndTable where $sVndTable.oxid = " . $oDb->quote($sInitialSearchVendor) .
" ";
134 $sQ .=
"and " . $oVendor->getSqlActiveSnippet();
135 if (!$oDb->getOne($sQ)) {
141 if ($sInitialSearchManufacturer) {
143 $oManufacturer =
oxNew(
'oxmanufacturer');
144 $sManTable = $oManufacturer->getViewName();
146 $sQ =
"select 1 from $sManTable where $sManTable.oxid = " . $oDb->quote($sInitialSearchManufacturer) .
" ";
147 $sQ .=
"and " . $oManufacturer->getSqlActiveSnippet();
148 if (!$oDb->getOne($sQ)) {
155 if ($sSearchParamForQuery) {
156 $sWhere = $this->
_getWhere($sSearchParamForQuery);
157 } elseif (!$sInitialSearchCat && !$sInitialSearchVendor && !$sInitialSearchManufacturer) {
162 $oArticle =
oxNew(
'oxarticle');
163 $sArticleTable = $oArticle->getViewName();
164 $sO2CView = getViewName(
'oxobject2category');
166 $sSelectFields = $oArticle->getSelectFields();
170 if (is_array($aSearchCols = $this->
getConfig()->getConfigParam(
'aSearchCols'))) {
172 if (in_array(
'oxlongdesc', $aSearchCols) || in_array(
'oxtags', $aSearchCols)) {
173 $sDescView = getViewName(
'oxartextends', $this->_iLanguage);
174 $sDescJoin =
" LEFT JOIN {$sDescView} ON {$sArticleTable}.oxid={$sDescView}.oxid ";
180 $sSelect =
"select {$sSelectFields}, {$sArticleTable}.oxtimestamp from {$sArticleTable} {$sDescJoin} where ";
183 if ($sInitialSearchCat) {
184 $sCatView = getViewName(
'oxcategories', $this->_iLanguage);
185 $sInitialSearchCatQuoted = $oDb->quote($sInitialSearchCat);
186 $sSelectCat =
"select oxid from {$sCatView} where oxid = $sInitialSearchCatQuoted and (oxpricefrom != '0' or oxpriceto != 0)";
187 if ($oDb->getOne($sSelectCat)) {
188 $sSelect =
"select {$sSelectFields}, {$sArticleTable}.oxtimestamp from {$sArticleTable} $sDescJoin " .
189 "where {$sArticleTable}.oxid in ( select {$sArticleTable}.oxid as id from {$sArticleTable}, {$sO2CView} as oxobject2category, {$sCatView} as oxcategories " .
190 "where (oxobject2category.oxcatnid=$sInitialSearchCatQuoted and oxobject2category.oxobjectid={$sArticleTable}.oxid) or (oxcategories.oxid=$sInitialSearchCatQuoted and {$sArticleTable}.oxprice >= oxcategories.oxpricefrom and
191 {$sArticleTable}.oxprice <= oxcategories.oxpriceto )) and ";
193 $sSelect =
"select {$sSelectFields} from {$sO2CView} as
194 oxobject2category, {$sArticleTable} {$sDescJoin} where oxobject2category.oxcatnid=$sInitialSearchCatQuoted and
195 oxobject2category.oxobjectid={$sArticleTable}.oxid and ";
199 $sSelect .= $oArticle->getSqlActiveSnippet();
200 $sSelect .=
" and {$sArticleTable}.oxparentid = '' and {$sArticleTable}.oxissearch = 1 ";
202 if ($sInitialSearchVendor) {
203 $sSelect .=
" and {$sArticleTable}.oxvendorid = " . $oDb->quote($sInitialSearchVendor) .
" ";
206 if ($sInitialSearchManufacturer) {
207 $sSelect .=
" and {$sArticleTable}.oxmanufacturerid = " . $oDb->quote($sInitialSearchManufacturer) .
" ";
213 $sSelect .=
" order by {$sSortBy} ";
231 $sArticleTable = getViewName(
'oxarticles', $this->_iLanguage);
233 $aSearchCols =
$myConfig->getConfigParam(
'aSearchCols');
234 if (!(is_array($aSearchCols) && count($aSearchCols))) {
238 $oTempArticle =
oxNew(
'oxarticle');
239 $sSearchSep =
$myConfig->getConfigParam(
'blSearchUseAND') ?
'and ' :
'or ';
240 $aSearch = explode(
' ', $sSearchString);
241 $sSearch =
' and ( ';
245 foreach ($aSearch as $sSearchString) {
247 if (!strlen($sSearchString)) {
252 $sSearch .= $sSearchSep;
258 foreach ($aSearchCols as $sField) {
266 if ($sField ==
'oxlongdesc' || $sField ==
'oxtags') {
267 $sSearchField = getViewName(
'oxartextends', $this->_iLanguage) .
".{$sField}";
269 $sSearchField =
"{$sArticleTable}.{$sField}";
273 $sSearch .=
" {$sSearchField} like " . $oDb->quote(
"%$sSearchString%");
276 if (($sUml = $myUtilsString->prepareStrForSearch($sSearchString))) {
277 $sSearch .=
" or {$sSearchField} like " . $oDb->quote(
"%$sUml%");