38 $this->_sCustomSorting = $sSorting;
48 $this->_blLoadSelectLists =
true;
61 startProfile(
"loadinglists");
63 stopProfile(
"loadinglists");
77 if ($aArticlesIds = $this->
getSession()->getVariable(
'aHistoryArticles')) {
78 $aResult = $aArticlesIds;
79 } elseif ( $sArticlesIds =
oxRegistry::get(
"oxUtilsServer")->getOxCookie(
'aHistoryArticles')) {
80 $aResult = explode(
'|', $sArticlesIds);
96 $this->
getSession()->setVariable(
'aHistoryArticles', $aArticlesIds);
100 oxRegistry::get(
"oxUtilsServer")->setOxCookie(
'aHistoryArticles', implode(
'|', $aArticlesIds));
116 $aHistoryArticles[] = $sArtId;
119 $aHistoryArticles = array_unique( $aHistoryArticles );
120 if (
count( $aHistoryArticles ) > ( $iCnt + 1 ) ) {
121 array_shift( $aHistoryArticles );
128 if ( ( $iCurrentArt = array_search( $sArtId, $aHistoryArticles ) ) !==
false ) {
129 unset( $aHistoryArticles[$iCurrentArt] );
132 $aHistoryArticles = array_values( $aHistoryArticles );
133 $this->
loadIds( $aHistoryArticles );
146 $this->_aOrderMap = array_flip( $aIds );
147 uksort($this->_aArray, array($this,
'_sortByOrderMapCallback'));
162 if (isset($this->_aOrderMap[$key1])) {
163 if (isset($this->_aOrderMap[$key2])) {
164 $iDiff = $this->_aOrderMap[$key2] - $this->_aOrderMap[$key1];
167 } elseif ($iDiff < 0) {
176 } elseif (isset($this->_aOrderMap[$key2])) {
197 if ( !
$myConfig->getConfigParam(
'bl_perfLoadPriceForAddList' ) ) {
201 $this->_aArray = array();
202 switch(
$myConfig->getConfigParam(
'iNewestArticlesMode' ) ) {
211 $sArticleTable = getViewName(
'oxarticles');
212 if (
$myConfig->getConfigParam(
'blNewArtByInsert' ) ) {
215 $sType =
'oxtimestamp';
217 $sSelect =
"select * from $sArticleTable ";
218 $sSelect .=
"where oxparentid = '' and ".$this->getBaseObject()->getSqlActiveSnippet().
" and oxissearch = 1 order by $sType desc ";
219 if (!($iLimit = (
int) $iLimit)) {
220 $iLimit =
$myConfig->getConfigParam(
'iNrofNewcomerArticles' );
222 $sSelect .=
"limit " . $iLimit;
242 if ( !
$myConfig->getConfigParam(
'bl_perfLoadPriceForAddList' ) ) {
246 switch(
$myConfig->getConfigParam(
'iTop5Mode' ) ) {
255 $sArticleTable = getViewName(
'oxarticles');
258 $sLimit = ( $iLimit > 0 ) ?
"limit " . $iLimit :
'limit 5';
260 $sSelect =
"select * from $sArticleTable ";
261 $sSelect .=
"where ".$this->getBaseObject()->getSqlActiveSnippet().
" and $sArticleTable.oxissearch = 1 ";
262 $sSelect .=
"and $sArticleTable.oxparentid = '' and $sArticleTable.oxsoldamount>0 ";
263 $sSelect .=
"order by $sArticleTable.oxsoldamount desc $sLimit";
281 if ( !trim( $sActionID) ) {
285 $sShopID = $this->
getConfig()->getShopId();
286 $sActionID =
oxDb::getDb()->quote(strtolower( $sActionID));
290 $sArticleTable = $oBaseObject->getViewName();
291 $sArticleFields = $oBaseObject->getSelectFields();
293 $oBase =
oxNew(
"oxactions");
294 $sActiveSql = $oBase->getSqlActiveSnippet();
295 $sViewName = $oBase->getViewName();
297 $sLimit = ( $iLimit > 0 ) ?
"limit " . $iLimit :
'';
299 $sSelect =
"select $sArticleFields from oxactions2article
300 left join $sArticleTable on $sArticleTable.oxid = oxactions2article.oxartid
301 left join $sViewName on $sViewName.oxid = oxactions2article.oxactionid
302 where oxactions2article.oxshopid = '$sShopID' and oxactions2article.oxactionid = $sActionID and $sActiveSql
303 and $sArticleTable.oxid is not null and " .$oBaseObject->getSqlActiveSnippet().
"
304 order by oxactions2article.oxsort $sLimit";
338 if ( !
$myConfig->getConfigParam(
'bl_perfLoadCrossselling' ) ) {
343 $sArticleTable = $oBaseObject->getViewName();
347 $sSelect =
"SELECT $sArticleTable.*
348 FROM $sArticleTable INNER JOIN oxobject2article ON oxobject2article.oxobjectid=$sArticleTable.oxid ";
349 $sSelect .=
"WHERE oxobject2article.oxarticlenid = $sArticleId ";
350 $sSelect .=
" AND " .$oBaseObject->getSqlActiveSnippet();
353 if (
$myConfig->getConfigParam(
'blBidirectCross' ) ) {
356 SELECT $sArticleTable.* FROM $sArticleTable
357 INNER JOIN oxobject2article AS O2A1 on
358 ( O2A1.oxobjectid = $sArticleTable.oxid AND O2A1.oxarticlenid = $sArticleId )
360 AND " . $oBaseObject->getSqlActiveSnippet() .
"
361 AND ($sArticleTable.oxid != $sArticleId)
365 SELECT $sArticleTable.* FROM $sArticleTable
366 INNER JOIN oxobject2article AS O2A2 ON
367 ( O2A2.oxarticlenid = $sArticleTable.oxid AND O2A2.oxobjectid = $sArticleId )
369 AND " . $oBaseObject->getSqlActiveSnippet() .
"
370 AND ($sArticleTable.oxid != $sArticleId)
390 if ( !
$myConfig->getConfigParam(
'bl_perfLoadAccessoires' ) ) {
397 $sArticleTable = $oBaseObject->getViewName();
399 $sSelect =
"select $sArticleTable.* from oxaccessoire2article left join $sArticleTable on oxaccessoire2article.oxobjectid=$sArticleTable.oxid ";
400 $sSelect .=
"where oxaccessoire2article.oxarticlenid = $sArticleId ";
401 $sSelect .=
" and $sArticleTable.oxid is not null and " .$oBaseObject->getSqlActiveSnippet();
403 $sSelect .=
" order by oxaccessoire2article.oxsort";
419 $sSelect = $this->
_getCategorySelect( $sArticleTable.
'.oxid as oxid', $sCatId, $aSessionFilter );
441 $iArticleCount = null;
442 if ( $aSessionFilter) {
446 if ($iLimit = (
int) $iLimit) {
447 $sSelect .=
" LIMIT $iLimit";
452 if ( $iArticleCount !== null ) {
453 return $iArticleCount;
486 $sArtView = getViewName(
'oxarticles' );
487 $sPartial = substr( $sSelect, strpos( $sSelect,
' from ' ) );
488 $sSelect =
"select distinct $sArtView.oxid $sPartial ";
505 $sArtView = getViewName(
'oxarticles' );
506 $sSelect =
"select distinct $sArtView.*, oxobject2list.oxdesc from oxobject2list ";
507 $sSelect .=
"left join $sArtView on oxobject2list.oxobjectid = $sArtView.oxid ";
508 $sSelect .=
"where (oxobject2list.oxlistid = $sRecommId) ".$sArticlesFilter;
523 public function loadSearchIds( $sSearchStr =
'', $sSearchCat =
'', $sSearchVendor =
'', $sSearchManufacturer =
'' )
526 $sSearchCat = $sSearchCat?$sSearchCat:null;
527 $sSearchVendor = $sSearchVendor?$sSearchVendor:null;
528 $sSearchManufacturer = $sSearchManufacturer?$sSearchManufacturer:null;
536 $sArticleTable = getViewName(
'oxarticles');
540 if ( is_array( $aSearchCols = $this->
getConfig()->getConfigParam(
'aSearchCols' ) ) ) {
541 if ( in_array(
'oxlongdesc', $aSearchCols ) || in_array(
'oxtags', $aSearchCols ) ) {
542 $sDescView = getViewName(
'oxartextends' );
543 $sDescJoin =
" LEFT JOIN $sDescView ON {$sDescView}.oxid={$sArticleTable}.oxid ";
548 $sSelect =
"select $sArticleTable.oxid, $sArticleTable.oxtimestamp from $sArticleTable $sDescJoin where ";
552 $sO2CView = getViewName(
'oxobject2category');
553 $sSelect =
"select $sArticleTable.oxid from $sO2CView as oxobject2category, $sArticleTable $sDescJoin ";
554 $sSelect .=
"where oxobject2category.oxcatnid=".$oDb->quote( $sSearchCat ).
" and oxobject2category.oxobjectid=$sArticleTable.oxid and ";
557 $sSelect .=
" and $sArticleTable.oxparentid = '' and $sArticleTable.oxissearch = 1 ";
560 if ( $sSearchVendor ) {
561 $sSelect .=
" and $sArticleTable.oxvendorid = ".$oDb->quote( $sSearchVendor ).
" ";
564 if ( $sSearchManufacturer ) {
565 $sSelect .=
" and $sArticleTable.oxmanufacturerid = ".$oDb->quote( $sSearchManufacturer ).
" ";
569 if ($this->_sCustomSorting) {
570 $sSelect .=
" order by {$this->_sCustomSorting} ";
604 startProfile(
"loadPriceArticles");
606 stopProfile(
"loadPriceArticles");
609 return $this->
count();
612 return oxRegistry::get(
"oxUtilsCount")->getPriceCatArticleCount( $oCategory->getId(), $dPriceFrom, $dPriceTo );
655 return oxRegistry::get(
"oxUtilsCount")->getVendorArticleCount( $sVendorId );
672 return oxRegistry::get(
"oxUtilsCount")->getManufacturerArticleCount( $sManufacturerId );
686 $sArticleTable = $oListObject->getViewName();
687 $sArticleFields = $oListObject->getSelectFields();
688 $sViewName = getViewName(
'oxartextends', $iLang );
690 $oTag =
oxNew(
'oxtag', $sTag );
691 $oTag->addUnderscores();
692 $sTag = $oTag->get();
694 $sQ =
"select {$sArticleFields} from {$sViewName} inner join {$sArticleTable} on ".
695 "{$sArticleTable}.oxid = {$sViewName}.oxid where {$sArticleTable}.oxparentid = '' AND match ( {$sViewName}.oxtags ) ".
696 "against( ".oxDb::getDb()->quote(
"\"".$sTag.
"\"" ).
" IN BOOLEAN MODE )";
699 if ( ( $sActiveSnippet = $oListObject->getSqlActiveSnippet() ) ) {
700 $sQ .=
" and {$sActiveSnippet}";
703 if ( $this->_sCustomSorting ) {
705 if (strpos($sSort,
'.') ===
false) {
706 $sSort = $sArticleTable.
'.'.$sSort;
708 $sQ .=
" order by $sSort ";
714 return oxRegistry::get(
"oxUtilsCount")->getTagArticleCount( $sTag, $iLang );
728 $sArticleTable = $oListObject->getViewName();
729 $sViewName = getViewName(
'oxartextends', $iLang );
731 $oTag =
oxNew(
'oxtag', $sTag );
732 $oTag->addUnderscores();
733 $sTag = $oTag->get();
735 $sQ =
"select {$sViewName}.oxid from {$sViewName} inner join {$sArticleTable} on ".
736 "{$sArticleTable}.oxid = {$sViewName}.oxid where {$sArticleTable}.oxparentid = '' and {$sArticleTable}.oxissearch = 1 and ".
737 "match ( {$sViewName}.oxtags ) ".
738 "against( ".oxDb::getDb()->quote(
"\"".$sTag.
"\"" ).
" IN BOOLEAN MODE )";
741 if ( ( $sActiveSnippet = $oListObject->getSqlActiveSnippet() ) ) {
742 $sQ .=
" and {$sActiveSnippet}";
745 if ( $this->_sCustomSorting ) {
747 if (strpos($sSort,
'.') ===
false) {
748 $sSort = $sArticleTable.
'.'.$sSort;
750 $sQ .=
" order by $sSort ";
770 foreach ($aIds as $iKey => $sVal) {
775 $sArticleTable = $oBaseObject->getViewName();
776 $sArticleFields = $oBaseObject->getSelectFields();
778 $sSelect =
"select $sArticleFields from $sArticleTable ";
779 $sSelect .=
"where $sArticleTable.oxid in ( '".implode(
"','", $aIds).
"' ) and ";
780 $sSelect .= $oBaseObject->getSqlActiveSnippet();
794 if (!
count($aOrders)) {
799 foreach ($aOrders as $oOrder) {
800 $aOrdersIds[] = $oOrder->getId();
804 $sArticleTable = $oBaseObject->getViewName();
805 $sArticleFields = $oBaseObject->getSelectFields();
806 $sArticleFields = str_replace(
"`$sArticleTable`.`oxid`",
"`oxorderarticles`.`oxartid` AS `oxid`", $sArticleFields );
808 $sSelect =
"SELECT $sArticleFields FROM oxorderarticles ";
809 $sSelect .=
"left join $sArticleTable on oxorderarticles.oxartid = $sArticleTable.oxid ";
810 $sSelect .=
"WHERE oxorderarticles.oxorderid IN ( '".implode(
"','", $aOrdersIds).
"' ) ";
811 $sSelect .=
"order by $sArticleTable.oxid ";
816 $sNow = date(
'Y-m-d H:i:s');
817 foreach ( $this as $oArticle ) {
818 if ( !$oArticle->oxarticles__oxactive->value &&
819 ( $oArticle->oxarticles__oxactivefrom->value > $sNow ||
820 $oArticle->oxarticles__oxactiveto->value < $sNow
822 $oArticle->setBuyableState(
false );
836 if ( is_array( $aBasketContents ) &&
count( $aBasketContents ) ) {
838 foreach ( $aBasketContents as $oBasketItem ) {
839 $aArtIds[] = $oDb->quote($oBasketItem->getProductId());
844 $sFieldNames = $oBaseObject->getSelectFields();
845 $sTable = $oBaseObject->getViewName();
848 $sQ =
"select {$sFieldNames} from {$sTable} where {$sTable}.oxid in ( ".implode(
",", $aArtIds ).
" ) and
849 oxremindactive = '1' and oxstock <= oxremindamount";
853 if ( $this->
count() ) {
854 $sQ =
"update {$sTable} set oxremindactive = '2' where {$sTable}.oxid in ( ".implode(
",", $aArtIds ).
" ) and
855 oxremindactive = '1' and oxstock <= oxremindamount";
856 $oDb->execute( $sQ );
871 $sQ =
"select unix_timestamp( oxupdatepricetime ) from %s where oxupdatepricetime > 0 order by oxupdatepricetime asc";
872 $iTimeToUpdate = $oDb->getOne( sprintf( $sQ,
"`oxarticles`" ),
false,
false );
877 $iNextUpdateTime = $iCurrUpdateTime + 3600 * 24;
880 if ( !$iTimeToUpdate || $iTimeToUpdate > $iNextUpdateTime ) {
881 $iTimeToUpdate = $iNextUpdateTime;
884 $this->
getConfig()->saveShopConfVar(
"int",
"iTimeToUpdatePrices", $iTimeToUpdate );
886 return $iTimeToUpdate;
905 $oDb->startTransaction();
907 $sCurrUpdateTime = date(
"Y-m-d H:i:s",
oxRegistry::get(
"oxUtilsDate")->getTime() );
910 $sQ =
"SELECT `oxid` FROM `oxarticles`
911 WHERE `oxupdatepricetime` > 0 AND `oxupdatepricetime` <= '{$sCurrUpdateTime}'";
912 $aUpdatedArticleIds = $oDb->getCol( $sQ,
false,
false );
916 `oxprice` = IF( `oxupdateprice` > 0, `oxupdateprice`, `oxprice` ),
917 `oxpricea` = IF( `oxupdatepricea` > 0, `oxupdatepricea`, `oxpricea` ),
918 `oxpriceb` = IF( `oxupdatepriceb` > 0, `oxupdatepriceb`, `oxpriceb` ),
919 `oxpricec` = IF( `oxupdatepricec` > 0, `oxupdatepricec`, `oxpricec` ),
920 `oxupdatepricetime` = 0,
922 `oxupdatepricea` = 0,
923 `oxupdatepriceb` = 0,
926 `oxupdatepricetime` > 0 AND
927 `oxupdatepricetime` <= '{$sCurrUpdateTime}'" ;
928 $blUpdated = $oDb->execute( sprintf( $sQ,
"`oxarticles`" ) );
932 if ( !$blForceUpdate ) {
936 $oDb->commitTransaction();
939 if ( is_array($aUpdatedArticleIds) ) {
940 foreach ($aUpdatedArticleIds as $sArticleId) {
941 $oArticle =
oxNew(
'oxarticle');
942 $oArticle->load($sArticleId);
943 $oArticle->onChange();
962 if ($rs !=
false && $rs->recordCount() > 0) {
964 $rs->fields = array_change_key_case($rs->fields, CASE_LOWER);
965 $this[$rs->fields[
'oxid']] = $rs->fields[
'oxid'];
981 $sO2CView = getViewName(
'oxobject2category' );
982 $sO2AView = getViewName(
'oxobject2attribute' );
988 foreach ( $aFilter as $sAttrId => $sValue ) {
993 $sValue = $oDb->quote( $sValue );
994 $sAttrId = $oDb->quote( $sAttrId );
996 $sFilter .=
"( oa.oxattrid = {$sAttrId} and oa.oxvalue = {$sValue} )";
1001 $sFilter =
"WHERE $sFilter ";
1004 $sFilterSelect =
"select oc.oxobjectid as oxobjectid, count(*) as cnt from ";
1005 $sFilterSelect.=
"(SELECT * FROM $sO2CView WHERE $sO2CView.oxcatnid = '$sCatId' GROUP BY $sO2CView.oxobjectid, $sO2CView.oxcatnid) as oc ";
1006 $sFilterSelect.=
"INNER JOIN $sO2AView as oa ON ( oa.oxobjectid = oc.oxobjectid ) ";
1007 return $sFilterSelect .
"{$sFilter} GROUP BY oa.oxobjectid HAVING cnt = $iCnt ";
1020 $sArticleTable = getViewName(
'oxarticles' );
1025 foreach ( $aIds as $aArt ) {
1033 $sFilterSql =
" and $sArticleTable.oxid in ( $sIds ) ";
1036 } elseif ( !(
current( $aFilter ) ==
'' &&
count( array_unique( $aFilter ) ) == 1 ) ) {
1037 $sFilterSql =
" and false ";
1054 $sArticleTable = getViewName(
'oxarticles' );
1055 $sO2CView = getViewName(
'oxobject2category' );
1060 if ( $this->_sCustomSorting ) {
1061 $sSorting =
" {$this->_sCustomSorting} , ";
1068 if ( $aSessionFilter && isset( $aSessionFilter[$sCatId][$iLang] ) ) {
1069 $sFilterSql = $this->
_getFilterSql($sCatId, $aSessionFilter[$sCatId][$iLang]);
1074 $sSelect =
"SELECT $sFields, $sArticleTable.oxtimestamp FROM $sO2CView as oc left join $sArticleTable
1075 ON $sArticleTable.oxid = oc.oxobjectid
1076 WHERE ".$this->getBaseObject()->getSqlActiveSnippet().
" and $sArticleTable.oxparentid = ''
1077 and oc.oxcatnid = ".$oDb->quote($sCatId).
" $sFilterSql ORDER BY $sSorting oc.oxpos, oc.oxobjectid ";
1092 $sArticleTable = getViewName(
'oxarticles' );
1093 $sO2CView = getViewName(
'oxobject2category' );
1100 if ( $aSessionFilter && isset( $aSessionFilter[$sCatId][$iLang] ) ) {
1101 $sFilterSql = $this->
_getFilterSql($sCatId, $aSessionFilter[$sCatId][$iLang]);
1106 $sSelect =
"SELECT COUNT(*) FROM $sO2CView as oc left join $sArticleTable
1107 ON $sArticleTable.oxid = oc.oxobjectid
1108 WHERE ".$this->getBaseObject()->getSqlActiveSnippet().
" and $sArticleTable.oxparentid = ''
1109 and oc.oxcatnid = ".$oDb->quote($sCatId).
" $sFilterSql ";
1124 if ( !$sSearchString || !str_replace(
' ',
'', $sSearchString ) ) {
1133 $aSearch = explode(
' ', $sSearchString);
1135 $sSearch =
' and ( ';
1139 if (
$myConfig->getConfigParam(
'blSearchUseAND' ) ) {
1140 $sSearchSep =
' and ';
1142 $sSearchSep =
' or ';
1145 $aSearchCols =
$myConfig->getConfigParam(
'aSearchCols' );
1147 foreach ( $aSearch as $sSearchString) {
1149 if ( !strlen( $sSearchString ) ) {
1154 $sSearch .= $sSearchSep;
1159 $sUml = $myUtilsString->prepareStrForSearch($sSearchString);
1160 foreach ( $aSearchCols as $sField ) {
1167 if ( $sField ==
'oxlongdesc' || $sField ==
'oxtags') {
1168 $sSearchTable = getViewName(
'oxartextends' );
1170 $sSearchTable = $sArticleTable;
1173 $sSearch .= $sSearchTable.
'.'.$sField.
' like '.$oDb->quote(
'%'.$sSearchString.
'%') .
' ';
1175 $sSearch .=
' or '.$sSearchTable.
'.'.$sField.
' like '.$oDb->quote(
'%'.$sUml.
'%');
1198 $sArticleTable = $oBaseObject->getViewName();
1199 $sSelectFields = $oBaseObject->getSelectFields();
1201 $sSelect =
"select {$sSelectFields} from {$sArticleTable} where oxvarminprice >= 0 ";
1202 $sSelect .= $dPriceTo ?
"and oxvarminprice <= " . (double)$dPriceTo .
" " :
" ";
1203 $sSelect .= $dPriceFrom ?
"and oxvarminprice >= " . (double)$dPriceFrom .
" " :
" ";
1205 $sSelect .=
" and ".$oBaseObject->getSqlActiveSnippet().
" and {$sArticleTable}.oxissearch = 1";
1207 if ( !$this->_sCustomSorting ) {
1208 $sSelect .=
" order by {$sArticleTable}.oxvarminprice asc , {$sArticleTable}.oxid";
1210 $sSelect .=
" order by {$this->_sCustomSorting}, {$sArticleTable}.oxid ";
1225 $sArticleTable = getViewName(
'oxarticles');
1227 $sFieldNames = $oBaseObject->getSelectFields();
1228 $sSelect =
"select $sFieldNames from $sArticleTable ";
1229 $sSelect .=
"where $sArticleTable.oxvendorid = ".oxDb::getDb()->quote($sVendorId).
" ";
1230 $sSelect .=
" and " . $oBaseObject->getSqlActiveSnippet() .
" and $sArticleTable.oxparentid = '' ";
1232 if ( $this->_sCustomSorting ) {
1233 $sSelect .=
" ORDER BY {$this->_sCustomSorting} ";
1248 $sArticleTable = getViewName(
'oxarticles');
1250 $sFieldNames = $oBaseObject->getSelectFields();
1251 $sSelect =
"select $sFieldNames from $sArticleTable ";
1252 $sSelect .=
"where $sArticleTable.oxmanufacturerid = ".oxDb::getDb()->quote($sManufacturerId).
" ";
1253 $sSelect .=
" and " . $oBaseObject->getSqlActiveSnippet() .
" and $sArticleTable.oxparentid = '' ";
1255 if ( $this->_sCustomSorting ) {
1256 $sSelect .=
" ORDER BY {$this->_sCustomSorting} ";
1273 if ( !$oConfig->getConfigParam(
"blUseCron" ) ) {
1274 $iTimeToUpdate = $oConfig->getConfigParam(
"iTimeToUpdatePrices" );
1275 if ( !$iTimeToUpdate || $iTimeToUpdate <=
oxRegistry::get(
"oxUtilsDate")->getTime() ) {