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 $aHistoryArticles = array_values($aHistoryArticles);
00111 $this->loadIds($aHistoryArticles);
00112 $this->_sortByIds($aHistoryArticles);
00113 }
00114
00122 protected function _sortByIds($aIds)
00123 {
00124 $this->_aOrderMap = array_flip($aIds);
00125 uksort($this->_aArray, array($this, '_sortByOrderMapCallback'));
00126 }
00127
00138 protected function _sortByOrderMapCallback($key1, $key2)
00139 {
00140 if (isset($this->_aOrderMap[$key1])) {
00141 if (isset($this->_aOrderMap[$key2])) {
00142 $iDiff = $this->_aOrderMap[$key2] - $this->_aOrderMap[$key1];
00143 if ($iDiff > 0) {
00144 return -1;
00145 } elseif ($iDiff < 0) {
00146 return 1;
00147 } else {
00148 return 0;
00149 }
00150 } else {
00151
00152 return -1;
00153 }
00154 } elseif (isset($this->_aOrderMap[$key2])) {
00155
00156 return 1;
00157 } else {
00158
00159 return 0;
00160 }
00161 }
00162
00170 public function loadNewestArticles( $iLimit = null )
00171 {
00172
00173 $myConfig = $this->getConfig();
00174
00175 if ( !$myConfig->getConfigParam( 'bl_perfLoadPriceForAddList' ) ) {
00176 $this->_blLoadPrice = false;
00177 }
00178
00179 $this->_aArray = array();
00180 switch( $myConfig->getConfigParam( 'iNewestArticlesMode' ) ) {
00181 case 0:
00182
00183 break;
00184 case 1:
00185
00186 $this->loadAktionArticles( 'oxnewest' );
00187 break;
00188 case 2:
00189 $sArticleTable = getViewName('oxarticles');
00190 if ( $myConfig->getConfigParam( 'blNewArtByInsert' ) ) {
00191 $sType = 'oxinsert';
00192 } else {
00193 $sType = 'oxtimestamp';
00194 }
00195 $sSelect = "select * from $sArticleTable ";
00196 $sSelect .= "where oxparentid = '' and ".$this->getBaseObject()->getSqlActiveSnippet()." and oxissearch = 1 order by $sType desc ";
00197 if (!($iLimit = (int) $iLimit)) {
00198 $iLimit = $myConfig->getConfigParam( 'iNrofNewcomerArticles' );
00199 }
00200 $sSelect .= "limit " . $iLimit;
00201
00202 $this->selectString($sSelect);
00203 break;
00204 }
00205
00206 }
00207
00213 public function loadTop5Articles()
00214 {
00215
00216 $myConfig = $this->getConfig();
00217
00218 if ( !$myConfig->getConfigParam( 'bl_perfLoadPriceForAddList' ) ) {
00219 $this->_blLoadPrice = false;
00220 }
00221
00222 switch( $myConfig->getConfigParam( 'iTop5Mode' ) ) {
00223 case 0:
00224
00225 break;
00226 case 1:
00227
00228 $this->loadAktionArticles( 'oxtop5');
00229 break;
00230 case 2:
00231 $sArticleTable = getViewName('oxarticles');
00232
00233 $sSelect = "select * from $sArticleTable ";
00234 $sSelect .= "where ".$this->getBaseObject()->getSqlActiveSnippet()." and $sArticleTable.oxissearch = 1 ";
00235 $sSelect .= "and $sArticleTable.oxparentid = '' and $sArticleTable.oxsoldamount>0 ";
00236 $sSelect .= "order by $sArticleTable.oxsoldamount desc limit 5";
00237
00238 $this->selectString($sSelect);
00239 break;
00240 }
00241 }
00242
00250 public function loadAktionArticles( $sActionID )
00251 {
00252
00253 if ( !trim( $sActionID) ) {
00254 return;
00255 }
00256
00257 $sShopID = $this->getConfig()->getShopId();
00258 $sActionID = oxDb::getDb()->quote(strtolower( $sActionID));
00259
00260
00261 $oBaseObject = $this->getBaseObject();
00262 $sArticleTable = $oBaseObject->getViewName();
00263 $sArticleFields = $oBaseObject->getSelectFields();
00264
00265 $oBase = oxNew("oxactions");
00266 $sActiveSql = $oBase->getSqlActiveSnippet();
00267
00268 $sSelect = "select $sArticleFields from oxactions2article
00269 left join $sArticleTable on $sArticleTable.oxid = oxactions2article.oxartid
00270 left join oxactions on oxactions.oxid = oxactions2article.oxactionid
00271 where oxactions2article.oxshopid = '$sShopID' and oxactions2article.oxactionid = $sActionID and $sActiveSql
00272 and $sArticleTable.oxid is not null and " .$oBaseObject->getSqlActiveSnippet(). "
00273 order by oxactions2article.oxsort";
00274
00275 $this->selectString( $sSelect );
00276 }
00277
00285 public function loadArticleCrossSell( $sArticleId )
00286 {
00287 $myConfig = $this->getConfig();
00288
00289
00290 if ( !$myConfig->getConfigParam( 'bl_perfLoadCrossselling' ) ) {
00291 return null;
00292 }
00293
00294 $oBaseObject = $this->getBaseObject();
00295 $sArticleTable = $oBaseObject->getViewName();
00296
00297 $sArticleId = oxDb::getDb()->quote($sArticleId);
00298
00299 $sSelect = "select $sArticleTable.* from oxobject2article left join $sArticleTable on oxobject2article.oxobjectid=$sArticleTable.oxid ";
00300 $sSelect .= "where oxobject2article.oxarticlenid = $sArticleId ";
00301 $sSelect .= " and $sArticleTable.oxid is not null and " .$oBaseObject->getSqlActiveSnippet(). " order by rand()";
00302
00303
00304 if ( $myConfig->getConfigParam( 'blBidirectCross' ) ) {
00305 $sSelect = "select distinct $sArticleTable.* from oxobject2article left join $sArticleTable on (oxobject2article.oxobjectid=$sArticleTable.oxid or oxobject2article.oxarticlenid=$sArticleTable.oxid) ";
00306 $sSelect .= "where (oxobject2article.oxarticlenid = $sArticleId or oxobject2article.oxobjectid = $sArticleId )";
00307 $sSelect .= " and $sArticleTable.oxid is not null and " .$oBaseObject->getSqlActiveSnippet(). " having $sArticleTable.oxid!=$sArticleId order by rand()";
00308 }
00309
00310 $this->setSqlLimit( 0, $myConfig->getConfigParam( 'iNrofCrossellArticles' ));
00311 $this->selectString( $sSelect );
00312 }
00313
00321 public function loadArticleAccessoires( $sArticleId )
00322 {
00323 $myConfig = $this->getConfig();
00324
00325
00326 if ( !$myConfig->getConfigParam( 'bl_perfLoadAccessoires' ) ) {
00327 return;
00328 }
00329
00330 $sArticleId = oxDb::getDb()->quote($sArticleId);
00331
00332 $oBaseObject = $this->getBaseObject();
00333 $sArticleTable = $oBaseObject->getViewName();
00334
00335 $sSelect = "select $sArticleTable.* from oxaccessoire2article left join $sArticleTable on oxaccessoire2article.oxobjectid=$sArticleTable.oxid ";
00336 $sSelect .= "where oxaccessoire2article.oxarticlenid = $sArticleId ";
00337 $sSelect .= " and $sArticleTable.oxid is not null and " .$oBaseObject->getSqlActiveSnippet();
00338
00339 $sSelect .= " order by oxaccessoire2article.oxsort";
00340
00341 $this->selectString( $sSelect );
00342 }
00343
00352 public function loadCategoryIds( $sCatId, $aSessionFilter )
00353 {
00354 $sArticleTable = $this->getBaseObject()->getViewName();
00355 $sSelect = $this->_getCategorySelect( $sArticleTable.'.oxid as oxid', $sCatId, $aSessionFilter );
00356
00357 $this->_createIdListFromSql( $sSelect );
00358 }
00359
00369 public function loadCategoryArticles( $sCatId, $aSessionFilter, $iLimit = null )
00370 {
00371 $sArticleFields = $this->getBaseObject()->getSelectFields();
00372
00373 $sSelect = $this->_getCategorySelect( $sArticleFields, $sCatId, $aSessionFilter );
00374
00375
00376
00377 $iArticleCount = null;
00378 if ( $aSessionFilter) {
00379 $oRet = oxDb::getDb()->Execute( $sSelect );
00380 $iArticleCount = $oRet->recordCount();
00381 }
00382
00383 if ($iLimit = (int) $iLimit) {
00384 $sSelect .= " LIMIT $iLimit";
00385 }
00386
00387 $this->selectString( $sSelect );
00388
00389 if ( $iArticleCount !== null ) {
00390 return $iArticleCount;
00391 }
00392
00393 $iTotalCount = oxUtilsCount::getInstance()->getCatArticleCount($sCatId);
00394
00395
00396 return $iTotalCount;
00397 }
00398
00407 public function loadRecommArticles( $sRecommId, $sArticlesFilter = null )
00408 {
00409 $sSelect = $this->_getArticleSelect( $sRecommId, $sArticlesFilter);
00410 $this->selectString( $sSelect );
00411 }
00412
00421 public function loadRecommArticleIds( $sRecommId, $sArticlesFilter )
00422 {
00423 $sSelect = $this->_getArticleSelect( $sRecommId, $sArticlesFilter );
00424
00425 $sArtView = getViewName( 'oxarticles' );
00426 $sPartial = substr( $sSelect, strpos( $sSelect, ' from ' ) );
00427 $sSelect = "select distinct $sArtView.oxid $sPartial ";
00428
00429 $this->_createIdListFromSql( $sSelect );
00430 }
00431
00440 protected function _getArticleSelect( $sRecommId, $sArticlesFilter = null )
00441 {
00442 $sRecommId = oxDb::getDb()->quote($sRecommId);
00443
00444 $sArtView = getViewName( 'oxarticles' );
00445 $sSelect = "select distinct $sArtView.*, oxobject2list.oxdesc from oxobject2list ";
00446 $sSelect .= "left join $sArtView on oxobject2list.oxobjectid = $sArtView.oxid ";
00447 $sSelect .= "where (oxobject2list.oxlistid = $sRecommId) ".$sArticlesFilter;
00448
00449 return $sSelect;
00450 }
00451
00462 public function loadSearchIds( $sSearchStr = '', $sSearchCat = '', $sSearchVendor = '', $sSearchManufacturer = '' )
00463 {
00464 $oDb = oxDb::getDb();
00465 $sSearchCat = $sSearchCat?$sSearchCat:null;
00466 $sSearchVendor = $sSearchVendor?$sSearchVendor:null;
00467 $sSearchManufacturer = $sSearchManufacturer?$sSearchManufacturer:null;
00468
00469 $sWhere = null;
00470
00471 if ( $sSearchStr ) {
00472 $sWhere = $this->_getSearchSelect( $sSearchStr );
00473 }
00474
00475 $sArticleTable = getViewName('oxarticles');
00476
00477
00478 $sDescTable = '';
00479 $sDescJoin = '';
00480 if ( is_array( $aSearchCols = $this->getConfig()->getConfigParam( 'aSearchCols' ) ) ) {
00481 if ( in_array( 'oxlongdesc', $aSearchCols ) || in_array( 'oxtags', $aSearchCols ) ) {
00482 $sDescView = getViewName( 'oxartextends' );
00483 $sDescJoin = " LEFT JOIN $sDescView ON {$sDescView}.oxid={$sArticleTable}.oxid ";
00484 }
00485 }
00486
00487
00488 $sSelect = "select $sArticleTable.oxid from $sArticleTable $sDescJoin where ";
00489
00490
00491 if ( $sSearchCat ) {
00492 $sO2CView = getViewName('oxobject2category');
00493 $sSelect = "select $sArticleTable.oxid from $sO2CView as oxobject2category, $sArticleTable $sDescJoin ";
00494 $sSelect .= "where oxobject2category.oxcatnid=".$oDb->quote( $sSearchCat )." and oxobject2category.oxobjectid=$sArticleTable.oxid and ";
00495 }
00496 $sSelect .= $this->getBaseObject()->getSqlActiveSnippet();
00497 $sSelect .= " and $sArticleTable.oxparentid = '' and $sArticleTable.oxissearch = 1 ";
00498
00499
00500 if ( $sSearchVendor ) {
00501 $sSelect .= " and $sArticleTable.oxvendorid = ".$oDb->quote( $sSearchVendor )." ";
00502 }
00503
00504 if ( $sSearchManufacturer ) {
00505 $sSelect .= " and $sArticleTable.oxmanufacturerid = ".$oDb->quote( $sSearchManufacturer )." ";
00506 }
00507 $sSelect .= $sWhere;
00508
00509 if ($this->_sCustomSorting) {
00510 $sSelect .= " order by {$this->_sCustomSorting} ";
00511 }
00512
00513 $this->_createIdListFromSql($sSelect);
00514 }
00515
00524 public function loadPriceIds( $dPriceFrom, $dPriceTo )
00525 {
00526 $sSelect = $this->_getPriceSelect( $dPriceFrom, $dPriceTo );
00527 $this->_createIdListFromSql( $sSelect );
00528 }
00529
00540 public function loadPriceArticles( $dPriceFrom, $dPriceTo, $oCategory = null)
00541 {
00542 $sArticleTable = getViewName('oxarticles');
00543
00544 $sSelect = $this->_getPriceSelect( $dPriceFrom, $dPriceTo );
00545
00546 $this->selectString( $sSelect);
00547
00548
00549 if ( !$oCategory ) {
00550 return $this->count();
00551 }
00552
00553
00554 $iNumOfArticles = $oCategory->getNrOfArticles();
00555 if ( !isset($iNumOfArticles) || $iNumOfArticles == -1) {
00556 return oxUtilsCount::getInstance()->getPriceCatArticleCount($oCategory->getId(), $dPriceFrom, $dPriceTo );
00557 } else {
00558 return $oCategory->getNrOfArticles();
00559 }
00560 }
00561
00569 public function loadVendorIDs( $sVendorId)
00570 {
00571 $sSelect = $this->_getVendorSelect($sVendorId);
00572 $this->_createIdListFromSql($sSelect);
00573 }
00574
00582 public function loadManufacturerIDs( $sManufacturerId)
00583 {
00584 $sSelect = $this->_getManufacturerSelect($sManufacturerId);
00585 $this->_createIdListFromSql($sSelect);
00586 }
00587
00597 public function loadVendorArticles( $sVendorId, $oVendor = null )
00598 {
00599 $sSelect = $this->_getVendorSelect($sVendorId);
00600 $this->selectString( $sSelect);
00601
00602 return oxUtilsCount::getInstance()->getVendorArticleCount( $sVendorId );
00603 }
00604
00614 public function loadManufacturerArticles( $sManufacturerId, $oManufacturer = null )
00615 {
00616 $sSelect = $this->_getManufacturerSelect($sManufacturerId);
00617 $this->selectString( $sSelect);
00618
00619 return oxUtilsCount::getInstance()->getManufacturerArticleCount( $sManufacturerId );
00620 }
00621
00630 public function loadTagArticles( $sTag, $iLang )
00631 {
00632 $oListObject = $this->getBaseObject();
00633 $sArticleTable = $oListObject->getViewName();
00634 $sArticleFields = $oListObject->getSelectFields();
00635
00636 $sLangExt = oxLang::getInstance()->getLanguageTag( $iLang );
00637
00638 $oTagHandler = oxNew( 'oxtagcloud' );
00639 $sTag = $oTagHandler->prepareTags( $sTag );
00640
00641 $sQ = "select {$sArticleFields} from oxartextends inner join {$sArticleTable} on
00642 {$sArticleTable}.oxid = oxartextends.oxid where {$sArticleTable}.oxissearch = 1
00643 and match ( oxartextends.oxtags{$sLangExt} )
00644 against( ".oxDb::getDb()->quote( $sTag )." )";
00645
00646
00647 if ( ( $sActiveSnippet = $oListObject->getSqlActiveSnippet() ) ) {
00648 $sQ .= " and {$sActiveSnippet}";
00649 }
00650
00651 if ( $this->_sCustomSorting ) {
00652 $sSort = $this->_sCustomSorting;
00653 if (strpos($sSort, '.') === false) {
00654 $sSort = $sArticleTable.'.'.$sSort;
00655 }
00656 $sQ .= " order by $sSort ";
00657 }
00658
00659 $this->selectString( $sQ );
00660
00661
00662 return oxUtilsCount::getInstance()->getTagArticleCount( $sTag, $iLang );
00663 }
00664
00673 public function getTagArticleIds( $sTag, $iLang )
00674 {
00675 $oListObject = $this->getBaseObject();
00676 $sArticleTable = $oListObject->getViewName();
00677 $sLangExt = oxLang::getInstance()->getLanguageTag( $iLang );
00678
00679 $oTagHandler = oxNew( 'oxtagcloud' );
00680 $sTag = $oTagHandler->prepareTags( $sTag );
00681
00682 $sQ = "select oxartextends.oxid from oxartextends inner join {$sArticleTable} on
00683 {$sArticleTable}.oxid = oxartextends.oxid where {$sArticleTable}.oxissearch = 1 and
00684 match ( oxartextends.oxtags{$sLangExt} )
00685 against( ".oxDb::getDb()->quote( $sTag )." )";
00686
00687
00688 if ( ( $sActiveSnippet = $oListObject->getSqlActiveSnippet() ) ) {
00689 $sQ .= " and {$sActiveSnippet}";
00690 }
00691
00692 if ( $this->_sCustomSorting ) {
00693 $sSort = $this->_sCustomSorting;
00694 if (strpos($sSort, '.') === false) {
00695 $sSort = $sArticleTable.'.'.$sSort;
00696 }
00697 $sQ .= " order by $sSort ";
00698 }
00699
00700 return $this->_createIdListFromSql( $sQ );
00701 }
00702
00710 public function loadIds($aIds)
00711 {
00712 if (!count($aIds)) {
00713 $this->clear();
00714 return;
00715 }
00716
00717 foreach ($aIds as $iKey => $sVal) {
00718 $aIds[$iKey] = mysql_real_escape_string($sVal);
00719 }
00720
00721 $oBaseObject = $this->getBaseObject();
00722 $sArticleTable = $oBaseObject->getViewName();
00723 $sArticleFields = $oBaseObject->getSelectFields();
00724
00725 $sSelect = "select $sArticleFields from $sArticleTable ";
00726 $sSelect .= "where $sArticleTable.oxid in ( '".implode("','", $aIds)."' ) and ";
00727 $sSelect .= $oBaseObject->getSqlActiveSnippet();
00728
00729 $this->selectString($sSelect);
00730 }
00731
00739 public function loadOrderArticles($aOrders)
00740 {
00741 if (!count($aOrders)) {
00742 $this->clear();
00743 return;
00744 }
00745
00746 foreach ($aOrders as $iKey => $oOrder) {
00747 $aOrdersIds[] = $oOrder->getId();
00748 }
00749
00750 $oBaseObject = $this->getBaseObject();
00751 $sArticleTable = $oBaseObject->getViewName();
00752 $sArticleFields = $oBaseObject->getSelectFields();
00753 $sArticleFields = str_replace( "$sArticleTable.oxid", "oxorderarticles.oxartid as oxid", $sArticleFields );
00754
00755 $sSelect = "SELECT $sArticleFields FROM oxorderarticles ";
00756 $sSelect .= "left join $sArticleTable on oxorderarticles.oxartid = $sArticleTable.oxid ";
00757 $sSelect .= "WHERE oxorderarticles.oxorderid IN ( '".implode("','", $aOrdersIds)."' ) ";
00758 $sSelect .= "order by $sArticleTable.oxid ";
00759
00760 $this->selectString( $sSelect );
00761
00762
00763 foreach ( $this as $oArticle ) {
00764 if ( !$oArticle->oxarticles__oxactive->value ) {
00765 $oArticle->setBuyableState( false );
00766 }
00767 }
00768 }
00769
00777 protected function _createIdListFromSql( $sSql)
00778 {
00779 $rs = oxDb::getDb(true)->execute( $sSql);
00780 if ($rs != false && $rs->recordCount() > 0) {
00781 while (!$rs->EOF) {
00782 $rs->fields = array_change_key_case($rs->fields, CASE_LOWER);
00783 $this[$rs->fields['oxid']] = $rs->fields['oxid'];
00784 $rs->moveNext();
00785 }
00786 }
00787 }
00788
00797 protected function _getFilterIdsSql( $sCatId, $aFilter )
00798 {
00799 $sO2CView = getViewName( 'oxobject2category' );
00800 $sFilter = '';
00801 $iCnt = 0;
00802 $sSuffix = oxLang::getInstance()->getLanguageTag();
00803
00804 $oDb = oxDb::getDb();
00805 foreach ( $aFilter as $sAttrId => $sValue ) {
00806 if ( $sValue ) {
00807 if ( $sFilter ) {
00808 $sFilter .= ' or ';
00809 }
00810 $sValue = $oDb->quote( $sValue );
00811 $sAttrId = $oDb->quote( $sAttrId );
00812
00813 $sFilter .= "( oa.oxattrid = {$sAttrId} and oa.oxvalue{$sSuffix} = {$sValue} )";
00814 $iCnt++;
00815 }
00816 }
00817 if ( $sFilter ) {
00818 $sFilter = "WHERE $sFilter ";
00819 }
00820
00821 $sFilterSelect = "select oc.oxobjectid as oxobjectid, count(*) as cnt from ";
00822 $sFilterSelect.= "(SELECT * FROM $sO2CView WHERE $sO2CView.oxcatnid = '$sCatId' GROUP BY $sO2CView.oxobjectid, $sO2CView.oxcatnid) as oc ";
00823 $sFilterSelect.= "INNER JOIN oxobject2attribute as oa ON ( oa.oxobjectid = oc.oxobjectid ) ";
00824 return $sFilterSelect . "{$sFilter} GROUP BY oa.oxobjectid HAVING cnt = $iCnt ";
00825 }
00826
00835 protected function _getFilterSql( $sCatId, $aFilter )
00836 {
00837 $oDb = oxDb::getDb( true );
00838 $sArticleTable = getViewName( 'oxarticles' );
00839 $aIds = $oDb->getAll( $this->_getFilterIdsSql( $sCatId, $aFilter ) );
00840 $sIds = '';
00841
00842 if ( $aIds ) {
00843 foreach ( $aIds as $aArt ) {
00844 if ( $sIds ) {
00845 $sIds .= ', ';
00846 }
00847 $sIds .= $oDb->quote( current( $aArt ) );
00848 }
00849
00850 if ( $sIds ) {
00851 $sFilterSql = " and $sArticleTable.oxid in ( $sIds ) ";
00852 }
00853 }
00854 return $sFilterSql;
00855 }
00856
00866 protected function _getCategorySelect( $sFields, $sCatId, $aSessionFilter )
00867 {
00868 $sArticleTable = getViewName( 'oxarticles' );
00869 $sO2CView = getViewName( 'oxobject2category' );
00870
00871
00872
00873 $sSorting = '';
00874 if ( $this->_sCustomSorting ) {
00875 $sSorting = " {$this->_sCustomSorting} , ";
00876 }
00877
00878
00879
00880 $sFilterSql = '';
00881 if ( $aSessionFilter && isset( $aSessionFilter[$sCatId] ) ) {
00882 $sFilterSql = $this->_getFilterSql($sCatId, $aSessionFilter[$sCatId]);
00883 }
00884
00885 $oDb = oxDb::getDb();
00886
00887 $sSelect = "SELECT $sFields FROM $sO2CView as oc left join $sArticleTable
00888 ON $sArticleTable.oxid = oc.oxobjectid
00889 WHERE ".$this->getBaseObject()->getSqlActiveSnippet()." and $sArticleTable.oxparentid = ''
00890 and oc.oxcatnid = ".$oDb->quote($sCatId)." $sFilterSql GROUP BY oc.oxcatnid, oc.oxobjectid ORDER BY $sSorting oc.oxpos, oc.oxobjectid ";
00891
00892 return $sSelect;
00893 }
00894
00902 protected function _getSearchSelect( $sSearchString )
00903 {
00904
00905 if ( !$sSearchString || !str_replace( ' ', '', $sSearchString ) ) {
00906 return '';
00907 }
00908
00909 $oDb = oxDb::getDb();
00910 $myConfig = $this->getConfig();
00911 $myUtils = oxUtils::getInstance();
00912 $sArticleTable = $this->getBaseObject()->getViewName();
00913
00914 $aSearch = explode( ' ', $sSearchString);
00915
00916 $sSearch = ' and ( ';
00917 $blSep = false;
00918
00919
00920 if ( $myConfig->getConfigParam( 'blSearchUseAND' ) ) {
00921 $sSearchSep = ' and ';
00922 } else {
00923 $sSearchSep = ' or ';
00924 }
00925
00926 $aSearchCols = $myConfig->getConfigParam( 'aSearchCols' );
00927 $oBaseObject = $this->getBaseObject();
00928 $myUtilsString = oxUtilsString::getInstance();
00929 foreach ( $aSearch as $sSearchString) {
00930
00931 if ( !strlen( $sSearchString ) ) {
00932 continue;
00933 }
00934
00935 if ( $blSep ) {
00936 $sSearch .= $sSearchSep;
00937 }
00938 $blSep2 = false;
00939 $sSearch .= '( ';
00940
00941 $sUml = $myUtilsString->prepareStrForSearch($sSearchString);
00942 foreach ( $aSearchCols as $sField ) {
00943
00944 if ( $blSep2) {
00945 $sSearch .= ' or ';
00946 }
00947
00948
00949 if ( $sField == 'oxlongdesc' || $sField == 'oxtags') {
00950 $sSearchTable = getViewName( 'oxartextends' );
00951 } else {
00952 $sSearchTable = $sArticleTable;
00953 }
00954
00955 $sField = $oBaseObject->getSqlFieldName( $sField );
00956
00957 $sSearch .= $sSearchTable.'.'.$sField.' like '.$oDb->quote('%'.$sSearchString.'%') . ' ';
00958 if ( $sUml ) {
00959 $sSearch .= ' or '.$sSearchTable.'.'.$sField.' like '.$oDb->quote('%'.$sUml.'%');
00960 }
00961 $blSep2 = true;
00962 }
00963 $sSearch .= ' ) ';
00964 $blSep = true;
00965 }
00966 $sSearch .= ' ) ';
00967
00968 return $sSearch;
00969 }
00970
00979 protected function _getPriceSelect( $dPriceFrom, $dPriceTo )
00980 {
00981 $oBaseObject = $this->getBaseObject();
00982 $sArticleTable = $oBaseObject->getViewName();
00983 $sSelectFields = $oBaseObject->getSelectFields();
00984
00985 $sSubSelect = "select if( oxparentid = '',oxid,oxparentid ) as id from {$sArticleTable} where oxprice >= 0 ";
00986 if ($dPriceTo) {
00987 $sSubSelect .= "and oxprice <= ".(double)$dPriceTo." ";
00988 } else {
00989 $sSubSelect .= " ";
00990 }
00991 if ($dPriceFrom) {
00992 $sSubSelect .= "group by id having min( oxprice ) >= ".(double)$dPriceFrom." ";
00993 } else {
00994 $sSubSelect .= " ";
00995 }
00996
00997 $sSelect = "select {$sSelectFields} from {$sArticleTable} where ";
00998 $sSelect .= "{$sArticleTable}.oxid in ( {$sSubSelect} ) ";
00999 $sSelect .= "and ".$oBaseObject->getSqlActiveSnippet()." and {$sArticleTable}.oxissearch = 1";
01000
01001 if ( !$this->_sCustomSorting ) {
01002 $sSelect .= " order by {$sArticleTable}.oxprice asc , {$sArticleTable}.oxid";
01003 } else {
01004 $sSelect .= " order by {$this->_sCustomSorting}, {$sArticleTable}.oxid ";
01005 }
01006
01007 return $sSelect;
01008
01009 }
01010
01018 protected function _getVendorSelect( $sVendorId )
01019 {
01020 $sArticleTable = getViewName('oxarticles');
01021 $oBaseObject = $this->getBaseObject();
01022 $sFieldNames = $oBaseObject->getSelectFields();
01023 $sSelect = "select $sFieldNames from $sArticleTable ";
01024 $sSelect .= "where $sArticleTable.oxvendorid = ".oxDb::getDb()->quote($sVendorId)." ";
01025 $sSelect .= " and " . $oBaseObject->getSqlActiveSnippet() . " and $sArticleTable.oxparentid = '' ";
01026
01027 if ( $this->_sCustomSorting ) {
01028 $sSelect .= " ORDER BY {$this->_sCustomSorting} ";
01029 }
01030
01031 return $sSelect;
01032 }
01033
01041 protected function _getManufacturerSelect( $sManufacturerId )
01042 {
01043 $sArticleTable = getViewName('oxarticles');
01044 $oBaseObject = $this->getBaseObject();
01045 $sFieldNames = $oBaseObject->getSelectFields();
01046 $sSelect = "select $sFieldNames from $sArticleTable ";
01047 $sSelect .= "where $sArticleTable.oxmanufacturerid = ".oxDb::getDb()->quote($sManufacturerId)." ";
01048 $sSelect .= " and " . $oBaseObject->getSqlActiveSnippet() . " and $sArticleTable.oxparentid = '' ";
01049
01050 if ( $this->_sCustomSorting ) {
01051 $sSelect .= " ORDER BY {$this->_sCustomSorting} ";
01052 }
01053
01054 return $sSelect;
01055 }
01056
01064 public function loadStockRemindProducts( $aBasketContents )
01065 {
01066 if ( is_array( $aBasketContents ) && count( $aBasketContents ) ) {
01067 $oDb = oxDb::getDb();
01068 foreach ( $aBasketContents as $oBasketItem ) {
01069 $aArtIds[] = $oDb->quote($oBasketItem->getProductId());
01070 }
01071
01072 $oBaseObject = $this->getBaseObject();
01073
01074 $sFieldNames = $oBaseObject->getSelectFields();
01075 $sTable = $oBaseObject->getViewName();
01076
01077
01078 $sQ = "select {$sFieldNames} from {$sTable} where {$sTable}.oxid in ( ".implode( ",", $aArtIds )." ) and
01079 oxremindactive = '1' and oxstock <= oxremindamount";
01080 $this->selectString( $sQ );
01081
01082
01083 if ( $this->count() ) {
01084 $sQ = "update {$sTable} set oxremindactive = '2' where {$sTable}.oxid in ( ".implode( ",", $aArtIds )." ) and
01085 oxremindactive = '1' and oxstock <= oxremindamount";
01086 $oDb->execute( $sQ );
01087 }
01088 }
01089 }
01090 }