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         $sArticleFields = str_replace( "$sArticleTable.oxid", "oxorderarticles.oxartid as oxid", $sArticleFields );
00693 
00694         $sSelect  = "SELECT $sArticleFields FROM oxorderarticles ";
00695         $sSelect .= "left join $sArticleTable on oxorderarticles.oxartid = $sArticleTable.oxid ";
00696         $sSelect .= "WHERE oxorderarticles.oxorderid IN ( '".implode("','", $aOrdersIds)."' ) ";
00697         $sSelect .= "order by $sArticleTable.oxid ";
00698 
00699         $this->selectString( $sSelect );
00700 
00701         // not active or not available products must not have button "tobasket"
00702         foreach ( $this as $oArticle ) {
00703             if ( !$oArticle->oxarticles__oxactive->value ) {
00704                 $oArticle->setBuyableState( false );
00705             }
00706         }
00707     }
00708 
00716     protected function _createIdListFromSql( $sSql)
00717     {
00718         $rs = oxDb::getDb(true)->execute( $sSql);
00719         if ($rs != false && $rs->recordCount() > 0) {
00720             while (!$rs->EOF) {
00721                 $rs->fields = array_change_key_case($rs->fields, CASE_LOWER);
00722                 $this[$rs->fields['oxid']] =  $rs->fields['oxid']; //only the oxid
00723                 $rs->moveNext();
00724             }
00725         }
00726     }
00727 
00736     protected function _getFilterSql($sCatId, $aFilter)
00737     {
00738         $sO2CView      = getViewName( 'oxobject2category' );
00739         $sArticleTable = getViewName( 'oxarticles' );
00740         $sFilter = '';
00741         $iCnt    = 0;
00742         $sSuffix = oxLang::getInstance()->getLanguageTag();
00743 
00744         foreach ( $aFilter as $sAttrId => $sValue ) {
00745             if ( $sValue ) {
00746                 if ( $sFilter ) {
00747                     $sFilter .= ' or ';
00748                 }
00749                 $sValue = mysql_real_escape_string($sValue);
00750                 $sFilter .= "( oa.oxattrid = '$sAttrId' and oa.oxvalue$sSuffix = '$sValue' )";
00751                 $iCnt++;
00752             }
00753         }
00754         if ( $sFilter ) {
00755             $sFilter = "WHERE $sFilter ";
00756         }
00757 
00758         $sFilterSelect = "select oc.oxobjectid as oxobjectid, count(*) as cnt from ";
00759         $sFilterSelect.= "(SELECT * FROM $sO2CView WHERE $sO2CView.oxcatnid = '$sCatId' GROUP BY $sO2CView.oxobjectid, $sO2CView.oxcatnid) as oc ";
00760         $sFilterSelect.= "INNER JOIN oxobject2attribute as oa ON ( oa.oxobjectid = oc.oxobjectid ) ";
00761         $sFilterSelect.= $sFilter;
00762         $sFilterSelect.= "GROUP BY oa.oxobjectid HAVING cnt = $iCnt ";
00763 
00764         $aIds = oxDb::getDb( true )->getAll( $sFilterSelect );
00765         $sIds = '';
00766 
00767         if ( $aIds ) {
00768             foreach ( $aIds as $aArt ) {
00769                 if ( $sIds ) {
00770                     $sIds .= ', ';
00771                 }
00772                 $sIds .= " '{$aArt['oxobjectid']}' ";
00773             }
00774 
00775             if ( $sIds ) {
00776                 $sFilterSql = " and $sArticleTable.oxid in ( $sIds ) ";
00777             }
00778         }
00779         return $sFilterSql;
00780     }
00781 
00791     protected function _getCategorySelect( $sFields, $sCatId, $aSessionFilter )
00792     {
00793         $sArticleTable = getViewName( 'oxarticles' );
00794         $sO2CView      = getViewName( 'oxobject2category' );
00795 
00796         // ----------------------------------
00797         // sorting
00798         $sSorting = '';
00799         if ( $this->_sCustomSorting ) {
00800             $sSorting = " {$this->_sCustomSorting} , ";
00801         }
00802 
00803         // ----------------------------------
00804         // filtering ?
00805         $sFilterSql = '';
00806         if ( $aSessionFilter && isset( $aSessionFilter[$sCatId] ) ) {
00807             $sFilterSql = $this->_getFilterSql($sCatId, $aSessionFilter[$sCatId]);
00808         }
00809 
00810         $sSelect = "SELECT $sFields FROM $sO2CView as oc left join $sArticleTable
00811                     ON $sArticleTable.oxid = oc.oxobjectid
00812                     WHERE ".$this->getBaseObject()->getSqlActiveSnippet()." and $sArticleTable.oxparentid = ''
00813                     and oc.oxcatnid = '$sCatId' $sFilterSql GROUP BY oc.oxcatnid, oc.oxobjectid ORDER BY $sSorting oc.oxpos, oc.oxobjectid ";
00814 
00815         return $sSelect;
00816     }
00817 
00825     protected function _getSearchSelect( $sSearchString )
00826     {
00827         // check if it has string at all
00828         if ( !$sSearchString || !str_replace( ' ', '', $sSearchString ) ) {
00829             return '';
00830         }
00831 
00832         $oDb = oxDb::getDb();
00833         $myConfig = $this->getConfig();
00834         $myUtils  = oxUtils::getInstance();
00835         $sArticleTable = $this->getBaseObject()->getViewName();
00836 
00837         $aSearch = explode( ' ', $sSearchString);
00838 
00839         $sSearch  = ' and ( ';
00840         $blSep = false;
00841 
00842         // #723
00843         if ( $myConfig->getConfigParam( 'blSearchUseAND' ) ) {
00844             $sSearchSep = ' and ';
00845         } else {
00846             $sSearchSep = ' or ';
00847         }
00848 
00849         $aSearchCols = $myConfig->getConfigParam( 'aSearchCols' );
00850         $oBaseObject = $this->getBaseObject();
00851         $myUtilsString = oxUtilsString::getInstance();
00852         foreach ( $aSearch as $sSearchString) {
00853 
00854             if ( !strlen( $sSearchString ) ) {
00855                 continue;
00856             }
00857 
00858             if ( $blSep ) {
00859                 $sSearch .= $sSearchSep;
00860             }
00861             $blSep2   = false;
00862             $sSearch .= '( ';
00863 
00864             $sUml = $myUtilsString->prepareStrForSearch($sSearchString);
00865             foreach ( $aSearchCols as $sField ) {
00866 
00867                 if ( $blSep2) {
00868                     $sSearch  .= ' or ';
00869                 }
00870 
00871                 // as long description now is on different table table must differ
00872                 if ( $sField == 'oxlongdesc' || $sField == 'oxtags') {
00873                     $sSearchTable = getViewName( 'oxartextends' );
00874                 } else {
00875                     $sSearchTable = $sArticleTable;
00876                 }
00877 
00878                 $sField = $oBaseObject->getSqlFieldName( $sField );
00879 
00880                 $sSearch .= $sSearchTable.'.'.$sField.' like '.$oDb->quote('%'.$sSearchString.'%') . ' ';
00881                 if ( $sUml ) {
00882                     $sSearch  .= ' or '.$sSearchTable.'.'.$sField.' like '.$oDb->quote('%'.$sUml.'%');
00883                 }
00884                 $blSep2 = true;
00885             }
00886             $sSearch  .= ' ) ';
00887             $blSep = true;
00888         }
00889         $sSearch .= ' ) ';
00890 
00891         return $sSearch;
00892     }
00893 
00902     protected function _getPriceSelect( $dPriceFrom, $dPriceTo )
00903     {
00904         $oBaseObject   = $this->getBaseObject();
00905         $sArticleTable = $oBaseObject->getViewName();
00906         $sSelectFields = $oBaseObject->getSelectFields();
00907 
00908         $sSubSelect  = "select if(oxparentid='',oxid,oxparentid) as id from $sArticleTable where oxprice > 0 ";
00909         if ( $dPriceTo) {
00910             $sSubSelect .= $dPriceTo?"and oxprice <= $dPriceTo ":" ";
00911         }
00912         $sSubSelect .= "group by id having ";
00913         if ( $dPriceFrom) {
00914             $sSubSelect .= $dPriceFrom?"min(oxprice) >= $dPriceFrom ":" ";
00915         }
00916         $sSelect =  "select $sSelectFields from $sArticleTable where ";
00917         $sSelect .= "$sArticleTable.oxid in ($sSubSelect) ";
00918         $sSelect .= "and ".$oBaseObject->getSqlActiveSnippet()." and $sArticleTable.oxissearch = 1";
00919 
00920         if ( !$this->_sCustomSorting ) {
00921             $sSelect .= " order by $sArticleTable.oxprice asc , $sArticleTable.oxid";
00922         } else {
00923             $sSelect .= " order by {$this->_sCustomSorting}, $sArticleTable.oxid ";
00924         }
00925 
00926         return $sSelect;
00927 
00928     }
00929 
00937     protected function _getVendorSelect( $sVendorId )
00938     {
00939         $sArticleTable = getViewName('oxarticles');
00940         $oBaseObject = $this->getBaseObject();
00941         $sFieldNames = $oBaseObject->getSelectFields();
00942         $sSelect  = "select $sFieldNames from $sArticleTable ";
00943         $sSelect .= "where $sArticleTable.oxvendorid = '$sVendorId' ";
00944         $sSelect .= " and " . $oBaseObject->getSqlActiveSnippet() . " and $sArticleTable.oxparentid = ''  ";
00945 
00946         if ( $this->_sCustomSorting ) {
00947             $sSelect .= " ORDER BY {$this->_sCustomSorting} ";
00948         }
00949 
00950         return $sSelect;
00951     }
00952 
00960     protected function _getManufacturerSelect( $sManufacturerId )
00961     {
00962         $sArticleTable = getViewName('oxarticles');
00963         $oBaseObject = $this->getBaseObject();
00964         $sFieldNames = $oBaseObject->getSelectFields();
00965         $sSelect  = "select $sFieldNames from $sArticleTable ";
00966         $sSelect .= "where $sArticleTable.oxmanufacturerid = '$sManufacturerId' ";
00967         $sSelect .= " and " . $oBaseObject->getSqlActiveSnippet() . " and $sArticleTable.oxparentid = ''  ";
00968 
00969         if ( $this->_sCustomSorting ) {
00970             $sSelect .= " ORDER BY {$this->_sCustomSorting} ";
00971         }
00972 
00973         return $sSelect;
00974     }
00975 }

Generated on Wed Jun 17 12:09:01 2009 for OXID eShop CE by  doxygen 1.5.5