00001 <?php
00002
00007 class oxArticleList extends oxList
00008 {
00012 protected $_sCustomSorting;
00013
00019 protected $_sObjectsInListName = 'oxarticle';
00020
00026 protected $_blLoadSelectLists = false;
00027
00035 public function setCustomSorting( $sSorting )
00036 {
00037 $this->_sCustomSorting = $sSorting;
00038 }
00039
00045 public function enableSelectLists()
00046 {
00047 $this->_blLoadSelectLists = true;
00048 }
00049
00058 public function selectString( $sSelect )
00059 {
00060 startProfile("loadinglists");
00061 $oRes = parent::selectString( $sSelect );
00062 stopProfile("loadinglists");
00063
00064 return $oRes;
00065 }
00066
00072 public function getHistoryArticles()
00073 {
00074 if ($aArticlesIds = $this->getSession()->getVar('aHistoryArticles')) {
00075 return $aArticlesIds;
00076 } elseif ( $sArticlesIds = oxUtilsServer::getInstance()->getOxCookie('aHistoryArticles')) {
00077 return explode('|', $sArticlesIds);
00078 }
00079 }
00080
00088 public function setHistoryArticles($aArticlesIds)
00089 {
00090 if ($this->getSession()->getId()) {
00091 oxSession::setVar('aHistoryArticles', $aArticlesIds);
00092
00093 oxUtilsServer::getInstance()->setOxCookie('aHistoryArticles', '');
00094 } else {
00095 oxUtilsServer::getInstance()->setOxCookie('aHistoryArticles', implode('|', $aArticlesIds));
00096 }
00097 }
00098
00108 public function loadHistoryArticles( $sArtId, $iCnt = 4 )
00109 {
00110 $aHistoryArticles = $this->getHistoryArticles();
00111 $aHistoryArticles[] = $sArtId;
00112
00113
00114 $aHistoryArticles = array_unique( $aHistoryArticles );
00115 if ( count( $aHistoryArticles ) > ( $iCnt + 1 ) ) {
00116 array_shift( $aHistoryArticles );
00117 }
00118
00119 $this->setHistoryArticles( $aHistoryArticles );
00120
00121
00122
00123 if ( ( $iCurrentArt = array_search( $sArtId, $aHistoryArticles ) ) !== false ) {
00124 unset( $aHistoryArticles[$iCurrentArt] );
00125 }
00126
00127 $aHistoryArticles = array_values( $aHistoryArticles );
00128 $this->loadIds( $aHistoryArticles );
00129 $this->_sortByIds( $aHistoryArticles );
00130 }
00131
00139 protected function _sortByIds($aIds)
00140 {
00141 $this->_aOrderMap = array_flip($aIds);
00142 uksort($this->_aArray, array($this, '_sortByOrderMapCallback'));
00143 }
00144
00155 protected function _sortByOrderMapCallback($key1, $key2)
00156 {
00157 if (isset($this->_aOrderMap[$key1])) {
00158 if (isset($this->_aOrderMap[$key2])) {
00159 $iDiff = $this->_aOrderMap[$key2] - $this->_aOrderMap[$key1];
00160 if ($iDiff > 0) {
00161 return -1;
00162 } elseif ($iDiff < 0) {
00163 return 1;
00164 } else {
00165 return 0;
00166 }
00167 } else {
00168
00169 return -1;
00170 }
00171 } elseif (isset($this->_aOrderMap[$key2])) {
00172
00173 return 1;
00174 } else {
00175
00176 return 0;
00177 }
00178 }
00179
00187 public function loadNewestArticles( $iLimit = null )
00188 {
00189
00190 $myConfig = $this->getConfig();
00191
00192 if ( !$myConfig->getConfigParam( 'bl_perfLoadPriceForAddList' ) ) {
00193 $this->getBaseObject()->disablePriceLoad();
00194 }
00195
00196 $this->_aArray = array();
00197 switch( $myConfig->getConfigParam( 'iNewestArticlesMode' ) ) {
00198 case 0:
00199
00200 break;
00201 case 1:
00202
00203 $this->loadAktionArticles( 'oxnewest' );
00204 break;
00205 case 2:
00206 $sArticleTable = getViewName('oxarticles');
00207 if ( $myConfig->getConfigParam( 'blNewArtByInsert' ) ) {
00208 $sType = 'oxinsert';
00209 } else {
00210 $sType = 'oxtimestamp';
00211 }
00212 $sSelect = "select * from $sArticleTable ";
00213 $sSelect .= "where oxparentid = '' and ".$this->getBaseObject()->getSqlActiveSnippet()." and oxissearch = 1 order by $sType desc ";
00214 if (!($iLimit = (int) $iLimit)) {
00215 $iLimit = $myConfig->getConfigParam( 'iNrofNewcomerArticles' );
00216 }
00217 $sSelect .= "limit " . $iLimit;
00218
00219 $this->selectString($sSelect);
00220 break;
00221 }
00222
00223 }
00224
00230 public function loadTop5Articles()
00231 {
00232
00233 $myConfig = $this->getConfig();
00234
00235 if ( !$myConfig->getConfigParam( 'bl_perfLoadPriceForAddList' ) ) {
00236 $this->getBaseObject()->disablePriceLoad();
00237 }
00238
00239 switch( $myConfig->getConfigParam( 'iTop5Mode' ) ) {
00240 case 0:
00241
00242 break;
00243 case 1:
00244
00245 $this->loadAktionArticles( 'oxtop5');
00246 break;
00247 case 2:
00248 $sArticleTable = getViewName('oxarticles');
00249
00250 $sSelect = "select * from $sArticleTable ";
00251 $sSelect .= "where ".$this->getBaseObject()->getSqlActiveSnippet()." and $sArticleTable.oxissearch = 1 ";
00252 $sSelect .= "and $sArticleTable.oxparentid = '' and $sArticleTable.oxsoldamount>0 ";
00253 $sSelect .= "order by $sArticleTable.oxsoldamount desc limit 5";
00254
00255 $this->selectString($sSelect);
00256 break;
00257 }
00258 }
00259
00267 public function loadAktionArticles( $sActionID )
00268 {
00269
00270 if ( !trim( $sActionID) ) {
00271 return;
00272 }
00273
00274 $sShopID = $this->getConfig()->getShopId();
00275 $sActionID = oxDb::getDb()->quote(strtolower( $sActionID));
00276
00277
00278 $oBaseObject = $this->getBaseObject();
00279 $sArticleTable = $oBaseObject->getViewName();
00280 $sArticleFields = $oBaseObject->getSelectFields();
00281
00282 $oBase = oxNew("oxactions");
00283 $sActiveSql = $oBase->getSqlActiveSnippet();
00284 $sViewName = $oBase->getViewName();
00285
00286 $sSelect = "select $sArticleFields from oxactions2article
00287 left join $sArticleTable on $sArticleTable.oxid = oxactions2article.oxartid
00288 left join $sViewName on $sViewName.oxid = oxactions2article.oxactionid
00289 where oxactions2article.oxshopid = '$sShopID' and oxactions2article.oxactionid = $sActionID and $sActiveSql
00290 and $sArticleTable.oxid is not null and " .$oBaseObject->getSqlActiveSnippet(). "
00291 order by oxactions2article.oxsort";
00292
00293 $this->selectString( $sSelect );
00294 }
00295
00303 public function loadArticleCrossSell( $sArticleId )
00304 {
00305 $myConfig = $this->getConfig();
00306
00307
00308 if ( !$myConfig->getConfigParam( 'bl_perfLoadCrossselling' ) ) {
00309 return null;
00310 }
00311
00312 $oBaseObject = $this->getBaseObject();
00313 $sArticleTable = $oBaseObject->getViewName();
00314
00315 $sArticleId = oxDb::getDb()->quote($sArticleId);
00316
00317 $sSelect = "select $sArticleTable.* from oxobject2article left join $sArticleTable on oxobject2article.oxobjectid=$sArticleTable.oxid ";
00318 $sSelect .= "where oxobject2article.oxarticlenid = $sArticleId ";
00319 $sSelect .= " and $sArticleTable.oxid is not null and " .$oBaseObject->getSqlActiveSnippet(). " order by rand()";
00320
00321
00322 if ( $myConfig->getConfigParam( 'blBidirectCross' ) ) {
00323 $sSelect = "select distinct $sArticleTable.* from oxobject2article left join $sArticleTable on (oxobject2article.oxobjectid=$sArticleTable.oxid or oxobject2article.oxarticlenid=$sArticleTable.oxid) ";
00324 $sSelect .= "where (oxobject2article.oxarticlenid = $sArticleId or oxobject2article.oxobjectid = $sArticleId )";
00325 $sSelect .= " and $sArticleTable.oxid is not null and " .$oBaseObject->getSqlActiveSnippet(). " having $sArticleTable.oxid!=$sArticleId order by rand()";
00326 }
00327
00328 $this->setSqlLimit( 0, $myConfig->getConfigParam( 'iNrofCrossellArticles' ));
00329 $this->selectString( $sSelect );
00330 }
00331
00339 public function loadArticleAccessoires( $sArticleId )
00340 {
00341 $myConfig = $this->getConfig();
00342
00343
00344 if ( !$myConfig->getConfigParam( 'bl_perfLoadAccessoires' ) ) {
00345 return;
00346 }
00347
00348 $sArticleId = oxDb::getDb()->quote($sArticleId);
00349
00350 $oBaseObject = $this->getBaseObject();
00351 $sArticleTable = $oBaseObject->getViewName();
00352
00353 $sSelect = "select $sArticleTable.* from oxaccessoire2article left join $sArticleTable on oxaccessoire2article.oxobjectid=$sArticleTable.oxid ";
00354 $sSelect .= "where oxaccessoire2article.oxarticlenid = $sArticleId ";
00355 $sSelect .= " and $sArticleTable.oxid is not null and " .$oBaseObject->getSqlActiveSnippet();
00356
00357 $sSelect .= " order by oxaccessoire2article.oxsort";
00358
00359 $this->selectString( $sSelect );
00360 }
00361
00370 public function loadCategoryIds( $sCatId, $aSessionFilter )
00371 {
00372 $sArticleTable = $this->getBaseObject()->getViewName();
00373 $sSelect = $this->_getCategorySelect( $sArticleTable.'.oxid as oxid', $sCatId, $aSessionFilter );
00374
00375 $this->_createIdListFromSql( $sSelect );
00376 }
00377
00387 public function loadCategoryArticles( $sCatId, $aSessionFilter, $iLimit = null )
00388 {
00389 $sArticleFields = $this->getBaseObject()->getSelectFields();
00390
00391 $sSelect = $this->_getCategorySelect( $sArticleFields, $sCatId, $aSessionFilter );
00392
00393
00394
00395 $iArticleCount = null;
00396 if ( $aSessionFilter) {
00397 $oRet = oxDb::getDb()->execute( $sSelect );
00398 $iArticleCount = $oRet->recordCount();
00399 }
00400
00401 if ($iLimit = (int) $iLimit) {
00402 $sSelect .= " LIMIT $iLimit";
00403 }
00404
00405 $this->selectString( $sSelect );
00406
00407 if ( $iArticleCount !== null ) {
00408 return $iArticleCount;
00409 }
00410
00411 $iTotalCount = oxUtilsCount::getInstance()->getCatArticleCount($sCatId);
00412
00413
00414 return $iTotalCount;
00415 }
00416
00425 public function loadRecommArticles( $sRecommId, $sArticlesFilter = null )
00426 {
00427 $sSelect = $this->_getArticleSelect( $sRecommId, $sArticlesFilter);
00428 $this->selectString( $sSelect );
00429 }
00430
00439 public function loadRecommArticleIds( $sRecommId, $sArticlesFilter )
00440 {
00441 $sSelect = $this->_getArticleSelect( $sRecommId, $sArticlesFilter );
00442
00443 $sArtView = getViewName( 'oxarticles' );
00444 $sPartial = substr( $sSelect, strpos( $sSelect, ' from ' ) );
00445 $sSelect = "select distinct $sArtView.oxid $sPartial ";
00446
00447 $this->_createIdListFromSql( $sSelect );
00448 }
00449
00458 protected function _getArticleSelect( $sRecommId, $sArticlesFilter = null )
00459 {
00460 $sRecommId = oxDb::getDb()->quote($sRecommId);
00461
00462 $sArtView = getViewName( 'oxarticles' );
00463 $sSelect = "select distinct $sArtView.*, oxobject2list.oxdesc from oxobject2list ";
00464 $sSelect .= "left join $sArtView on oxobject2list.oxobjectid = $sArtView.oxid ";
00465 $sSelect .= "where (oxobject2list.oxlistid = $sRecommId) ".$sArticlesFilter;
00466
00467 return $sSelect;
00468 }
00469
00480 public function loadSearchIds( $sSearchStr = '', $sSearchCat = '', $sSearchVendor = '', $sSearchManufacturer = '' )
00481 {
00482 $oDb = oxDb::getDb();
00483 $sSearchCat = $sSearchCat?$sSearchCat:null;
00484 $sSearchVendor = $sSearchVendor?$sSearchVendor:null;
00485 $sSearchManufacturer = $sSearchManufacturer?$sSearchManufacturer:null;
00486
00487 $sWhere = null;
00488
00489 if ( $sSearchStr ) {
00490 $sWhere = $this->_getSearchSelect( $sSearchStr );
00491 }
00492
00493 $sArticleTable = getViewName('oxarticles');
00494
00495
00496 $sDescTable = '';
00497 $sDescJoin = '';
00498 if ( is_array( $aSearchCols = $this->getConfig()->getConfigParam( 'aSearchCols' ) ) ) {
00499 if ( in_array( 'oxlongdesc', $aSearchCols ) || in_array( 'oxtags', $aSearchCols ) ) {
00500 $sDescView = getViewName( 'oxartextends' );
00501 $sDescJoin = " LEFT JOIN $sDescView ON {$sDescView}.oxid={$sArticleTable}.oxid ";
00502 }
00503 }
00504
00505
00506 $sSelect = "select $sArticleTable.oxid from $sArticleTable $sDescJoin where ";
00507
00508
00509 if ( $sSearchCat ) {
00510 $sO2CView = getViewName('oxobject2category');
00511 $sSelect = "select $sArticleTable.oxid from $sO2CView as oxobject2category, $sArticleTable $sDescJoin ";
00512 $sSelect .= "where oxobject2category.oxcatnid=".$oDb->quote( $sSearchCat )." and oxobject2category.oxobjectid=$sArticleTable.oxid and ";
00513 }
00514 $sSelect .= $this->getBaseObject()->getSqlActiveSnippet();
00515 $sSelect .= " and $sArticleTable.oxparentid = '' and $sArticleTable.oxissearch = 1 ";
00516
00517
00518 if ( $sSearchVendor ) {
00519 $sSelect .= " and $sArticleTable.oxvendorid = ".$oDb->quote( $sSearchVendor )." ";
00520 }
00521
00522 if ( $sSearchManufacturer ) {
00523 $sSelect .= " and $sArticleTable.oxmanufacturerid = ".$oDb->quote( $sSearchManufacturer )." ";
00524 }
00525 $sSelect .= $sWhere;
00526
00527 if ($this->_sCustomSorting) {
00528 $sSelect .= " order by {$this->_sCustomSorting} ";
00529 }
00530
00531 $this->_createIdListFromSql($sSelect);
00532 }
00533
00542 public function loadPriceIds( $dPriceFrom, $dPriceTo )
00543 {
00544 $sSelect = $this->_getPriceSelect( $dPriceFrom, $dPriceTo );
00545 $this->_createIdListFromSql( $sSelect );
00546 }
00547
00558 public function loadPriceArticles( $dPriceFrom, $dPriceTo, $oCategory = null)
00559 {
00560 $sSelect = $this->_getPriceSelect( $dPriceFrom, $dPriceTo );
00561
00562 startProfile("loadPriceArticles");
00563 $this->selectString( $sSelect);
00564 stopProfile("loadPriceArticles");
00565
00566 if ( !$oCategory ) {
00567 return $this->count();
00568 }
00569
00570 $iTotalCount = oxUtilsCount::getInstance()->getPriceCatArticleCount($oCategory->getId(), $dPriceFrom, $dPriceTo );
00571
00572 return $iTotalCount;
00573 }
00574
00582 public function loadVendorIDs( $sVendorId)
00583 {
00584 $sSelect = $this->_getVendorSelect($sVendorId);
00585 $this->_createIdListFromSql($sSelect);
00586 }
00587
00595 public function loadManufacturerIDs( $sManufacturerId)
00596 {
00597 $sSelect = $this->_getManufacturerSelect($sManufacturerId);
00598 $this->_createIdListFromSql($sSelect);
00599 }
00600
00610 public function loadVendorArticles( $sVendorId, $oVendor = null )
00611 {
00612 $sSelect = $this->_getVendorSelect($sVendorId);
00613 $this->selectString( $sSelect);
00614
00615 return oxUtilsCount::getInstance()->getVendorArticleCount( $sVendorId );
00616 }
00617
00627 public function loadManufacturerArticles( $sManufacturerId, $oManufacturer = null )
00628 {
00629 $sSelect = $this->_getManufacturerSelect($sManufacturerId);
00630 $this->selectString( $sSelect);
00631
00632 return oxUtilsCount::getInstance()->getManufacturerArticleCount( $sManufacturerId );
00633 }
00634
00643 public function loadTagArticles( $sTag, $iLang )
00644 {
00645 $oListObject = $this->getBaseObject();
00646 $sArticleTable = $oListObject->getViewName();
00647 $sArticleFields = $oListObject->getSelectFields();
00648 $sViewName = getViewName( 'oxartextends', $iLang );
00649
00650 $oTagHandler = oxNew( 'oxtagcloud' );
00651 $sTag = $oTagHandler->prepareTags( $sTag );
00652
00653 $sQ = "select {$sArticleFields} from {$sViewName} inner join {$sArticleTable} on ".
00654 "{$sArticleTable}.oxid = {$sViewName}.oxid where {$sArticleTable}.oxparentid = '' AND match ( {$sViewName}.oxtags ) ".
00655 "against( ".oxDb::getDb()->quote( "\"".$sTag."\"" )." IN BOOLEAN MODE )";
00656
00657
00658 if ( ( $sActiveSnippet = $oListObject->getSqlActiveSnippet() ) ) {
00659 $sQ .= " and {$sActiveSnippet}";
00660 }
00661
00662 if ( $this->_sCustomSorting ) {
00663 $sSort = $this->_sCustomSorting;
00664 if (strpos($sSort, '.') === false) {
00665 $sSort = $sArticleTable.'.'.$sSort;
00666 }
00667 $sQ .= " order by $sSort ";
00668 }
00669
00670 $this->selectString( $sQ );
00671
00672
00673 return oxUtilsCount::getInstance()->getTagArticleCount( $sTag, $iLang );
00674 }
00675
00684 public function getTagArticleIds( $sTag, $iLang )
00685 {
00686 $oListObject = $this->getBaseObject();
00687 $sArticleTable = $oListObject->getViewName();
00688 $sViewName = getViewName( 'oxartextends', $iLang );
00689
00690 $oTagHandler = oxNew( 'oxtagcloud' );
00691 $sTag = $oTagHandler->prepareTags( $sTag );
00692
00693 $sQ = "select {$sViewName}.oxid from {$sViewName} inner join {$sArticleTable} on ".
00694 "{$sArticleTable}.oxid = {$sViewName}.oxid where {$sArticleTable}.oxissearch = 1 and ".
00695 "match ( {$sViewName}.oxtags ) ".
00696 "against( ".oxDb::getDb()->quote( "\"".$sTag."\"" )." IN BOOLEAN MODE )";
00697
00698
00699 if ( ( $sActiveSnippet = $oListObject->getSqlActiveSnippet() ) ) {
00700 $sQ .= " and {$sActiveSnippet}";
00701 }
00702
00703 if ( $this->_sCustomSorting ) {
00704 $sSort = $this->_sCustomSorting;
00705 if (strpos($sSort, '.') === false) {
00706 $sSort = $sArticleTable.'.'.$sSort;
00707 }
00708 $sQ .= " order by $sSort ";
00709 }
00710
00711 return $this->_createIdListFromSql( $sQ );
00712 }
00713
00721 public function loadIds($aIds)
00722 {
00723 if (!count($aIds)) {
00724 $this->clear();
00725 return;
00726 }
00727
00728 foreach ($aIds as $iKey => $sVal) {
00729 $aIds[$iKey] = mysql_real_escape_string($sVal);
00730 }
00731
00732 $oBaseObject = $this->getBaseObject();
00733 $sArticleTable = $oBaseObject->getViewName();
00734 $sArticleFields = $oBaseObject->getSelectFields();
00735
00736 $sSelect = "select $sArticleFields from $sArticleTable ";
00737 $sSelect .= "where $sArticleTable.oxid in ( '".implode("','", $aIds)."' ) and ";
00738 $sSelect .= $oBaseObject->getSqlActiveSnippet();
00739
00740 $this->selectString($sSelect);
00741 }
00742
00750 public function loadOrderArticles($aOrders)
00751 {
00752 if (!count($aOrders)) {
00753 $this->clear();
00754 return;
00755 }
00756
00757 foreach ($aOrders as $iKey => $oOrder) {
00758 $aOrdersIds[] = $oOrder->getId();
00759 }
00760
00761 $oBaseObject = $this->getBaseObject();
00762 $sArticleTable = $oBaseObject->getViewName();
00763 $sArticleFields = $oBaseObject->getSelectFields();
00764 $sArticleFields = str_replace( "$sArticleTable.oxid", "oxorderarticles.oxartid as oxid", $sArticleFields );
00765
00766 $sSelect = "SELECT $sArticleFields FROM oxorderarticles ";
00767 $sSelect .= "left join $sArticleTable on oxorderarticles.oxartid = $sArticleTable.oxid ";
00768 $sSelect .= "WHERE oxorderarticles.oxorderid IN ( '".implode("','", $aOrdersIds)."' ) ";
00769 $sSelect .= "order by $sArticleTable.oxid ";
00770
00771 $this->selectString( $sSelect );
00772
00773
00774 foreach ( $this as $oArticle ) {
00775 if ( !$oArticle->oxarticles__oxactive->value ) {
00776 $oArticle->setBuyableState( false );
00777 }
00778 }
00779 }
00780
00788 protected function _createIdListFromSql( $sSql)
00789 {
00790 $rs = oxDb::getDb(true)->execute( $sSql);
00791 if ($rs != false && $rs->recordCount() > 0) {
00792 while (!$rs->EOF) {
00793 $rs->fields = array_change_key_case($rs->fields, CASE_LOWER);
00794 $this[$rs->fields['oxid']] = $rs->fields['oxid'];
00795 $rs->moveNext();
00796 }
00797 }
00798 }
00799
00808 protected function _getFilterIdsSql( $sCatId, $aFilter )
00809 {
00810 $sO2CView = getViewName( 'oxobject2category' );
00811 $sO2AView = getViewName( 'oxobject2attribute' );
00812
00813 $sFilter = '';
00814 $iCnt = 0;
00815
00816 $oDb = oxDb::getDb();
00817 foreach ( $aFilter as $sAttrId => $sValue ) {
00818 if ( $sValue ) {
00819 if ( $sFilter ) {
00820 $sFilter .= ' or ';
00821 }
00822 $sValue = $oDb->quote( $sValue );
00823 $sAttrId = $oDb->quote( $sAttrId );
00824
00825 $sFilter .= "( oa.oxattrid = {$sAttrId} and oa.oxvalue = {$sValue} )";
00826 $iCnt++;
00827 }
00828 }
00829 if ( $sFilter ) {
00830 $sFilter = "WHERE $sFilter ";
00831 }
00832
00833 $sFilterSelect = "select oc.oxobjectid as oxobjectid, count(*) as cnt from ";
00834 $sFilterSelect.= "(SELECT * FROM $sO2CView WHERE $sO2CView.oxcatnid = '$sCatId' GROUP BY $sO2CView.oxobjectid, $sO2CView.oxcatnid) as oc ";
00835 $sFilterSelect.= "INNER JOIN $sO2AView as oa ON ( oa.oxobjectid = oc.oxobjectid ) ";
00836 return $sFilterSelect . "{$sFilter} GROUP BY oa.oxobjectid HAVING cnt = $iCnt ";
00837 }
00838
00847 protected function _getFilterSql( $sCatId, $aFilter )
00848 {
00849 $oDb = oxDb::getDb( true );
00850 $sArticleTable = getViewName( 'oxarticles' );
00851 $aIds = $oDb->getAll( $this->_getFilterIdsSql( $sCatId, $aFilter ) );
00852 $sIds = '';
00853
00854 if ( $aIds ) {
00855 foreach ( $aIds as $aArt ) {
00856 if ( $sIds ) {
00857 $sIds .= ', ';
00858 }
00859 $sIds .= $oDb->quote( current( $aArt ) );
00860 }
00861
00862 if ( $sIds ) {
00863 $sFilterSql = " and $sArticleTable.oxid in ( $sIds ) ";
00864 }
00865
00866 } elseif ( !( current( $aFilter ) == '' && count( array_unique( $aFilter ) ) == 1 ) ) {
00867 $sFilterSql = " and false ";
00868 }
00869
00870 return $sFilterSql;
00871 }
00872
00882 protected function _getCategorySelect( $sFields, $sCatId, $aSessionFilter )
00883 {
00884 $sArticleTable = getViewName( 'oxarticles' );
00885 $sO2CView = getViewName( 'oxobject2category' );
00886
00887
00888
00889 $sSorting = '';
00890 if ( $this->_sCustomSorting ) {
00891 $sSorting = " {$this->_sCustomSorting} , ";
00892 }
00893
00894
00895
00896 $sFilterSql = '';
00897 $iLang = oxLang::getInstance()->getBaseLanguage();
00898 if ( $aSessionFilter && isset( $aSessionFilter[$sCatId][$iLang] ) ) {
00899 $sFilterSql = $this->_getFilterSql($sCatId, $aSessionFilter[$sCatId][$iLang]);
00900 }
00901
00902 $oDb = oxDb::getDb();
00903
00904 $sSelect = "SELECT $sFields FROM $sO2CView as oc left join $sArticleTable
00905 ON $sArticleTable.oxid = oc.oxobjectid
00906 WHERE ".$this->getBaseObject()->getSqlActiveSnippet()." and $sArticleTable.oxparentid = ''
00907 and oc.oxcatnid = ".$oDb->quote($sCatId)." $sFilterSql GROUP BY oc.oxcatnid, oc.oxobjectid ORDER BY $sSorting oc.oxpos, oc.oxobjectid ";
00908
00909 return $sSelect;
00910 }
00911
00919 protected function _getSearchSelect( $sSearchString )
00920 {
00921
00922 if ( !$sSearchString || !str_replace( ' ', '', $sSearchString ) ) {
00923 return '';
00924 }
00925
00926 $oDb = oxDb::getDb();
00927 $myConfig = $this->getConfig();
00928 $myUtils = oxUtils::getInstance();
00929 $sArticleTable = $this->getBaseObject()->getViewName();
00930
00931 $aSearch = explode( ' ', $sSearchString);
00932
00933 $sSearch = ' and ( ';
00934 $blSep = false;
00935
00936
00937 if ( $myConfig->getConfigParam( 'blSearchUseAND' ) ) {
00938 $sSearchSep = ' and ';
00939 } else {
00940 $sSearchSep = ' or ';
00941 }
00942
00943 $aSearchCols = $myConfig->getConfigParam( 'aSearchCols' );
00944 $oBaseObject = $this->getBaseObject();
00945 $myUtilsString = oxUtilsString::getInstance();
00946 foreach ( $aSearch as $sSearchString) {
00947
00948 if ( !strlen( $sSearchString ) ) {
00949 continue;
00950 }
00951
00952 if ( $blSep ) {
00953 $sSearch .= $sSearchSep;
00954 }
00955 $blSep2 = false;
00956 $sSearch .= '( ';
00957
00958 $sUml = $myUtilsString->prepareStrForSearch($sSearchString);
00959 foreach ( $aSearchCols as $sField ) {
00960
00961 if ( $blSep2) {
00962 $sSearch .= ' or ';
00963 }
00964
00965
00966 if ( $sField == 'oxlongdesc' || $sField == 'oxtags') {
00967 $sSearchTable = getViewName( 'oxartextends' );
00968 } else {
00969 $sSearchTable = $sArticleTable;
00970 }
00971
00972 $sSearch .= $sSearchTable.'.'.$sField.' like '.$oDb->quote('%'.$sSearchString.'%') . ' ';
00973 if ( $sUml ) {
00974 $sSearch .= ' or '.$sSearchTable.'.'.$sField.' like '.$oDb->quote('%'.$sUml.'%');
00975 }
00976 $blSep2 = true;
00977 }
00978 $sSearch .= ' ) ';
00979 $blSep = true;
00980 }
00981 $sSearch .= ' ) ';
00982
00983 return $sSearch;
00984 }
00985
00994 protected function _getPriceSelect( $dPriceFrom, $dPriceTo )
00995 {
00996 $oBaseObject = $this->getBaseObject();
00997 $sArticleTable = $oBaseObject->getViewName();
00998 $sSelectFields = $oBaseObject->getSelectFields();
00999
01000 $sSubSelect = "";
01001
01002 $sSelect = "select {$sSelectFields} from {$sArticleTable} where oxvarminprice >= 0 ";
01003 $sSelect .= $dPriceTo ? "and oxvarminprice <= " . (double)$dPriceTo . " " : " ";
01004 $sSelect .= $dPriceFrom ? "and oxvarminprice >= " . (double)$dPriceFrom . " " : " ";
01005
01006 $sSelect .= " and ".$oBaseObject->getSqlActiveSnippet()." and {$sArticleTable}.oxissearch = 1";
01007
01008 if ( !$this->_sCustomSorting ) {
01009 $sSelect .= " order by {$sArticleTable}.oxvarminprice asc , {$sArticleTable}.oxid";
01010 } else {
01011 $sSelect .= " order by {$this->_sCustomSorting}, {$sArticleTable}.oxid ";
01012 }
01013
01014 return $sSelect;
01015 }
01016
01024 protected function _getVendorSelect( $sVendorId )
01025 {
01026 $sArticleTable = getViewName('oxarticles');
01027 $oBaseObject = $this->getBaseObject();
01028 $sFieldNames = $oBaseObject->getSelectFields();
01029 $sSelect = "select $sFieldNames from $sArticleTable ";
01030 $sSelect .= "where $sArticleTable.oxvendorid = ".oxDb::getDb()->quote($sVendorId)." ";
01031 $sSelect .= " and " . $oBaseObject->getSqlActiveSnippet() . " and $sArticleTable.oxparentid = '' ";
01032
01033 if ( $this->_sCustomSorting ) {
01034 $sSelect .= " ORDER BY {$this->_sCustomSorting} ";
01035 }
01036
01037 return $sSelect;
01038 }
01039
01047 protected function _getManufacturerSelect( $sManufacturerId )
01048 {
01049 $sArticleTable = getViewName('oxarticles');
01050 $oBaseObject = $this->getBaseObject();
01051 $sFieldNames = $oBaseObject->getSelectFields();
01052 $sSelect = "select $sFieldNames from $sArticleTable ";
01053 $sSelect .= "where $sArticleTable.oxmanufacturerid = ".oxDb::getDb()->quote($sManufacturerId)." ";
01054 $sSelect .= " and " . $oBaseObject->getSqlActiveSnippet() . " and $sArticleTable.oxparentid = '' ";
01055
01056 if ( $this->_sCustomSorting ) {
01057 $sSelect .= " ORDER BY {$this->_sCustomSorting} ";
01058 }
01059
01060 return $sSelect;
01061 }
01062
01070 public function loadStockRemindProducts( $aBasketContents )
01071 {
01072 if ( is_array( $aBasketContents ) && count( $aBasketContents ) ) {
01073 $oDb = oxDb::getDb();
01074 foreach ( $aBasketContents as $oBasketItem ) {
01075 $aArtIds[] = $oDb->quote($oBasketItem->getProductId());
01076 }
01077
01078 $oBaseObject = $this->getBaseObject();
01079
01080 $sFieldNames = $oBaseObject->getSelectFields();
01081 $sTable = $oBaseObject->getViewName();
01082
01083
01084 $sQ = "select {$sFieldNames} from {$sTable} where {$sTable}.oxid in ( ".implode( ",", $aArtIds )." ) and
01085 oxremindactive = '1' and oxstock <= oxremindamount";
01086 $this->selectString( $sQ );
01087
01088
01089 if ( $this->count() ) {
01090 $sQ = "update {$sTable} set oxremindactive = '2' where {$sTable}.oxid in ( ".implode( ",", $aArtIds )." ) and
01091 oxremindactive = '1' and oxstock <= oxremindamount";
01092 $oDb->execute( $sQ );
01093 }
01094 }
01095 }
01096 }