37 $this->_sCustomSorting = $sSorting;
45 $this->_blLoadSelectLists =
true;
58 startProfile(
"loadinglists");
60 stopProfile(
"loadinglists");
72 if ($aArticlesIds = $this->
getSession()->getVariable(
'aHistoryArticles')) {
74 } elseif ($sArticlesIds =
oxRegistry::get(
"oxUtilsServer")->getOxCookie(
'aHistoryArticles')) {
75 return explode(
'|', $sArticlesIds);
91 oxRegistry::get(
"oxUtilsServer")->setOxCookie(
'aHistoryArticles', implode(
'|', $aArticlesIds));
105 $aHistoryArticles[] = $sArtId;
108 $aHistoryArticles = array_unique($aHistoryArticles);
109 if (
count($aHistoryArticles) > ($iCnt + 1)) {
110 array_shift($aHistoryArticles);
117 if (($iCurrentArt = array_search($sArtId, $aHistoryArticles)) !==
false) {
118 unset($aHistoryArticles[$iCurrentArt]);
121 $aHistoryArticles = array_values($aHistoryArticles);
122 $this->
loadIds($aHistoryArticles);
133 $this->_aOrderMap = array_flip($aIds);
134 uksort($this->_aArray, array($this,
'_sortByOrderMapCallback'));
149 if (isset($this->_aOrderMap[$key1])) {
150 if (isset($this->_aOrderMap[$key2])) {
151 $iDiff = $this->_aOrderMap[$key2] - $this->_aOrderMap[$key1];
154 } elseif ($iDiff < 0) {
163 } elseif (isset($this->_aOrderMap[$key2])) {
182 if (!
$myConfig->getConfigParam(
'bl_perfLoadPriceForAddList')) {
186 $this->_aArray = array();
187 switch (
$myConfig->getConfigParam(
'iNewestArticlesMode')) {
196 $sArticleTable = getViewName(
'oxarticles');
197 if (
$myConfig->getConfigParam(
'blNewArtByInsert')) {
200 $sType =
'oxtimestamp';
202 $sSelect =
"select * from $sArticleTable ";
203 $sSelect .=
"where oxparentid = '' and " . $this->
getBaseObject()->getSqlActiveSnippet() .
" and oxissearch = 1 order by $sType desc ";
204 if (!($iLimit = (
int) $iLimit)) {
205 $iLimit =
$myConfig->getConfigParam(
'iNrofNewcomerArticles');
207 $sSelect .=
"limit " . $iLimit;
225 if (!
$myConfig->getConfigParam(
'bl_perfLoadPriceForAddList')) {
229 switch (
$myConfig->getConfigParam(
'iTop5Mode')) {
238 $sArticleTable = getViewName(
'oxarticles');
241 $sLimit = ($iLimit > 0) ?
"limit " . $iLimit :
'limit 5';
243 $sSelect =
"select * from $sArticleTable ";
244 $sSelect .=
"where " . $this->
getBaseObject()->getSqlActiveSnippet() .
" and $sArticleTable.oxissearch = 1 ";
245 $sSelect .=
"and $sArticleTable.oxparentid = '' and $sArticleTable.oxsoldamount>0 ";
246 $sSelect .=
"order by $sArticleTable.oxsoldamount desc $sLimit";
264 if (!trim($sActionID)) {
268 $sShopID = $this->
getConfig()->getShopId();
269 $sActionID =
oxDb::getDb()->quote(strtolower($sActionID));
273 $sArticleTable = $oBaseObject->getViewName();
274 $sArticleFields = $oBaseObject->getSelectFields();
276 $oBase =
oxNew(
"oxactions");
277 $sActiveSql = $oBase->getSqlActiveSnippet();
278 $sViewName = $oBase->getViewName();
280 $sLimit = ($iLimit > 0) ?
"limit " . $iLimit :
'';
282 $sSelect =
"select $sArticleFields from oxactions2article
283 left join $sArticleTable on $sArticleTable.oxid = oxactions2article.oxartid
284 left join $sViewName on $sViewName.oxid = oxactions2article.oxactionid
285 where oxactions2article.oxshopid = '$sShopID' and oxactions2article.oxactionid = $sActionID and $sActiveSql
286 and $sArticleTable.oxid is not null and " . $oBaseObject->getSqlActiveSnippet() .
"
287 order by oxactions2article.oxsort $sLimit";
304 if (!
$myConfig->getConfigParam(
'bl_perfLoadCrossselling')) {
309 $sArticleTable = $oBaseObject->getViewName();
313 $sSelect =
"SELECT $sArticleTable.*
314 FROM $sArticleTable INNER JOIN oxobject2article ON oxobject2article.oxobjectid=$sArticleTable.oxid ";
315 $sSelect .=
"WHERE oxobject2article.oxarticlenid = $sArticleId ";
316 $sSelect .=
" AND " . $oBaseObject->getSqlActiveSnippet();
319 if (
$myConfig->getConfigParam(
'blBidirectCross')) {
322 SELECT $sArticleTable.* FROM $sArticleTable
323 INNER JOIN oxobject2article AS O2A1 on
324 ( O2A1.oxobjectid = $sArticleTable.oxid AND O2A1.oxarticlenid = $sArticleId )
326 AND " . $oBaseObject->getSqlActiveSnippet() .
"
327 AND ($sArticleTable.oxid != $sArticleId)
331 SELECT $sArticleTable.* FROM $sArticleTable
332 INNER JOIN oxobject2article AS O2A2 ON
333 ( O2A2.oxarticlenid = $sArticleTable.oxid AND O2A2.oxobjectid = $sArticleId )
335 AND " . $oBaseObject->getSqlActiveSnippet() .
"
336 AND ($sArticleTable.oxid != $sArticleId)
356 if (!
$myConfig->getConfigParam(
'bl_perfLoadAccessoires')) {
363 $sArticleTable = $oBaseObject->getViewName();
365 $sSelect =
"select $sArticleTable.* from oxaccessoire2article left join $sArticleTable on oxaccessoire2article.oxobjectid=$sArticleTable.oxid ";
366 $sSelect .=
"where oxaccessoire2article.oxarticlenid = $sArticleId ";
367 $sSelect .=
" and $sArticleTable.oxid is not null and " . $oBaseObject->getSqlActiveSnippet();
369 $sSelect .=
" order by oxaccessoire2article.oxsort";
383 $sSelect = $this->
_getCategorySelect($sArticleTable .
'.oxid as oxid', $sCatId, $aSessionFilter);
405 $iArticleCount = null;
406 if ($aSessionFilter) {
410 if ($iLimit = (
int) $iLimit) {
411 $sSelect .=
" LIMIT $iLimit";
416 if ($iArticleCount !== null) {
417 return $iArticleCount;
446 $sArtView = getViewName(
'oxarticles');
447 $sPartial = substr($sSelect, strpos($sSelect,
' from '));
448 $sSelect =
"select distinct $sArtView.oxid $sPartial ";
465 $sArtView = getViewName(
'oxarticles');
466 $sSelect =
"select distinct $sArtView.*, oxobject2list.oxdesc from oxobject2list ";
467 $sSelect .=
"left join $sArtView on oxobject2list.oxobjectid = $sArtView.oxid ";
468 $sSelect .=
"where (oxobject2list.oxlistid = $sRecommId) " . $sArticlesFilter;
481 public function loadSearchIds($sSearchStr =
'', $sSearchCat =
'', $sSearchVendor =
'', $sSearchManufacturer =
'')
484 $sSearchCat = $sSearchCat ? $sSearchCat : null;
485 $sSearchVendor = $sSearchVendor ? $sSearchVendor : null;
486 $sSearchManufacturer = $sSearchManufacturer ? $sSearchManufacturer : null;
494 $sArticleTable = getViewName(
'oxarticles');
499 if (is_array($aSearchCols = $this->
getConfig()->getConfigParam(
'aSearchCols'))) {
500 if (in_array(
'oxlongdesc', $aSearchCols) || in_array(
'oxtags', $aSearchCols)) {
501 $sDescView = getViewName(
'oxartextends');
502 $sDescJoin =
" LEFT JOIN $sDescView ON {$sDescView}.oxid={$sArticleTable}.oxid ";
507 $sSelect =
"select $sArticleTable.oxid, $sArticleTable.oxtimestamp from $sArticleTable $sDescJoin where ";
511 $sO2CView = getViewName(
'oxobject2category');
512 $sSelect =
"select $sArticleTable.oxid from $sO2CView as oxobject2category, $sArticleTable $sDescJoin ";
513 $sSelect .=
"where oxobject2category.oxcatnid=" . $oDb->quote($sSearchCat) .
" and oxobject2category.oxobjectid=$sArticleTable.oxid and ";
516 $sSelect .=
" and $sArticleTable.oxparentid = '' and $sArticleTable.oxissearch = 1 ";
519 if ($sSearchVendor) {
520 $sSelect .=
" and $sArticleTable.oxvendorid = " . $oDb->quote($sSearchVendor) .
" ";
523 if ($sSearchManufacturer) {
524 $sSelect .=
" and $sArticleTable.oxmanufacturerid = " . $oDb->quote($sSearchManufacturer) .
" ";
528 if ($this->_sCustomSorting) {
529 $sSelect .=
" order by {$this->_sCustomSorting} ";
561 startProfile(
"loadPriceArticles");
563 stopProfile(
"loadPriceArticles");
566 return $this->
count();
569 return oxRegistry::get(
"oxUtilsCount")->getPriceCatArticleCount($oCategory->getId(), $dPriceFrom, $dPriceTo);
608 return oxRegistry::get(
"oxUtilsCount")->getVendorArticleCount($sVendorId);
625 return oxRegistry::get(
"oxUtilsCount")->getManufacturerArticleCount($sManufacturerId);
639 $sArticleTable = $oListObject->getViewName();
640 $sArticleFields = $oListObject->getSelectFields();
641 $sViewName = getViewName(
'oxartextends', $iLang);
643 $oTag =
oxNew(
'oxtag', $sTag);
644 $oTag->addUnderscores();
645 $sTag = $oTag->get();
647 $sQ =
"select {$sArticleFields} from {$sViewName} inner join {$sArticleTable} on " .
648 "{$sArticleTable}.oxid = {$sViewName}.oxid where {$sArticleTable}.oxparentid = '' AND match ( {$sViewName}.oxtags ) " .
649 "against( " .
oxDb::getDb()->quote(
"\"" . $sTag .
"\"") .
" IN BOOLEAN MODE )";
652 if (($sActiveSnippet = $oListObject->getSqlActiveSnippet())) {
653 $sQ .=
" and {$sActiveSnippet}";
656 if ($this->_sCustomSorting) {
658 if (strpos($sSort,
'.') ===
false) {
659 $sSort = $sArticleTable .
'.' . $sSort;
661 $sQ .=
" order by $sSort ";
667 return oxRegistry::get(
"oxUtilsCount")->getTagArticleCount($sTag, $iLang);
681 $sArticleTable = $oListObject->getViewName();
682 $sViewName = getViewName(
'oxartextends', $iLang);
684 $oTag =
oxNew(
'oxtag', $sTag);
685 $oTag->addUnderscores();
686 $sTag = $oTag->get();
688 $sQ =
"select {$sViewName}.oxid from {$sViewName} inner join {$sArticleTable} on " .
689 "{$sArticleTable}.oxid = {$sViewName}.oxid where {$sArticleTable}.oxparentid = '' and {$sArticleTable}.oxissearch = 1 and " .
690 "match ( {$sViewName}.oxtags ) " .
691 "against( " .
oxDb::getDb()->quote(
"\"" . $sTag .
"\"") .
" IN BOOLEAN MODE )";
694 if (($sActiveSnippet = $oListObject->getSqlActiveSnippet())) {
695 $sQ .=
" and {$sActiveSnippet}";
698 if ($this->_sCustomSorting) {
700 if (strpos($sSort,
'.') ===
false) {
701 $sSort = $sArticleTable .
'.' . $sSort;
703 $sQ .=
" order by $sSort ";
724 foreach ($aIds as $iKey => $sVal) {
729 $sArticleTable = $oBaseObject->getViewName();
730 $sArticleFields = $oBaseObject->getSelectFields();
732 $sSelect =
"select $sArticleFields from $sArticleTable ";
733 $sSelect .=
"where $sArticleTable.oxid in ( '" . implode(
"','", $aIds) .
"' ) and ";
734 $sSelect .= $oBaseObject->getSqlActiveSnippet();
748 if (!
count($aOrders)) {
754 foreach ($aOrders as $iKey => $oOrder) {
755 $aOrdersIds[] = $oOrder->getId();
759 $sArticleTable = $oBaseObject->getViewName();
760 $sArticleFields = $oBaseObject->getSelectFields();
761 $sArticleFields = str_replace(
"`$sArticleTable`.`oxid`",
"`oxorderarticles`.`oxartid` AS `oxid`", $sArticleFields);
763 $sSelect =
"SELECT $sArticleFields FROM oxorderarticles ";
764 $sSelect .=
"left join $sArticleTable on oxorderarticles.oxartid = $sArticleTable.oxid ";
765 $sSelect .=
"WHERE oxorderarticles.oxorderid IN ( '" . implode(
"','", $aOrdersIds) .
"' ) ";
766 $sSelect .=
"order by $sArticleTable.oxid ";
771 $sNow = date(
'Y-m-d H:i:s');
772 foreach ($this as $oArticle) {
773 if (!$oArticle->oxarticles__oxactive->value &&
774 ($oArticle->oxarticles__oxactivefrom->value > $sNow ||
775 $oArticle->oxarticles__oxactiveto->value < $sNow
778 $oArticle->setBuyableState(
false);
790 if (is_array($aBasketContents) &&
count($aBasketContents)) {
792 foreach ($aBasketContents as $oBasketItem) {
793 $aArtIds[] = $oDb->quote($oBasketItem->getProductId());
798 $sFieldNames = $oBaseObject->getSelectFields();
799 $sTable = $oBaseObject->getViewName();
802 $sQ =
"select {$sFieldNames} from {$sTable} where {$sTable}.oxid in ( " . implode(
",", $aArtIds) .
" ) and
803 oxremindactive = '1' and oxstock <= oxremindamount";
807 if ($this->
count()) {
808 $sQ =
"update {$sTable} set oxremindactive = '2' where {$sTable}.oxid in ( " . implode(
",", $aArtIds) .
" ) and
809 oxremindactive = '1' and oxstock <= oxremindamount";
825 $sQ =
"select unix_timestamp( oxupdatepricetime ) from %s where oxupdatepricetime > 0 order by oxupdatepricetime asc";
826 $iTimeToUpdate = $oDb->getOne(sprintf($sQ,
"`oxarticles`"),
false,
false);
831 $iNextUpdateTime = $iCurrUpdateTime + 3600 * 24;
834 if (!$iTimeToUpdate || $iTimeToUpdate > $iNextUpdateTime) {
835 $iTimeToUpdate = $iNextUpdateTime;
838 $this->
getConfig()->saveShopConfVar(
"num",
"iTimeToUpdatePrices", $iTimeToUpdate);
840 return $iTimeToUpdate;
859 $oDb->startTransaction();
861 $sCurrUpdateTime = date(
"Y-m-d H:i:s",
oxRegistry::get(
"oxUtilsDate")->getTime());
864 $sQ =
"SELECT `oxid` FROM `oxarticles`
865 WHERE `oxupdatepricetime` > 0 AND `oxupdatepricetime` <= '{$sCurrUpdateTime}'";
866 $aUpdatedArticleIds = $oDb->getCol($sQ,
false,
false);
870 `oxprice` = IF( `oxupdateprice` > 0, `oxupdateprice`, `oxprice` ),
871 `oxpricea` = IF( `oxupdatepricea` > 0, `oxupdatepricea`, `oxpricea` ),
872 `oxpriceb` = IF( `oxupdatepriceb` > 0, `oxupdatepriceb`, `oxpriceb` ),
873 `oxpricec` = IF( `oxupdatepricec` > 0, `oxupdatepricec`, `oxpricec` ),
874 `oxupdatepricetime` = 0,
876 `oxupdatepricea` = 0,
877 `oxupdatepriceb` = 0,
880 `oxupdatepricetime` > 0 AND
881 `oxupdatepricetime` <= '{$sCurrUpdateTime}'";
882 $blUpdated = $oDb->execute(sprintf($sQ,
"`oxarticles`"));
886 if (!$blForceUpdate) {
890 $oDb->commitTransaction();
893 if (is_array($aUpdatedArticleIds)) {
894 foreach ($aUpdatedArticleIds as $sArticleId) {
895 $oArticle =
oxNew(
'oxarticle');
896 $oArticle->load($sArticleId);
897 $oArticle->onChange();
914 if ($rs !=
false && $rs->recordCount() > 0) {
916 $rs->fields = array_change_key_case($rs->fields, CASE_LOWER);
917 $this[$rs->fields[
'oxid']] = $rs->fields[
'oxid'];
933 $sO2CView = getViewName(
'oxobject2category');
934 $sO2AView = getViewName(
'oxobject2attribute');
940 foreach ($aFilter as $sAttrId => $sValue) {
945 $sValue = $oDb->quote($sValue);
946 $sAttrId = $oDb->quote($sAttrId);
948 $sFilter .=
"( oa.oxattrid = {$sAttrId} and oa.oxvalue = {$sValue} )";
953 $sFilter =
"WHERE $sFilter ";
956 $sFilterSelect =
"select oc.oxobjectid as oxobjectid, count(*) as cnt from ";
957 $sFilterSelect .=
"(SELECT * FROM $sO2CView WHERE $sO2CView.oxcatnid = '$sCatId' GROUP BY $sO2CView.oxobjectid, $sO2CView.oxcatnid) as oc ";
958 $sFilterSelect .=
"INNER JOIN $sO2AView as oa ON ( oa.oxobjectid = oc.oxobjectid ) ";
960 return $sFilterSelect .
"{$sFilter} GROUP BY oa.oxobjectid HAVING cnt = $iCnt ";
973 $sArticleTable = getViewName(
'oxarticles');
978 foreach ($aIds as $aArt) {
986 $sFilterSql =
" and $sArticleTable.oxid in ( $sIds ) ";
989 } elseif (!(
current($aFilter) ==
'' &&
count(array_unique($aFilter)) == 1)) {
990 $sFilterSql =
" and false ";
1007 $sArticleTable = getViewName(
'oxarticles');
1008 $sO2CView = getViewName(
'oxobject2category');
1013 if ($this->_sCustomSorting) {
1014 $sSorting =
" {$this->_sCustomSorting} , ";
1021 if ($aSessionFilter && isset($aSessionFilter[$sCatId][$iLang])) {
1022 $sFilterSql = $this->
_getFilterSql($sCatId, $aSessionFilter[$sCatId][$iLang]);
1027 $sSelect =
"SELECT $sFields, $sArticleTable.oxtimestamp FROM $sO2CView as oc left join $sArticleTable
1028 ON $sArticleTable.oxid = oc.oxobjectid
1029 WHERE " . $this->
getBaseObject()->getSqlActiveSnippet() .
" and $sArticleTable.oxparentid = ''
1030 and oc.oxcatnid = " . $oDb->quote($sCatId) .
" $sFilterSql ORDER BY $sSorting oc.oxpos, oc.oxobjectid ";
1045 $sArticleTable = getViewName(
'oxarticles');
1046 $sO2CView = getViewName(
'oxobject2category');
1053 if ($aSessionFilter && isset($aSessionFilter[$sCatId][$iLang])) {
1054 $sFilterSql = $this->
_getFilterSql($sCatId, $aSessionFilter[$sCatId][$iLang]);
1059 $sSelect =
"SELECT COUNT(*) FROM $sO2CView as oc left join $sArticleTable
1060 ON $sArticleTable.oxid = oc.oxobjectid
1061 WHERE " . $this->
getBaseObject()->getSqlActiveSnippet() .
" and $sArticleTable.oxparentid = ''
1062 and oc.oxcatnid = " . $oDb->quote($sCatId) .
" $sFilterSql ";
1077 if (!$sSearchString || !str_replace(
' ',
'', $sSearchString)) {
1086 $aSearch = explode(
' ', $sSearchString);
1088 $sSearch =
' and ( ';
1092 if (
$myConfig->getConfigParam(
'blSearchUseAND')) {
1093 $sSearchSep =
' and ';
1095 $sSearchSep =
' or ';
1098 $aSearchCols =
$myConfig->getConfigParam(
'aSearchCols');
1101 foreach ($aSearch as $sSearchString) {
1103 if (!strlen($sSearchString)) {
1108 $sSearch .= $sSearchSep;
1113 $sUml = $myUtilsString->prepareStrForSearch($sSearchString);
1114 foreach ($aSearchCols as $sField) {
1121 if ($sField ==
'oxlongdesc' || $sField ==
'oxtags') {
1122 $sSearchTable = getViewName(
'oxartextends');
1124 $sSearchTable = $sArticleTable;
1127 $sSearch .= $sSearchTable .
'.' . $sField .
' like ' . $oDb->quote(
'%' . $sSearchString .
'%') .
' ';
1129 $sSearch .=
' or ' . $sSearchTable .
'.' . $sField .
' like ' . $oDb->quote(
'%' . $sUml .
'%');
1152 $sArticleTable = $oBaseObject->getViewName();
1153 $sSelectFields = $oBaseObject->getSelectFields();
1157 $sSelect =
"select {$sSelectFields} from {$sArticleTable} where oxvarminprice >= 0 ";
1158 $sSelect .= $dPriceTo ?
"and oxvarminprice <= " . (double) $dPriceTo .
" " :
" ";
1159 $sSelect .= $dPriceFrom ?
"and oxvarminprice >= " . (double) $dPriceFrom .
" " :
" ";
1161 $sSelect .=
" and " . $oBaseObject->getSqlActiveSnippet() .
" and {$sArticleTable}.oxissearch = 1";
1163 if (!$this->_sCustomSorting) {
1164 $sSelect .=
" order by {$sArticleTable}.oxvarminprice asc , {$sArticleTable}.oxid";
1166 $sSelect .=
" order by {$this->_sCustomSorting}, {$sArticleTable}.oxid ";
1181 $sArticleTable = getViewName(
'oxarticles');
1183 $sFieldNames = $oBaseObject->getSelectFields();
1184 $sSelect =
"select $sFieldNames from $sArticleTable ";
1185 $sSelect .=
"where $sArticleTable.oxvendorid = " .
oxDb::getDb()->quote($sVendorId) .
" ";
1186 $sSelect .=
" and " . $oBaseObject->getSqlActiveSnippet() .
" and $sArticleTable.oxparentid = '' ";
1188 if ($this->_sCustomSorting) {
1189 $sSelect .=
" ORDER BY {$this->_sCustomSorting} ";
1204 $sArticleTable = getViewName(
'oxarticles');
1206 $sFieldNames = $oBaseObject->getSelectFields();
1207 $sSelect =
"select $sFieldNames from $sArticleTable ";
1208 $sSelect .=
"where $sArticleTable.oxmanufacturerid = " .
oxDb::getDb()->quote($sManufacturerId) .
" ";
1209 $sSelect .=
" and " . $oBaseObject->getSqlActiveSnippet() .
" and $sArticleTable.oxparentid = '' ";
1211 if ($this->_sCustomSorting) {
1212 $sSelect .=
" ORDER BY {$this->_sCustomSorting} ";
1229 if (!$oConfig->getConfigParam(
"blUseCron")) {
1230 $iTimeToUpdate = $oConfig->getConfigParam(
"iTimeToUpdatePrices");
1231 if (!$iTimeToUpdate || $iTimeToUpdate <=
oxRegistry::get(
"oxUtilsDate")->getTime()) {