$arFilter["DATE_FROM"] = ConvertTimeStamp(AddToTimeStamp(array("DD" => "-" . $dateBack), mktime(0, 0, 0, date("n"), date("j"), date("Y"))), "SHORT"); } CAdminMessage::ShowNote($viewedMessage); CAdminMessage::ShowMessage($viewedError); $newFilter = array(); foreach ($arFilter as $key => $value) { if ($key == "DATE_FROM") { $newFilter['>=DATE_VISIT'] = $value; } elseif ($key == "DATE_TO") { $newFilter['<DATE_VISIT'] = $value; } else { $newFilter[$key] = $value; } } if (\Bitrix\Main\Loader::includeModule("catalog")) { $viewedQuery = new \Bitrix\Main\Entity\Query(\Bitrix\Catalog\CatalogViewedProductTable::getEntity()); $viewedQuery->setSelect(array("PRODUCT_ID", "DATE_VISIT", "SITE_ID", "VIEW_COUNT", "NAME" => "ELEMENT.NAME", "PRICE" => "PRODUCT.PRICE", "QUANTITY" => "PRODUCT.QUANTITY", "CURRENCY" => "PRODUCT.CURRENCY", "RATE" => "PRODUCT.CURRENT_CURRENCY_RATE", "CURRENCY_RATE" => "PRODUCT.CURRENT_CURRENCY_RATE_CNT"))->setfilter($newFilter); $viewedIterator = $viewedQuery->exec(); } else { $viewedIterator = new CDBResult(); } $dbViewsList = new CAdminResult($viewedIterator, $sTableID_tab5); $dbViewsList->NavStart(); $lAdmin_tab5->NavText($dbViewsList->GetNavPrint(GetMessage('BUYER_PRODUCT_LIST'))); $viewedHeader = array(array("id" => "DATE_VISIT", "content" => GetMessage("BUYER_V_DATE_INSERT"), "sort" => "DATE_VISIT", "default" => true), array("id" => "NAME", "content" => GetMessage("BUYER_V_NAME"), "sort" => "NAME", "default" => true), array("id" => "PRICE", "content" => GetMessage("BUYER_V_PRICE"), "sort" => "PRICE", "default" => true), array("id" => "QUANTITY", "content" => GetMessage("BUYER_V_QUANTITY"), "sort" => "", "default" => true)); if (count($arSites) > 1) { $viewedHeader[] = array("id" => "SITE_ID", "content" => GetMessage("BUYER_V_LID"), "sort" => "SITE_ID", "default" => true); } $lAdmin_tab5->AddHeaders($viewedHeader); $arProductId = array(); $arCatalogProductId = array();
while ($arR = $dbR->Fetch()) { $arResult["SEL"][] = $arR; } // VIEWED $arResult["VIEWED"] = array(); if (!Loader::includeModule("catalog")) { return; } $arFilter[">=DATE_VISIT"] = $arFilter[">=DATE_INSERT"]; unset($arFilter[">=DATE_INSERT"]); if (isset($arFilter['LID'])) { $arFilter['SITE_ID'] = $arFilter['LID']; unset($arFilter['LID']); } unset($arFilter['PAYED']); $viewedQuery = new Query(ViewedProducts::getEntity()); $viewedQuery->setSelect(array("PRODUCT_ID", "NAME" => "ELEMENT.NAME", "PRICE" => "PRODUCT.PRICE", "CURRENCY" => "PRODUCT.CURRENCY", "RATE" => "PRODUCT.CURRENT_CURRENCY_RATE", "CURRENCY_RATE" => "PRODUCT.CURRENT_CURRENCY_RATE_CNT"))->setfilter($arFilter); $viewedIterator = $viewedQuery->exec(); $viewedProducts = array(); while ($row = $viewedIterator->fetch()) { $row['VIEW_COUNT'] = 1; if ((int) $row['CURRENCY_RATE'] > 0) { $row['SORT_PRICE'] = $row['PRICE'] * $row['RATE'] / (int) $row['CURRENCY_RATE']; } else { $row['SORT_PRICE'] = $row['PRICE'] * $row['RATE']; } if (!isset($viewedProducts[$row['PRODUCT_ID']])) { $viewedProducts[$row['PRODUCT_ID']] = $row; } else { $viewedProducts[$row['PRODUCT_ID']]['VIEW_COUNT']++; if ($viewedProducts[$row['PRODUCT_ID']]['SORT_PRICE'] > $row['SORT_PRICE']) {