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;
450 $sArtView = getViewName(
'oxarticles');
451 $sPartial = substr($sSelect, strpos($sSelect,
' from '));
452 $sSelect =
"select distinct $sArtView.oxid $sPartial ";
471 $sArtView = getViewName(
'oxarticles');
472 $sSelect =
"select distinct $sArtView.*, oxobject2list.oxdesc from oxobject2list ";
473 $sSelect .=
"left join $sArtView on oxobject2list.oxobjectid = $sArtView.oxid ";
474 $sSelect .=
"where (oxobject2list.oxlistid = $sRecommId) " . $sArticlesFilter;
487 public function loadSearchIds($sSearchStr =
'', $sSearchCat =
'', $sSearchVendor =
'', $sSearchManufacturer =
'')
490 $sSearchCat = $sSearchCat ? $sSearchCat : null;
491 $sSearchVendor = $sSearchVendor ? $sSearchVendor : null;
492 $sSearchManufacturer = $sSearchManufacturer ? $sSearchManufacturer : null;
500 $sArticleTable = getViewName(
'oxarticles');
505 if (is_array($aSearchCols = $this->
getConfig()->getConfigParam(
'aSearchCols'))) {
507 if (in_array(
'oxlongdesc', $aSearchCols) || in_array(
'oxtags', $aSearchCols)) {
508 $sDescView = getViewName(
'oxartextends');
509 $sDescJoin =
" LEFT JOIN $sDescView ON {$sDescView}.oxid={$sArticleTable}.oxid ";
515 $sSelect =
"select $sArticleTable.oxid, $sArticleTable.oxtimestamp from $sArticleTable $sDescJoin where ";
519 $sO2CView = getViewName(
'oxobject2category');
520 $sSelect =
"select $sArticleTable.oxid from $sO2CView as oxobject2category, $sArticleTable $sDescJoin ";
521 $sSelect .=
"where oxobject2category.oxcatnid=" . $oDb->quote($sSearchCat) .
" and oxobject2category.oxobjectid=$sArticleTable.oxid and ";
524 $sSelect .=
" and $sArticleTable.oxparentid = '' and $sArticleTable.oxissearch = 1 ";
527 if ($sSearchVendor) {
528 $sSelect .=
" and $sArticleTable.oxvendorid = " . $oDb->quote($sSearchVendor) .
" ";
531 if ($sSearchManufacturer) {
532 $sSelect .=
" and $sArticleTable.oxmanufacturerid = " . $oDb->quote($sSearchManufacturer) .
" ";
536 if ($this->_sCustomSorting) {
537 $sSelect .=
" order by {$this->_sCustomSorting} ";
569 startProfile(
"loadPriceArticles");
571 stopProfile(
"loadPriceArticles");
574 return $this->
count();
577 return oxRegistry::get(
"oxUtilsCount")->getPriceCatArticleCount($oCategory->getId(), $dPriceFrom, $dPriceTo);
616 return oxRegistry::get(
"oxUtilsCount")->getVendorArticleCount($sVendorId);
633 return oxRegistry::get(
"oxUtilsCount")->getManufacturerArticleCount($sManufacturerId);
649 $sArticleTable = $oListObject->getViewName();
650 $sArticleFields = $oListObject->getSelectFields();
651 $sViewName = getViewName(
'oxartextends', $iLang);
653 $oTag =
oxNew(
'oxtag', $sTag);
654 $oTag->addUnderscores();
655 $sTag = $oTag->get();
657 $sQ =
"select {$sArticleFields} from {$sViewName} inner join {$sArticleTable} on " .
658 "{$sArticleTable}.oxid = {$sViewName}.oxid where {$sArticleTable}.oxparentid = '' AND match ( {$sViewName}.oxtags ) " .
659 "against( " .
oxDb::getDb()->quote(
"\"" . $sTag .
"\"") .
" IN BOOLEAN MODE )";
662 if (($sActiveSnippet = $oListObject->getSqlActiveSnippet())) {
663 $sQ .=
" and {$sActiveSnippet}";
666 if ($this->_sCustomSorting) {
668 if (strpos($sSort,
'.') ===
false) {
669 $sSort = $sArticleTable .
'.' . $sSort;
671 $sQ .=
" order by $sSort ";
677 return oxRegistry::get(
"oxUtilsCount")->getTagArticleCount($sTag, $iLang);
693 $sArticleTable = $oListObject->getViewName();
694 $sViewName = getViewName(
'oxartextends', $iLang);
696 $oTag =
oxNew(
'oxtag', $sTag);
697 $oTag->addUnderscores();
698 $sTag = $oTag->get();
700 $sQ =
"select {$sViewName}.oxid from {$sViewName} inner join {$sArticleTable} on " .
701 "{$sArticleTable}.oxid = {$sViewName}.oxid where {$sArticleTable}.oxparentid = '' and {$sArticleTable}.oxissearch = 1 and " .
702 "match ( {$sViewName}.oxtags ) " .
703 "against( " .
oxDb::getDb()->quote(
"\"" . $sTag .
"\"") .
" IN BOOLEAN MODE )";
706 if (($sActiveSnippet = $oListObject->getSqlActiveSnippet())) {
707 $sQ .=
" and {$sActiveSnippet}";
710 if ($this->_sCustomSorting) {
712 if (strpos($sSort,
'.') ===
false) {
713 $sSort = $sArticleTable .
'.' . $sSort;
715 $sQ .=
" order by $sSort ";
736 foreach ($aIds as $iKey => $sVal) {
741 $sArticleTable = $oBaseObject->getViewName();
742 $sArticleFields = $oBaseObject->getSelectFields();
744 $sSelect =
"select $sArticleFields from $sArticleTable ";
745 $sSelect .=
"where $sArticleTable.oxid in ( '" . implode(
"','", $aIds) .
"' ) and ";
746 $sSelect .= $oBaseObject->getSqlActiveSnippet();
760 if (!
count($aOrders)) {
766 foreach ($aOrders as $iKey => $oOrder) {
767 $aOrdersIds[] = $oOrder->getId();
771 $sArticleTable = $oBaseObject->getViewName();
772 $sArticleFields = $oBaseObject->getSelectFields();
773 $sArticleFields = str_replace(
"`$sArticleTable`.`oxid`",
"`oxorderarticles`.`oxartid` AS `oxid`", $sArticleFields);
775 $sSelect =
"SELECT $sArticleFields FROM oxorderarticles ";
776 $sSelect .=
"left join $sArticleTable on oxorderarticles.oxartid = $sArticleTable.oxid ";
777 $sSelect .=
"WHERE oxorderarticles.oxorderid IN ( '" . implode(
"','", $aOrdersIds) .
"' ) ";
778 $sSelect .=
"order by $sArticleTable.oxid ";
783 $sNow = date(
'Y-m-d H:i:s');
784 foreach ($this as $oArticle) {
785 if (!$oArticle->oxarticles__oxactive->value &&
786 ($oArticle->oxarticles__oxactivefrom->value > $sNow ||
787 $oArticle->oxarticles__oxactiveto->value < $sNow
790 $oArticle->setBuyableState(
false);
802 if (is_array($aBasketContents) &&
count($aBasketContents)) {
804 foreach ($aBasketContents as $oBasketItem) {
805 $aArtIds[] = $oDb->quote($oBasketItem->getProductId());
810 $sFieldNames = $oBaseObject->getSelectFields();
811 $sTable = $oBaseObject->getViewName();
814 $sQ =
"select {$sFieldNames} from {$sTable} where {$sTable}.oxid in ( " . implode(
",", $aArtIds) .
" ) and
815 oxremindactive = '1' and oxstock <= oxremindamount";
819 if ($this->
count()) {
820 $sQ =
"update {$sTable} set oxremindactive = '2' where {$sTable}.oxid in ( " . implode(
",", $aArtIds) .
" ) and
821 oxremindactive = '1' and oxstock <= oxremindamount";
837 $sQ =
"select unix_timestamp( oxupdatepricetime ) from %s where oxupdatepricetime > 0 order by oxupdatepricetime asc";
838 $iTimeToUpdate = $oDb->getOne(sprintf($sQ,
"`oxarticles`"),
false,
false);
843 $iNextUpdateTime = $iCurrUpdateTime + 3600 * 24;
846 if (!$iTimeToUpdate || $iTimeToUpdate > $iNextUpdateTime) {
847 $iTimeToUpdate = $iNextUpdateTime;
850 $this->
getConfig()->saveShopConfVar(
"num",
"iTimeToUpdatePrices", $iTimeToUpdate);
852 return $iTimeToUpdate;
871 $oDb->startTransaction();
873 $sCurrUpdateTime = date(
"Y-m-d H:i:s",
oxRegistry::get(
"oxUtilsDate")->getTime());
876 $sQ =
"SELECT `oxid` FROM `oxarticles`
877 WHERE `oxupdatepricetime` > 0 AND `oxupdatepricetime` <= '{$sCurrUpdateTime}'";
878 $aUpdatedArticleIds = $oDb->getCol($sQ,
false,
false);
882 `oxprice` = IF( `oxupdateprice` > 0, `oxupdateprice`, `oxprice` ),
883 `oxpricea` = IF( `oxupdatepricea` > 0, `oxupdatepricea`, `oxpricea` ),
884 `oxpriceb` = IF( `oxupdatepriceb` > 0, `oxupdatepriceb`, `oxpriceb` ),
885 `oxpricec` = IF( `oxupdatepricec` > 0, `oxupdatepricec`, `oxpricec` ),
886 `oxupdatepricetime` = 0,
888 `oxupdatepricea` = 0,
889 `oxupdatepriceb` = 0,
892 `oxupdatepricetime` > 0 AND
893 `oxupdatepricetime` <= '{$sCurrUpdateTime}'";
894 $blUpdated = $oDb->execute(sprintf($sQ,
"`oxarticles`"));
898 if (!$blForceUpdate) {
902 $oDb->commitTransaction();
905 if (is_array($aUpdatedArticleIds)) {
906 foreach ($aUpdatedArticleIds as $sArticleId) {
907 $oArticle =
oxNew(
'oxarticle');
908 $oArticle->load($sArticleId);
909 $oArticle->onChange();
926 if ($rs !=
false && $rs->recordCount() > 0) {
928 $rs->fields = array_change_key_case($rs->fields, CASE_LOWER);
929 $this[$rs->fields[
'oxid']] = $rs->fields[
'oxid'];
945 $sO2CView = getViewName(
'oxobject2category');
946 $sO2AView = getViewName(
'oxobject2attribute');
952 foreach ($aFilter as $sAttrId => $sValue) {
957 $sValue = $oDb->quote($sValue);
958 $sAttrId = $oDb->quote($sAttrId);
960 $sFilter .=
"( oa.oxattrid = {$sAttrId} and oa.oxvalue = {$sValue} )";
965 $sFilter =
"WHERE $sFilter ";
968 $sFilterSelect =
"select oc.oxobjectid as oxobjectid, count(*) as cnt from ";
969 $sFilterSelect .=
"(SELECT * FROM $sO2CView WHERE $sO2CView.oxcatnid = '$sCatId' GROUP BY $sO2CView.oxobjectid, $sO2CView.oxcatnid) as oc ";
970 $sFilterSelect .=
"INNER JOIN $sO2AView as oa ON ( oa.oxobjectid = oc.oxobjectid ) ";
972 return $sFilterSelect .
"{$sFilter} GROUP BY oa.oxobjectid HAVING cnt = $iCnt ";
985 $sArticleTable = getViewName(
'oxarticles');
990 foreach ($aIds as $aArt) {
998 $sFilterSql =
" and $sArticleTable.oxid in ( $sIds ) ";
1001 } elseif (!(
current($aFilter) ==
'' &&
count(array_unique($aFilter)) == 1)) {
1002 $sFilterSql =
" and false ";
1019 $sArticleTable = getViewName(
'oxarticles');
1020 $sO2CView = getViewName(
'oxobject2category');
1025 if ($this->_sCustomSorting) {
1026 $sSorting =
" {$this->_sCustomSorting} , ";
1033 if ($aSessionFilter && isset($aSessionFilter[$sCatId][$iLang])) {
1034 $sFilterSql = $this->
_getFilterSql($sCatId, $aSessionFilter[$sCatId][$iLang]);
1039 $sSelect =
"SELECT $sFields, $sArticleTable.oxtimestamp FROM $sO2CView as oc left join $sArticleTable
1040 ON $sArticleTable.oxid = oc.oxobjectid
1041 WHERE " . $this->
getBaseObject()->getSqlActiveSnippet() .
" and $sArticleTable.oxparentid = ''
1042 and oc.oxcatnid = " . $oDb->quote($sCatId) .
" $sFilterSql ORDER BY $sSorting oc.oxpos, oc.oxobjectid ";
1057 $sArticleTable = getViewName(
'oxarticles');
1058 $sO2CView = getViewName(
'oxobject2category');
1065 if ($aSessionFilter && isset($aSessionFilter[$sCatId][$iLang])) {
1066 $sFilterSql = $this->
_getFilterSql($sCatId, $aSessionFilter[$sCatId][$iLang]);
1071 $sSelect =
"SELECT COUNT(*) FROM $sO2CView as oc left join $sArticleTable
1072 ON $sArticleTable.oxid = oc.oxobjectid
1073 WHERE " . $this->
getBaseObject()->getSqlActiveSnippet() .
" and $sArticleTable.oxparentid = ''
1074 and oc.oxcatnid = " . $oDb->quote($sCatId) .
" $sFilterSql ";
1089 if (!$sSearchString || !str_replace(
' ',
'', $sSearchString)) {
1098 $aSearch = explode(
' ', $sSearchString);
1100 $sSearch =
' and ( ';
1104 if (
$myConfig->getConfigParam(
'blSearchUseAND')) {
1105 $sSearchSep =
' and ';
1107 $sSearchSep =
' or ';
1110 $aSearchCols =
$myConfig->getConfigParam(
'aSearchCols');
1113 foreach ($aSearch as $sSearchString) {
1115 if (!strlen($sSearchString)) {
1120 $sSearch .= $sSearchSep;
1125 $sUml = $myUtilsString->prepareStrForSearch($sSearchString);
1126 foreach ($aSearchCols as $sField) {
1134 if ($sField ==
'oxlongdesc' || $sField ==
'oxtags') {
1135 $sSearchTable = getViewName(
'oxartextends');
1137 $sSearchTable = $sArticleTable;
1141 $sSearch .= $sSearchTable .
'.' . $sField .
' like ' . $oDb->quote(
'%' . $sSearchString .
'%') .
' ';
1143 $sSearch .=
' or ' . $sSearchTable .
'.' . $sField .
' like ' . $oDb->quote(
'%' . $sUml .
'%');
1166 $sArticleTable = $oBaseObject->getViewName();
1167 $sSelectFields = $oBaseObject->getSelectFields();
1171 $sSelect =
"select {$sSelectFields} from {$sArticleTable} where oxvarminprice >= 0 ";
1172 $sSelect .= $dPriceTo ?
"and oxvarminprice <= " . (double) $dPriceTo .
" " :
" ";
1173 $sSelect .= $dPriceFrom ?
"and oxvarminprice >= " . (double) $dPriceFrom .
" " :
" ";
1175 $sSelect .=
" and " . $oBaseObject->getSqlActiveSnippet() .
" and {$sArticleTable}.oxissearch = 1";
1177 if (!$this->_sCustomSorting) {
1178 $sSelect .=
" order by {$sArticleTable}.oxvarminprice asc , {$sArticleTable}.oxid";
1180 $sSelect .=
" order by {$this->_sCustomSorting}, {$sArticleTable}.oxid ";
1195 $sArticleTable = getViewName(
'oxarticles');
1197 $sFieldNames = $oBaseObject->getSelectFields();
1198 $sSelect =
"select $sFieldNames from $sArticleTable ";
1199 $sSelect .=
"where $sArticleTable.oxvendorid = " .
oxDb::getDb()->quote($sVendorId) .
" ";
1200 $sSelect .=
" and " . $oBaseObject->getSqlActiveSnippet() .
" and $sArticleTable.oxparentid = '' ";
1202 if ($this->_sCustomSorting) {
1203 $sSelect .=
" ORDER BY {$this->_sCustomSorting} ";
1218 $sArticleTable = getViewName(
'oxarticles');
1220 $sFieldNames = $oBaseObject->getSelectFields();
1221 $sSelect =
"select $sFieldNames from $sArticleTable ";
1222 $sSelect .=
"where $sArticleTable.oxmanufacturerid = " .
oxDb::getDb()->quote($sManufacturerId) .
" ";
1223 $sSelect .=
" and " . $oBaseObject->getSqlActiveSnippet() .
" and $sArticleTable.oxparentid = '' ";
1225 if ($this->_sCustomSorting) {
1226 $sSelect .=
" ORDER BY {$this->_sCustomSorting} ";
1243 if (!$oConfig->getConfigParam(
"blUseCron")) {
1244 $iTimeToUpdate = $oConfig->getConfigParam(
"iTimeToUpdatePrices");
1245 if (!$iTimeToUpdate || $iTimeToUpdate <=
oxRegistry::get(
"oxUtilsDate")->getTime()) {