00001 <?php
00002
00007 class oxArticleList extends oxList
00008 {
00012 protected $_sCustomSorting;
00013
00019 protected $_sObjectsInListName = 'oxarticle';
00020
00026 protected $_blLoadSelectLists = false;
00027
00033 protected $_blLoadPrice = true;
00034
00042 public function setCustomSorting( $sSorting)
00043 {
00044
00045 $aSorting = explode(" ", $sSorting);
00046 $aSorting[0] = $this->getBaseObject()->getSqlFieldName($aSorting[0]);
00047 $this->_sCustomSorting = implode( " ", $aSorting );
00048 }
00049
00055 public function enableSelectLists()
00056 {
00057 $this->_blLoadSelectLists = true;
00058 }
00059
00068 public function selectString( $sSelect )
00069 {
00070 if ( !$this->isAdmin() ) {
00071 $this->_aAssignCallbackPrepend = ( !$this->_blLoadPrice )?array( oxNew("oxarticle"), 'disablePriceLoad'):null;
00072 }
00073
00074 startProfile("loadinglists");
00075 $oRes = parent::selectString( $sSelect );
00076 stopProfile("loadinglists");
00077
00078 return $oRes;
00079 }
00080
00089 public function loadHistoryArticles($sArtId)
00090 {
00091 $mySession = $this->getSession();
00092 $aHistoryArticles = $mySession->getVar('aHistoryArticles');
00093 $aHistoryArticles[] = $sArtId;
00094
00095
00096 $aHistoryArticles = array_unique( $aHistoryArticles);
00097
00098 if (count($aHistoryArticles) > 5) {
00099 array_shift($aHistoryArticles);
00100 }
00101
00102
00103 $mySession->setVar('aHistoryArticles', $aHistoryArticles);
00104
00105
00106
00107 if (($iCurrentArt = array_search($sArtId, $aHistoryArticles)) !== false) {
00108 unset ($aHistoryArticles[$iCurrentArt]);
00109 }
00110
00111 $this->loadIds(array_values($aHistoryArticles));
00112 }
00113
00121 public function loadNewestArticles( $iLimit = null )
00122 {
00123
00124 $myConfig = $this->getConfig();
00125
00126 if ( !$myConfig->getConfigParam( 'bl_perfLoadPriceForAddList' ) ) {
00127 $this->_blLoadPrice = false;
00128 }
00129
00130 $this->_aArray = array();
00131 switch( $myConfig->getConfigParam( 'iNewestArticlesMode' ) ) {
00132 case 0:
00133
00134 break;
00135 case 1:
00136
00137 $this->loadAktionArticles( 'oxnewest' );
00138 break;
00139 case 2:
00140 $sArticleTable = getViewName('oxarticles');
00141 if ( $myConfig->getConfigParam( 'blNewArtByInsert' ) ) {
00142 $sType = 'oxinsert';
00143 } else {
00144 $sType = 'oxtimestamp';
00145 }
00146 $sSelect = "select * from $sArticleTable ";
00147 $sSelect .= "where oxparentid = '' and ".$this->getBaseObject()->getSqlActiveSnippet()." and oxissearch = 1 order by $sType desc ";
00148 if (!($iLimit = (int) $iLimit)) {
00149 $iLimit = $myConfig->getConfigParam( 'iNrofNewcomerArticles' );
00150 }
00151 $sSelect .= "limit " . $iLimit;
00152
00153 $this->selectString($sSelect);
00154 break;
00155 }
00156
00157 }
00158
00164 public function loadTop5Articles()
00165 {
00166
00167 $myConfig = $this->getConfig();
00168
00169 if ( !$myConfig->getConfigParam( 'bl_perfLoadPriceForAddList' ) ) {
00170 $this->_blLoadPrice = false;
00171 }
00172
00173 switch( $myConfig->getConfigParam( 'iTop5Mode' ) ) {
00174 case 0:
00175
00176 break;
00177 case 1:
00178
00179 $this->loadAktionArticles( 'oxtop5');
00180 break;
00181 case 2:
00182 $sArticleTable = getViewName('oxarticles');
00183
00184 $sSelect = "select * from $sArticleTable ";
00185 $sSelect .= "where ".$this->getBaseObject()->getSqlActiveSnippet()." and $sArticleTable.oxissearch = 1 ";
00186 $sSelect .= "and $sArticleTable.oxparentid = '' and $sArticleTable.oxsoldamount>0 ";
00187 $sSelect .= "order by $sArticleTable.oxsoldamount desc limit 5";
00188
00189 $this->selectString($sSelect);
00190 break;
00191 }
00192 }
00193
00201 public function loadAktionArticles( $sActionID )
00202 {
00203
00204 if ( !trim( $sActionID) ) {
00205 return;
00206 }
00207
00208 $sShopID = $this->getConfig()->getShopId();
00209 $sActionID = strtolower( $sActionID);
00210
00211
00212 $oBaseObject = $this->getBaseObject();
00213 $sArticleTable = $oBaseObject->getViewName();
00214 $sArticleFields = $oBaseObject->getSelectFields();
00215
00216 $oBase = oxNew("oxactions");
00217 $sActiveSql = $oBase->getSqlActiveSnippet();
00218
00219 $sSelect = "select $sArticleFields from oxactions2article
00220 left join $sArticleTable on $sArticleTable.oxid = oxactions2article.oxartid
00221 left join oxactions on oxactions.oxid = oxactions2article.oxactionid
00222 where oxactions2article.oxshopid = '$sShopID' and oxactions2article.oxactionid = '$sActionID' and $sActiveSql
00223 and $sArticleTable.oxid is not null and " .$oBaseObject->getSqlActiveSnippet(). "
00224 order by oxactions2article.oxsort";
00225
00226 $this->selectString( $sSelect );
00227 }
00228
00236 public function loadArticleCrossSell( $sArticleId )
00237 {
00238 $myConfig = $this->getConfig();
00239
00240
00241 if ( !$myConfig->getConfigParam( 'bl_perfLoadCrossselling' ) ) {
00242 return null;
00243 }
00244
00245 $oBaseObject = $this->getBaseObject();
00246 $sArticleTable = $oBaseObject->getViewName();
00247
00248 $sSelect = "select $sArticleTable.* from oxobject2article left join $sArticleTable on oxobject2article.oxobjectid=$sArticleTable.oxid ";
00249 $sSelect .= "where oxobject2article.oxarticlenid = '$sArticleId' ";
00250 $sSelect .= " and $sArticleTable.oxid is not null and " .$oBaseObject->getSqlActiveSnippet(). " order by rand()";
00251
00252
00253 if ( $myConfig->getConfigParam( 'blBidirectCross' ) ) {
00254 $sSelect = "select distinct $sArticleTable.* from oxobject2article left join $sArticleTable on (oxobject2article.oxobjectid=$sArticleTable.oxid or oxobject2article.oxarticlenid=$sArticleTable.oxid) ";
00255 $sSelect .= "where (oxobject2article.oxarticlenid = '$sArticleId' or oxobject2article.oxobjectid = '$sArticleId' )";
00256 $sSelect .= " and $sArticleTable.oxid is not null and " .$oBaseObject->getSqlActiveSnippet(). " having $sArticleTable.oxid!='$sArticleId' order by rand()";
00257 }
00258
00259 $this->setSqlLimit( 0, $myConfig->getConfigParam( 'iNrofCrossellArticles' ));
00260 $this->selectString( $sSelect );
00261 }
00262
00270 public function loadArticleAccessoires( $sArticleId )
00271 {
00272 $myConfig = $this->getConfig();
00273
00274
00275 if ( !$myConfig->getConfigParam( 'bl_perfLoadAccessoires' ) ) {
00276 return;
00277 }
00278
00279 $oBaseObject = $this->getBaseObject();
00280 $sArticleTable = $oBaseObject->getViewName();
00281
00282 $sSelect = "select $sArticleTable.* from oxaccessoire2article left join $sArticleTable on oxaccessoire2article.oxobjectid=$sArticleTable.oxid ";
00283 $sSelect .= "where oxaccessoire2article.oxarticlenid = '$sArticleId' ";
00284 $sSelect .= " and $sArticleTable.oxid is not null and " .$oBaseObject->getSqlActiveSnippet();
00285
00286 $sSelect .= " order by oxaccessoire2article.oxsort";
00287
00288 $this->selectString( $sSelect );
00289 }
00290
00299 public function loadCategoryIds( $sCatId, $aSessionFilter )
00300 {
00301 $sArticleTable = $this->getBaseObject()->getViewName();
00302 $sSelect = $this->_getCategorySelect( $sArticleTable.'.oxid as oxid', $sCatId, $aSessionFilter );
00303
00304 $this->_createIdListFromSql( $sSelect );
00305 }
00306
00316 public function loadCategoryArticles( $sCatId, $aSessionFilter, $iLimit = null )
00317 {
00318 $sArticleFields = $this->getBaseObject()->getSelectFields();
00319
00320 $sSelect = $this->_getCategorySelect( $sArticleFields, $sCatId, $aSessionFilter );
00321
00322
00323
00324 $iArticleCount = null;
00325 if ( $aSessionFilter) {
00326 $oRet = oxDb::getDb()->Execute( $sSelect );
00327 $iArticleCount = $oRet->recordCount();
00328 }
00329
00330 if ($iLimit = (int) $iLimit) {
00331 $sSelect .= " LIMIT $iLimit";
00332 }
00333
00334 $this->selectString( $sSelect );
00335
00336 if ( $iArticleCount !== null ) {
00337 return $iArticleCount;
00338 }
00339
00340 $iTotalCount = oxUtilsCount::getInstance()->getCatArticleCount($sCatId);
00341
00342
00343 return $iTotalCount;
00344 }
00345
00354 public function loadRecommArticles( $sRecommId, $sArticlesFilter = null )
00355 {
00356 $sSelect = $this->_getArticleSelect( $sRecommId, $sArticlesFilter);
00357 $this->selectString( $sSelect );
00358 }
00359
00368 public function loadRecommArticleIds( $sRecommId, $sArticlesFilter )
00369 {
00370 $sSelect = $this->_getArticleSelect( $sRecommId, $sArticlesFilter );
00371
00372 $sArtView = getViewName( 'oxarticles' );
00373 $sPartial = substr( $sSelect, strpos( $sSelect, ' from ' ) );
00374 $sSelect = "select distinct $sArtView.oxid $sPartial ";
00375
00376 $this->_createIdListFromSql( $sSelect );
00377 }
00378
00387 protected function _getArticleSelect( $sRecommId, $sArticlesFilter = null )
00388 {
00389 $sArtView = getViewName( 'oxarticles' );
00390 $sSelect = "select distinct $sArtView.*, oxobject2list.oxdesc from oxobject2list ";
00391 $sSelect .= "left join $sArtView on oxobject2list.oxobjectid = $sArtView.oxid ";
00392 $sSelect .= "where (oxobject2list.oxlistid = '".$sRecommId."') ".$sArticlesFilter;
00393
00394 return $sSelect;
00395 }
00396
00407 public function loadSearchIds( $sSearchStr = '', $sSearchCat = '', $sSearchVendor = '', $sSearchManufacturer = '' )
00408 {
00409 $oDb = oxDb::getDb();
00410 $sSearchCat = $sSearchCat?$oDb->quote( $sSearchCat ):null;
00411 $sSearchVendor = $sSearchVendor?$oDb->quote( $sSearchVendor ):null;
00412 $sSearchManufacturer = $sSearchManufacturer?$oDb->quote( $sSearchManufacturer ):null;
00413
00414 $sWhere = null;
00415
00416 if ( $sSearchStr ) {
00417 $sWhere = $this->_getSearchSelect( $sSearchStr );
00418 }
00419
00420 $sArticleTable = getViewName('oxarticles');
00421
00422
00423 $sDescTable = '';
00424 $sDescJoin = '';
00425 if ( is_array( $aSearchCols = $this->getConfig()->getConfigParam( 'aSearchCols' ) ) ) {
00426 if ( in_array( 'oxlongdesc', $aSearchCols ) || in_array( 'oxtags', $aSearchCols ) ) {
00427 $sDescView = getViewName( 'oxartextends' );
00428 $sDescJoin = " LEFT JOIN $sDescView ON {$sDescView}.oxid={$sArticleTable}.oxid ";
00429 }
00430 }
00431
00432
00433 $sSelect = "select $sArticleTable.oxid from $sArticleTable $sDescJoin where ";
00434
00435
00436 if ( $sSearchCat ) {
00437 $sO2CView = getViewName('oxobject2category');
00438 $sSelect = "select $sArticleTable.oxid from $sO2CView as oxobject2category, $sArticleTable $sDescJoin ";
00439 $sSelect .= "where oxobject2category.oxcatnid=$sSearchCat and oxobject2category.oxobjectid=$sArticleTable.oxid and ";
00440 }
00441 $sSelect .= $this->getBaseObject()->getSqlActiveSnippet();
00442 $sSelect .= " and $sArticleTable.oxparentid = '' and $sArticleTable.oxissearch = 1 ";
00443
00444
00445 if ( $sSearchVendor ) {
00446 $sSelect .= " and $sArticleTable.oxvendorid = $sSearchVendor ";
00447 }
00448
00449 if ( $sSearchManufacturer ) {
00450 $sSelect .= " and $sArticleTable.oxmanufacturerid = $sSearchManufacturer ";
00451 }
00452 $sSelect .= $sWhere;
00453
00454 if ($this->_sCustomSorting) {
00455 $sSelect .= " order by {$this->_sCustomSorting} ";
00456 }
00457
00458 $this->_createIdListFromSql($sSelect);
00459 }
00460
00469 public function loadPriceIds( $dPriceFrom, $dPriceTo )
00470 {
00471
00472 $sSelect = $this->_getPriceSelect( $dPriceFrom, $dPriceTo );
00473 $this->_createIdListFromSql($sSelect);
00474 }
00475
00486 public function loadPriceArticles( $dPriceFrom, $dPriceTo, $oCategory = null)
00487 {
00488 $sArticleTable = getViewName('oxarticles');
00489
00490 $sSelect = $this->_getPriceSelect( $dPriceFrom, $dPriceTo );
00491
00492 $this->selectString( $sSelect);
00493
00494
00495 if ( !$oCategory ) {
00496 return $this->count();
00497 }
00498
00499
00500 $iNumOfArticles = $oCategory->getNrOfArticles();
00501 if ( !isset($iNumOfArticles) || $iNumOfArticles == -1) {
00502 return oxUtilsCount::getInstance()->getPriceCatArticleCount($oCategory->getId(), $dPriceFrom, $dPriceTo );
00503 } else {
00504 return $oCategory->getNrOfArticles();
00505 }
00506 }
00507
00515 public function loadVendorIDs( $sVendorId)
00516 {
00517 $sSelect = $this->_getVendorSelect($sVendorId);
00518 $this->_createIdListFromSql($sSelect);
00519 }
00520
00528 public function loadManufacturerIDs( $sManufacturerId)
00529 {
00530 $sSelect = $this->_getManufacturerSelect($sManufacturerId);
00531 $this->_createIdListFromSql($sSelect);
00532 }
00533
00543 public function loadVendorArticles( $sVendorId, $oVendor = null )
00544 {
00545 $sSelect = $this->_getVendorSelect($sVendorId);
00546 $this->selectString( $sSelect);
00547
00548 return oxUtilsCount::getInstance()->getVendorArticleCount( $sVendorId );
00549 }
00550
00560 public function loadManufacturerArticles( $sManufacturerId, $oManufacturer = null )
00561 {
00562 $sSelect = $this->_getManufacturerSelect($sManufacturerId);
00563 $this->selectString( $sSelect);
00564
00565 return oxUtilsCount::getInstance()->getManufacturerArticleCount( $sManufacturerId );
00566 }
00567
00576 public function loadTagArticles( $sTag, $iLang )
00577 {
00578 $oListObject = $this->getBaseObject();
00579 $sArticleTable = $oListObject->getViewName();
00580 $sArticleFields = $oListObject->getSelectFields();
00581
00582 $sLangExt = oxLang::getInstance()->getLanguageTag( $iLang );
00583
00584 $oTagHandler = oxNew( 'oxtagcloud' );
00585 $sTag = $oTagHandler->prepareTags( $sTag );
00586
00587 $sQ = "select {$sArticleFields} from oxartextends inner join {$sArticleTable} on
00588 {$sArticleTable}.oxid = oxartextends.oxid where {$sArticleTable}.oxissearch = 1
00589 and match ( oxartextends.oxtags{$sLangExt} )
00590 against( ".oxDb::getDb()->quote( $sTag )." )";
00591
00592
00593 if ( ( $sActiveSnippet = $oListObject->getSqlActiveSnippet() ) ) {
00594 $sQ .= " and {$sActiveSnippet}";
00595 }
00596
00597 if ( $this->_sCustomSorting ) {
00598 $sSort = $this->_sCustomSorting;
00599 if (strpos($sSort, '.') === false) {
00600 $sSort = $sArticleTable.'.'.$sSort;
00601 }
00602 $sQ .= " order by $sSort ";
00603 }
00604
00605 $this->selectString( $sQ );
00606
00607
00608 return oxUtilsCount::getInstance()->getTagArticleCount( $sTag, $iLang );
00609 }
00610
00619 public function getTagArticleIds( $sTag, $iLang )
00620 {
00621 $oListObject = $this->getBaseObject();
00622 $sArticleTable = $oListObject->getViewName();
00623 $sLangExt = oxLang::getInstance()->getLanguageTag( $iLang );
00624
00625 $oTagHandler = oxNew( 'oxtagcloud' );
00626 $sTag = $oTagHandler->prepareTags( $sTag );
00627
00628 $sQ = "select oxartextends.oxid from oxartextends inner join {$sArticleTable} on
00629 {$sArticleTable}.oxid = oxartextends.oxid where {$sArticleTable}.oxissearch = 1 and
00630 match ( oxartextends.oxtags{$sLangExt} )
00631 against( ".oxDb::getDb()->quote( $sTag )." )";
00632
00633
00634 if ( ( $sActiveSnippet = $oListObject->getSqlActiveSnippet() ) ) {
00635 $sQ .= " and {$sActiveSnippet}";
00636 }
00637
00638 if ( $this->_sCustomSorting ) {
00639 $sSort = $this->_sCustomSorting;
00640 if (strpos($sSort, '.') === false) {
00641 $sSort = $sArticleTable.'.'.$sSort;
00642 }
00643 $sQ .= " order by $sSort ";
00644 }
00645
00646 return $this->_createIdListFromSql( $sQ );
00647 }
00648
00656 public function loadIds($aIds)
00657 {
00658 if (!count($aIds)) {
00659 $this->clear();
00660 return;
00661 }
00662
00663 foreach ($aIds as $iKey => $sVal) {
00664 $aIds[$iKey] = mysql_real_escape_string($sVal);
00665 }
00666
00667 $oBaseObject = $this->getBaseObject();
00668 $sArticleTable = $oBaseObject->getViewName();
00669 $sArticleFields = $oBaseObject->getSelectFields();
00670
00671 $sSelect = "select $sArticleFields from $sArticleTable ";
00672 $sSelect .= "where $sArticleTable.oxid in ( '".implode("','", $aIds)."' ) and ";
00673 $sSelect .= $oBaseObject->getSqlActiveSnippet();
00674
00675 $this->selectString($sSelect);
00676 }
00677
00685 public function loadOrderArticles($aOrders)
00686 {
00687 if (!count($aOrders)) {
00688 $this->clear();
00689 return;
00690 }
00691
00692 foreach ($aOrders as $iKey => $oOrder) {
00693 $aOrdersIds[] = $oOrder->getId();
00694 }
00695
00696 $oBaseObject = $this->getBaseObject();
00697 $sArticleTable = $oBaseObject->getViewName();
00698 $sArticleFields = $oBaseObject->getSelectFields();
00699 $sArticleFields = str_replace( "$sArticleTable.oxid", "oxorderarticles.oxartid as oxid", $sArticleFields );
00700
00701 $sSelect = "SELECT $sArticleFields FROM oxorderarticles ";
00702 $sSelect .= "left join $sArticleTable on oxorderarticles.oxartid = $sArticleTable.oxid ";
00703 $sSelect .= "WHERE oxorderarticles.oxorderid IN ( '".implode("','", $aOrdersIds)."' ) ";
00704 $sSelect .= "order by $sArticleTable.oxid ";
00705
00706 $this->selectString( $sSelect );
00707
00708
00709 foreach ( $this as $oArticle ) {
00710 if ( !$oArticle->oxarticles__oxactive->value ) {
00711 $oArticle->setBuyableState( false );
00712 }
00713 }
00714 }
00715
00723 protected function _createIdListFromSql( $sSql)
00724 {
00725 $rs = oxDb::getDb(true)->execute( $sSql);
00726 if ($rs != false && $rs->recordCount() > 0) {
00727 while (!$rs->EOF) {
00728 $rs->fields = array_change_key_case($rs->fields, CASE_LOWER);
00729 $this[$rs->fields['oxid']] = $rs->fields['oxid'];
00730 $rs->moveNext();
00731 }
00732 }
00733 }
00734
00743 protected function _getFilterSql($sCatId, $aFilter)
00744 {
00745 $sO2CView = getViewName( 'oxobject2category' );
00746 $sArticleTable = getViewName( 'oxarticles' );
00747 $sFilter = '';
00748 $iCnt = 0;
00749 $sSuffix = oxLang::getInstance()->getLanguageTag();
00750
00751 foreach ( $aFilter as $sAttrId => $sValue ) {
00752 if ( $sValue ) {
00753 if ( $sFilter ) {
00754 $sFilter .= ' or ';
00755 }
00756 $sValue = mysql_real_escape_string($sValue);
00757 $sFilter .= "( oa.oxattrid = '$sAttrId' and oa.oxvalue$sSuffix = '$sValue' )";
00758 $iCnt++;
00759 }
00760 }
00761 if ( $sFilter ) {
00762 $sFilter = "WHERE $sFilter ";
00763 }
00764
00765 $sFilterSelect = "select oc.oxobjectid as oxobjectid, count(*) as cnt from ";
00766 $sFilterSelect.= "(SELECT * FROM $sO2CView WHERE $sO2CView.oxcatnid = '$sCatId' GROUP BY $sO2CView.oxobjectid, $sO2CView.oxcatnid) as oc ";
00767 $sFilterSelect.= "INNER JOIN oxobject2attribute as oa ON ( oa.oxobjectid = oc.oxobjectid ) ";
00768 $sFilterSelect.= $sFilter;
00769 $sFilterSelect.= "GROUP BY oa.oxobjectid HAVING cnt = $iCnt ";
00770
00771 $aIds = oxDb::getDb( true )->getAll( $sFilterSelect );
00772 $sIds = '';
00773
00774 if ( $aIds ) {
00775 foreach ( $aIds as $aArt ) {
00776 if ( $sIds ) {
00777 $sIds .= ', ';
00778 }
00779 $sIds .= " '{$aArt['oxobjectid']}' ";
00780 }
00781
00782 if ( $sIds ) {
00783 $sFilterSql = " and $sArticleTable.oxid in ( $sIds ) ";
00784 }
00785 }
00786 return $sFilterSql;
00787 }
00788
00798 protected function _getCategorySelect( $sFields, $sCatId, $aSessionFilter )
00799 {
00800 $sArticleTable = getViewName( 'oxarticles' );
00801 $sO2CView = getViewName( 'oxobject2category' );
00802
00803
00804
00805 $sSorting = '';
00806 if ( $this->_sCustomSorting ) {
00807 $sSorting = " {$this->_sCustomSorting} , ";
00808 }
00809
00810
00811
00812 $sFilterSql = '';
00813 if ( $aSessionFilter && isset( $aSessionFilter[$sCatId] ) ) {
00814 $sFilterSql = $this->_getFilterSql($sCatId, $aSessionFilter[$sCatId]);
00815 }
00816
00817 $sSelect = "SELECT $sFields FROM $sO2CView as oc left join $sArticleTable
00818 ON $sArticleTable.oxid = oc.oxobjectid
00819 WHERE ".$this->getBaseObject()->getSqlActiveSnippet()." and $sArticleTable.oxparentid = ''
00820 and oc.oxcatnid = '$sCatId' $sFilterSql GROUP BY oc.oxcatnid, oc.oxobjectid ORDER BY $sSorting oc.oxpos, oc.oxobjectid ";
00821
00822 return $sSelect;
00823 }
00824
00832 protected function _getSearchSelect( $sSearchString )
00833 {
00834
00835 if ( !$sSearchString || !str_replace( ' ', '', $sSearchString ) ) {
00836 return '';
00837 }
00838
00839 $oDb = oxDb::getDb();
00840 $myConfig = $this->getConfig();
00841 $myUtils = oxUtils::getInstance();
00842 $sArticleTable = $this->getBaseObject()->getViewName();
00843
00844 $aSearch = explode( ' ', $sSearchString);
00845
00846 $sSearch = ' and ( ';
00847 $blSep = false;
00848
00849
00850 if ( $myConfig->getConfigParam( 'blSearchUseAND' ) ) {
00851 $sSearchSep = ' and ';
00852 } else {
00853 $sSearchSep = ' or ';
00854 }
00855
00856 $aSearchCols = $myConfig->getConfigParam( 'aSearchCols' );
00857 $oBaseObject = $this->getBaseObject();
00858 $myUtilsString = oxUtilsString::getInstance();
00859 foreach ( $aSearch as $sSearchString) {
00860
00861 if ( !strlen( $sSearchString ) ) {
00862 continue;
00863 }
00864
00865 if ( $blSep ) {
00866 $sSearch .= $sSearchSep;
00867 }
00868 $blSep2 = false;
00869 $sSearch .= '( ';
00870
00871 $sUml = $myUtilsString->prepareStrForSearch($sSearchString);
00872 foreach ( $aSearchCols as $sField ) {
00873
00874 if ( $blSep2) {
00875 $sSearch .= ' or ';
00876 }
00877
00878
00879 if ( $sField == 'oxlongdesc' || $sField == 'oxtags') {
00880 $sSearchTable = getViewName( 'oxartextends' );
00881 } else {
00882 $sSearchTable = $sArticleTable;
00883 }
00884
00885 $sField = $oBaseObject->getSqlFieldName( $sField );
00886
00887 $sSearch .= $sSearchTable.'.'.$sField.' like '.$oDb->quote('%'.$sSearchString.'%') . ' ';
00888 if ( $sUml ) {
00889 $sSearch .= ' or '.$sSearchTable.'.'.$sField.' like '.$oDb->quote('%'.$sUml.'%');
00890 }
00891 $blSep2 = true;
00892 }
00893 $sSearch .= ' ) ';
00894 $blSep = true;
00895 }
00896 $sSearch .= ' ) ';
00897
00898 return $sSearch;
00899 }
00900
00909 protected function _getPriceSelect( $dPriceFrom, $dPriceTo )
00910 {
00911 $oBaseObject = $this->getBaseObject();
00912 $sArticleTable = $oBaseObject->getViewName();
00913 $sSelectFields = $oBaseObject->getSelectFields();
00914
00915 $sSubSelect = "select if(oxparentid='',oxid,oxparentid) as id from $sArticleTable where oxprice > 0 ";
00916 if ( $dPriceTo) {
00917 $sSubSelect .= $dPriceTo?"and oxprice <= $dPriceTo ":" ";
00918 }
00919 $sSubSelect .= "group by id having ";
00920 if ( $dPriceFrom) {
00921 $sSubSelect .= $dPriceFrom?"min(oxprice) >= $dPriceFrom ":" ";
00922 }
00923 $sSelect = "select $sSelectFields from $sArticleTable where ";
00924 $sSelect .= "$sArticleTable.oxid in ($sSubSelect) ";
00925 $sSelect .= "and ".$oBaseObject->getSqlActiveSnippet()." and $sArticleTable.oxissearch = 1";
00926
00927 if ( !$this->_sCustomSorting ) {
00928 $sSelect .= " order by $sArticleTable.oxprice asc , $sArticleTable.oxid";
00929 } else {
00930 $sSelect .= " order by {$this->_sCustomSorting}, $sArticleTable.oxid ";
00931 }
00932
00933 return $sSelect;
00934
00935 }
00936
00944 protected function _getVendorSelect( $sVendorId )
00945 {
00946 $sArticleTable = getViewName('oxarticles');
00947 $oBaseObject = $this->getBaseObject();
00948 $sFieldNames = $oBaseObject->getSelectFields();
00949 $sSelect = "select $sFieldNames from $sArticleTable ";
00950 $sSelect .= "where $sArticleTable.oxvendorid = '$sVendorId' ";
00951 $sSelect .= " and " . $oBaseObject->getSqlActiveSnippet() . " and $sArticleTable.oxparentid = '' ";
00952
00953 if ( $this->_sCustomSorting ) {
00954 $sSelect .= " ORDER BY {$this->_sCustomSorting} ";
00955 }
00956
00957 return $sSelect;
00958 }
00959
00967 protected function _getManufacturerSelect( $sManufacturerId )
00968 {
00969 $sArticleTable = getViewName('oxarticles');
00970 $oBaseObject = $this->getBaseObject();
00971 $sFieldNames = $oBaseObject->getSelectFields();
00972 $sSelect = "select $sFieldNames from $sArticleTable ";
00973 $sSelect .= "where $sArticleTable.oxmanufacturerid = '$sManufacturerId' ";
00974 $sSelect .= " and " . $oBaseObject->getSqlActiveSnippet() . " and $sArticleTable.oxparentid = '' ";
00975
00976 if ( $this->_sCustomSorting ) {
00977 $sSelect .= " ORDER BY {$this->_sCustomSorting} ";
00978 }
00979
00980 return $sSelect;
00981 }
00982 }