oxarticlelist.php

Go to the documentation of this file.
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         // sorting for multilanguage fields
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         // removing dublicates
00096         $aHistoryArticles = array_unique( $aHistoryArticles);
00097 
00098         if (count($aHistoryArticles) > 5) {
00099             array_shift($aHistoryArticles);
00100         }
00101 
00102         //add to session
00103         $mySession->setVar('aHistoryArticles', $aHistoryArticles);
00104 
00105         //remove current article and return array
00106         //asignment =, not ==
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         //has module?
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                 // switched off, do nothing
00134                 break;
00135             case 1:
00136                 // manually entered
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         //has module?
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                 // switched off, do nothing
00176                 break;
00177             case 1:
00178                 // manually entered
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         // Performance
00204         if ( !trim( $sActionID) ) {
00205             return;
00206         }
00207 
00208         $sShopID        = $this->getConfig()->getShopId();
00209         $sActionID      = strtolower( $sActionID);
00210 
00211         //echo $sSelect;
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         // Performance
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         // #525 bidirectional crossselling
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         // Performance
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         //sorting articles
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         // calc count - we can not use count($this) here as we might have paging enabled
00323         // #1970C - if any filters are used, we can not use cached category article count
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         // this select is FAST so no need to hazzle here with getNrOfArticles()
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         // longdesc field now is kept on different table
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                 $sDescTable = ", {$sDescView} ";
00429                 $sDescJoin  = " {$sDescView}.oxid={$sArticleTable}.oxid and ";
00430             }
00431         }
00432 
00433         // load the articles
00434         $sSelect  =  "select $sArticleTable.oxid from $sArticleTable $sDescTable where $sDescJoin";
00435 
00436         // must be additional conditions in select if searching in category
00437         if ( $sSearchCat ) {
00438             $sO2CView = getViewName('oxobject2category');
00439             $sSelect  = "select $sArticleTable.oxid from $sArticleTable, $sO2CView as oxobject2category $sDescTable ";
00440             $sSelect .= "where oxobject2category.oxcatnid=$sSearchCat and oxobject2category.oxobjectid=$sArticleTable.oxid and $sDescJoin ";
00441         }
00442         $sSelect .= $this->getBaseObject()->getSqlActiveSnippet();
00443         $sSelect .= " and $sArticleTable.oxparentid = '' and $sArticleTable.oxissearch = 1 ";
00444 
00445         // #671
00446         if ( $sSearchVendor ) {
00447             $sSelect .= " and $sArticleTable.oxvendorid = $sSearchVendor ";
00448         }
00449 
00450         if ( $sSearchManufacturer ) {
00451             $sSelect .= " and $sArticleTable.oxmanufacturerid = $sSearchManufacturer ";
00452         }
00453         $sSelect .= $sWhere;
00454 
00455         if ($this->_sCustomSorting) {
00456             $sSelect .= " order by {$this->_sCustomSorting} ";
00457         }
00458 
00459         $this->_createIdListFromSql($sSelect);
00460     }
00461 
00470     public function loadPriceIds( $dPriceFrom, $dPriceTo )
00471     {
00472 
00473         $sSelect =  $this->_getPriceSelect( $dPriceFrom, $dPriceTo );
00474         $this->_createIdListFromSql($sSelect);
00475     }
00476 
00487     public function loadPriceArticles( $dPriceFrom, $dPriceTo, $oCategory = null)
00488     {
00489         $sArticleTable = getViewName('oxarticles');
00490 
00491         $sSelect =  $this->_getPriceSelect( $dPriceFrom, $dPriceTo );
00492 
00493         $this->selectString( $sSelect);
00494         //echo( $sSelect);
00495 
00496         if ( !$oCategory ) {
00497             return $this->count();
00498         }
00499 
00500         // #858A
00501         $iNumOfArticles = $oCategory->getNrOfArticles();
00502         if ( !isset($iNumOfArticles) || $iNumOfArticles == -1) {
00503             return oxUtilsCount::getInstance()->getPriceCatArticleCount($oCategory->getId(), $dPriceFrom, $dPriceTo );
00504         } else {
00505             return $oCategory->getNrOfArticles();
00506         }
00507     }
00508 
00516     public function loadVendorIDs( $sVendorId)
00517     {
00518         $sSelect = $this->_getVendorSelect($sVendorId);
00519         $this->_createIdListFromSql($sSelect);
00520     }
00521 
00529     public function loadManufacturerIDs( $sManufacturerId)
00530     {
00531         $sSelect = $this->_getManufacturerSelect($sManufacturerId);
00532         $this->_createIdListFromSql($sSelect);
00533     }
00534 
00544     public function loadVendorArticles( $sVendorId, $oVendor = null )
00545     {
00546         $sSelect = $this->_getVendorSelect($sVendorId);
00547         $this->selectString( $sSelect);
00548 
00549         return oxUtilsCount::getInstance()->getVendorArticleCount( $sVendorId );
00550     }
00551 
00561     public function loadManufacturerArticles( $sManufacturerId, $oManufacturer = null )
00562     {
00563         $sSelect = $this->_getManufacturerSelect($sManufacturerId);
00564         $this->selectString( $sSelect);
00565 
00566         return oxUtilsCount::getInstance()->getManufacturerArticleCount( $sManufacturerId );
00567     }
00568 
00577     public function loadTagArticles( $sTag, $iLang )
00578     {
00579         $oListObject = $this->getBaseObject();
00580         $sArticleTable = $oListObject->getViewName();
00581         $sArticleFields = $oListObject->getSelectFields();
00582 
00583         $sLangExt = oxLang::getInstance()->getLanguageTag( $iLang );
00584 
00585         $oTagHandler = oxNew( 'oxtagcloud' );
00586         $sTag = $oTagHandler->prepareTags( $sTag );
00587 
00588         $sQ = "select {$sArticleFields} from oxartextends inner join {$sArticleTable} on
00589                {$sArticleTable}.oxid = oxartextends.oxid where {$sArticleTable}.oxissearch = 1
00590                and match ( oxartextends.oxtags{$sLangExt} )
00591                against( ".oxDb::getDb()->quote( $sTag )." )";
00592 
00593         // checking stock etc
00594         if ( ( $sActiveSnippet = $oListObject->getSqlActiveSnippet() ) ) {
00595             $sQ .= " and {$sActiveSnippet}";
00596         }
00597 
00598         if ( $this->_sCustomSorting ) {
00599             $sQ .= " order by {$sArticleTable}.{$this->_sCustomSorting} ";
00600         }
00601 
00602         $this->selectString( $sQ );
00603 
00604         // calc count - we can not use count($this) here as we might have paging enabled
00605         return oxUtilsCount::getInstance()->getTagArticleCount( $sTag, $iLang );
00606     }
00607 
00616     public function getTagArticleIds( $sTag, $iLang )
00617     {
00618         $oListObject = $this->getBaseObject();
00619         $sArticleTable = $oListObject->getViewName();
00620         $sLangExt = oxLang::getInstance()->getLanguageTag( $iLang );
00621 
00622         $oTagHandler = oxNew( 'oxtagcloud' );
00623         $sTag = $oTagHandler->prepareTags( $sTag );
00624 
00625         $sQ = "select oxartextends.oxid from oxartextends inner join {$sArticleTable} on
00626                {$sArticleTable}.oxid = oxartextends.oxid where {$sArticleTable}.oxissearch = 1 and
00627                match ( oxartextends.oxtags{$sLangExt} )
00628                against( ".oxDb::getDb()->quote( $sTag )." )";
00629 
00630         // checking stock etc
00631         if ( ( $sActiveSnippet = $oListObject->getSqlActiveSnippet() ) ) {
00632             $sQ .= " and {$sActiveSnippet}";
00633         }
00634 
00635         if ( $this->_sCustomSorting ) {
00636             $sQ .= " order by {$sArticleTable}.{$this->_sCustomSorting} ";
00637         }
00638 
00639         return $this->_createIdListFromSql( $sQ );
00640     }
00641 
00649     public function loadIds($aIds)
00650     {
00651         if (!count($aIds)) {
00652             $this->clear();
00653             return;
00654         }
00655 
00656         foreach ($aIds as $iKey => $sVal) {
00657             $aIds[$iKey] = mysql_real_escape_string($sVal);
00658         }
00659 
00660         $oBaseObject    = $this->getBaseObject();
00661         $sArticleTable  = $oBaseObject->getViewName();
00662         $sArticleFields = $oBaseObject->getSelectFields();
00663 
00664         $sSelect  = "select $sArticleFields from $sArticleTable ";
00665         $sSelect .= "where $sArticleTable.oxid in ( '".implode("','", $aIds)."' ) and ";
00666         $sSelect .= $oBaseObject->getSqlActiveSnippet();
00667 
00668         $this->selectString($sSelect);
00669     }
00670 
00678     public function loadOrderArticles($aOrders)
00679     {
00680         if (!count($aOrders)) {
00681             $this->clear();
00682             return;
00683         }
00684 
00685         foreach ($aOrders as $iKey => $oOrder) {
00686             $aOrdersIds[] = $oOrder->getId();
00687         }
00688 
00689         $oBaseObject    = $this->getBaseObject();
00690         $sArticleTable  = $oBaseObject->getViewName();
00691         $sArticleFields = $oBaseObject->getSelectFields();
00692 
00693         $sSelect  = "SELECT $sArticleFields FROM oxorderarticles ";
00694         $sSelect .= "left join $sArticleTable on oxorderarticles.oxartid = $sArticleTable.oxid ";
00695         $sSelect .= "WHERE oxorderarticles.oxorderid IN ( '".implode("','", $aOrdersIds)."' ) ";
00696         $sSelect .= "order by $sArticleTable.oxid ";
00697 
00698         $this->selectString( $sSelect );
00699     }
00700 
00708     protected function _createIdListFromSql( $sSql)
00709     {
00710         $rs = oxDb::getDb(true)->execute( $sSql);
00711         if ($rs != false && $rs->recordCount() > 0) {
00712             while (!$rs->EOF) {
00713                 $rs->fields = array_change_key_case($rs->fields, CASE_LOWER);
00714                 $this[$rs->fields['oxid']] =  $rs->fields['oxid']; //only the oxid
00715                 $rs->moveNext();
00716             }
00717         }
00718     }
00719 
00728     protected function _getFilterSql($sCatId, $aFilter)
00729     {
00730         $sO2CView      = getViewName( 'oxobject2category' );
00731         $sArticleTable = getViewName( 'oxarticles' );
00732         $sFilter = '';
00733         $iCnt    = 0;
00734         $sSuffix = oxLang::getInstance()->getLanguageTag();
00735 
00736         foreach ( $aFilter as $sAttrId => $sValue ) {
00737             if ( $sValue ) {
00738                 if ( $sFilter ) {
00739                     $sFilter .= ' or ';
00740                 }
00741                 $sValue = mysql_real_escape_string($sValue);
00742                 $sFilter .= "( oa.oxattrid = '$sAttrId' and oa.oxvalue$sSuffix = '$sValue' )";
00743                 $iCnt++;
00744             }
00745         }
00746         if ( $sFilter ) {
00747             $sFilter = "WHERE $sFilter ";
00748         }
00749 
00750         $sFilterSelect = "select oc.oxobjectid as oxobjectid, count(*) as cnt from ";
00751         $sFilterSelect.= "(SELECT * FROM $sO2CView WHERE $sO2CView.oxcatnid = '$sCatId' GROUP BY $sO2CView.oxobjectid, $sO2CView.oxcatnid) as oc ";
00752         $sFilterSelect.= "INNER JOIN oxobject2attribute as oa ON ( oa.oxobjectid = oc.oxobjectid ) ";
00753         $sFilterSelect.= $sFilter;
00754         $sFilterSelect.= "GROUP BY oa.oxobjectid HAVING cnt = $iCnt ";
00755 
00756         $aIds = oxDb::getDb( true )->getAll( $sFilterSelect );
00757         $sIds = '';
00758 
00759         if ( $aIds ) {
00760             foreach ( $aIds as $aArt ) {
00761                 if ( $sIds ) {
00762                     $sIds .= ', ';
00763                 }
00764                 $sIds .= " '{$aArt['oxobjectid']}' ";
00765             }
00766 
00767             if ( $sIds ) {
00768                 $sFilterSql = " and $sArticleTable.oxid in ( $sIds ) ";
00769             }
00770         }
00771         return $sFilterSql;
00772     }
00773 
00783     protected function _getCategorySelect( $sFields, $sCatId, $aSessionFilter )
00784     {
00785         $sArticleTable = getViewName( 'oxarticles' );
00786         $sO2CView      = getViewName( 'oxobject2category' );
00787 
00788         // ----------------------------------
00789         // sorting
00790         $sSorting = '';
00791         if ( $this->_sCustomSorting ) {
00792             $sSorting = " {$this->_sCustomSorting} , ";
00793         }
00794 
00795         // ----------------------------------
00796         // filtering ?
00797         $sFilterSql = '';
00798         if ( $aSessionFilter && isset( $aSessionFilter[$sCatId] ) ) {
00799             $sFilterSql = $this->_getFilterSql($sCatId, $aSessionFilter[$sCatId]);
00800         }
00801 
00802         $sSelect = "SELECT $sFields FROM $sO2CView as oc left join $sArticleTable
00803                     ON $sArticleTable.oxid = oc.oxobjectid
00804                     WHERE ".$this->getBaseObject()->getSqlActiveSnippet()." and $sArticleTable.oxparentid = ''
00805                     and oc.oxcatnid = '$sCatId' $sFilterSql GROUP BY oc.oxcatnid, oc.oxobjectid ORDER BY $sSorting oc.oxpos, oc.oxobjectid ";
00806 
00807         return $sSelect;
00808     }
00809 
00817     protected function _getSearchSelect( $sSearchString )
00818     {
00819         // check if it has string at all
00820         if ( !$sSearchString || !str_replace( ' ', '', $sSearchString ) ) {
00821             return '';
00822         }
00823 
00824         $oDb = oxDb::getDb();
00825         $myConfig = $this->getConfig();
00826         $myUtils  = oxUtils::getInstance();
00827         $sArticleTable = $this->getBaseObject()->getViewName();
00828 
00829         $aSearch = explode( ' ', $sSearchString);
00830 
00831         $sSearch  = ' and ( ';
00832         $blSep = false;
00833 
00834         // #723
00835         if ( $myConfig->getConfigParam( 'blSearchUseAND' ) ) {
00836             $sSearchSep = ' and ';
00837         } else {
00838             $sSearchSep = ' or ';
00839         }
00840 
00841         $aSearchCols = $myConfig->getConfigParam( 'aSearchCols' );
00842         $oBaseObject = $this->getBaseObject();
00843         $myUtilsString = oxUtilsString::getInstance();
00844         foreach ( $aSearch as $sSearchString) {
00845 
00846             if ( !strlen( $sSearchString ) ) {
00847                 continue;
00848             }
00849 
00850             if ( $blSep ) {
00851                 $sSearch .= $sSearchSep;
00852             }
00853             $blSep2   = false;
00854             $sSearch .= '( ';
00855 
00856             $sUml = $myUtilsString->prepareStrForSearch($sSearchString);
00857             foreach ( $aSearchCols as $sField ) {
00858 
00859                 if ( $blSep2) {
00860                     $sSearch  .= ' or ';
00861                 }
00862 
00863                 // as long description now is on different table table must differ
00864                 if ( $sField == 'oxlongdesc' || $sField == 'oxtags') {
00865                     $sSearchTable = getViewName( 'oxartextends' );
00866                 } else {
00867                     $sSearchTable = $sArticleTable;
00868                 }
00869 
00870                 $sField = $oBaseObject->getSqlFieldName( $sField );
00871 
00872                 $sSearch .= $sSearchTable.'.'.$sField.' like '.$oDb->quote('%'.$sSearchString.'%') . ' ';
00873                 if ( $sUml ) {
00874                     $sSearch  .= ' or '.$sSearchTable.'.'.$sField.' like '.$oDb->quote('%'.$sUml.'%');
00875                 }
00876                 $blSep2 = true;
00877             }
00878             $sSearch  .= ' ) ';
00879             $blSep = true;
00880         }
00881         $sSearch .= ' ) ';
00882 
00883         return $sSearch;
00884     }
00885 
00894     protected function _getPriceSelect( $dPriceFrom, $dPriceTo )
00895     {
00896         $oBaseObject   = $this->getBaseObject();
00897         $sArticleTable = $oBaseObject->getViewName();
00898         $sSelectFields = $oBaseObject->getSelectFields();
00899 
00900         $sSubSelect  = "select if(oxparentid='',oxid,oxparentid) as id from $sArticleTable where oxprice > 0 ";
00901         if ( $dPriceTo) {
00902             $sSubSelect .= $dPriceTo?"and oxprice <= $dPriceTo ":" ";
00903         }
00904         $sSubSelect .= "group by id having ";
00905         if ( $dPriceFrom) {
00906             $sSubSelect .= $dPriceFrom?"min(oxprice) >= $dPriceFrom ":" ";
00907         }
00908         $sSelect =  "select $sSelectFields from $sArticleTable where ";
00909         $sSelect .= "$sArticleTable.oxid in ($sSubSelect) ";
00910         $sSelect .= "and ".$oBaseObject->getSqlActiveSnippet()." and $sArticleTable.oxissearch = 1";
00911 
00912         if ( !$this->_sCustomSorting ) {
00913             $sSelect .= " order by $sArticleTable.oxprice asc , $sArticleTable.oxid";
00914         } else {
00915             $sSelect .= " order by {$this->_sCustomSorting}, $sArticleTable.oxid ";
00916         }
00917 
00918         return $sSelect;
00919 
00920     }
00921 
00929     protected function _getVendorSelect( $sVendorId )
00930     {
00931         $sArticleTable = getViewName('oxarticles');
00932         $oBaseObject = $this->getBaseObject();
00933         $sFieldNames = $oBaseObject->getSelectFields();
00934         $sSelect  = "select $sFieldNames from $sArticleTable ";
00935         $sSelect .= "where $sArticleTable.oxvendorid = '$sVendorId' ";
00936         $sSelect .= " and " . $oBaseObject->getSqlActiveSnippet() . " and $sArticleTable.oxparentid = ''  ";
00937 
00938         if ( $this->_sCustomSorting ) {
00939             $sSelect .= " ORDER BY {$this->_sCustomSorting} ";
00940         }
00941 
00942         return $sSelect;
00943     }
00944 
00952     protected function _getManufacturerSelect( $sManufacturerId )
00953     {
00954         $sArticleTable = getViewName('oxarticles');
00955         $oBaseObject = $this->getBaseObject();
00956         $sFieldNames = $oBaseObject->getSelectFields();
00957         $sSelect  = "select $sFieldNames from $sArticleTable ";
00958         $sSelect .= "where $sArticleTable.oxmanufacturerid = '$sManufacturerId' ";
00959         $sSelect .= " and " . $oBaseObject->getSqlActiveSnippet() . " and $sArticleTable.oxparentid = ''  ";
00960 
00961         if ( $this->_sCustomSorting ) {
00962             $sSelect .= " ORDER BY {$this->_sCustomSorting} ";
00963         }
00964 
00965         return $sSelect;
00966     }
00967 }

Generated on Wed May 13 13:25:51 2009 for OXID eShop CE by  doxygen 1.5.5