"PRODUCT_ID" => IntVal($_SESSION["VIEWED_PRODUCT"]), "MODULE" => "catalog", "LID" => SITE_ID ); CSaleViewedProduct::Add($arFields); } if (isset($_SESSION["VIEWED_ENABLE"]) && $_SESSION["VIEWED_ENABLE"] == "Y" && $_SESSION["VIEWED_PRODUCT"] != $arResult["ID"] && Loader::includeModule("sale")) { $arFields = array( "PRODUCT_ID" => $arResult["ID"], "MODULE" => "catalog", "LID" => SITE_ID, "IBLOCK_ID" => $arResult["IBLOCK_ID"] ); CSaleViewedProduct::Add($arFields); } $_SESSION["VIEWED_PRODUCT"] = $arResult["ID"]; $arTitleOptions = null; if($USER->IsAuthorized()) { if( $APPLICATION->GetShowIncludeAreas() || $arParams["SET_TITLE"] || isset($arResult[$arParams["BROWSER_TITLE"]]) ) { if (Loader::includeModule('iblock'))
} if (($action == "ADD2BASKET" || $action == "BUY") && $productID > 0) { if (CModule::IncludeModule('catalog')) { Add2BasketByProductID($productID, 1, array(), $product_properties); } if ($action == "BUY") { LocalRedirect($arParams["BASKET_URL"]); } else { LocalRedirect($APPLICATION->GetCurPageParam("", array($arParams["PRODUCT_ID_VARIABLE"], $arParams["ACTION_VARIABLE"]))); } } } //end add to basket $arViewed = array(); $arViewedId = array(); $db_res = CSaleViewedProduct::GetList(array("DATE_VISIT" => "DESC"), $arFilter, false, array("nTopCount" => $arParams["VIEWED_COUNT"]), array('ID', 'IBLOCK_ID', 'PRICE', 'CURRENCY', 'CAN_BUY', 'PRODUCT_ID', 'DATE_VISIT', 'DETAIL_PAGE_URL', 'DETAIL_PICTURE', 'PREVIEW_PICTURE', 'NAME', 'NOTES')); while ($arItems = $db_res->Fetch()) { $arViewedId[] = $arItems["PRODUCT_ID"]; $arViewed[$arItems["PRODUCT_ID"]] = $arItems; } $arElementSort = array(); //check catalog if (count($arViewedId) > 0 && CModule::IncludeModule("iblock") && CModule::IncludeModule("catalog")) { $res = CIBlockElement::GetList(array(), array("ID" => $arViewedId), false, false, array('ID', 'IBLOCK_ID', 'IBLOCK_SECTION_ID')); while ($arElements = $res->Fetch()) { $arElements["DATE_VISIT"] = $arViewed[$arElements["ID"]]["DATE_VISIT"]; $arElementSort[] = $arElements; } usort($arElementSort, "arraySort"); foreach ($arElementSort as $arElements) { static $arCacheOffersIblock = array();
/** * The agent function delete old viewed * * @param * @return true false */ public function ClearViewed() { CSaleViewedProduct::_ClearViewed(); return "CSaleViewedProduct::ClearViewed();"; }
<?php $displayNone = "block"; $displayNoneBasket = "block"; $displayNoneViewed = "block"; $arRecomendet = CSaleProduct::GetRecommendetProduct($str_USER_ID, $LID, $arFilterRecomendet); $arRecomendetResult = fDeleteDoubleProduct($arRecomendet, $arFilterRecomendet, 'N'); if (count($arRecomendetResult["ITEMS"]) <= 0) { $displayNone = "none"; } $arShoppingCart = CSaleBasket::DoGetUserShoppingCart($LID, $str_USER_ID, $FUSER_ID, $arErrors, $arCupon); $arShoppingCart = fDeleteDoubleProduct($arShoppingCart, $arFilterRecomendet, 'N'); if (count($arShoppingCart["ITEMS"]) <= 0) { $displayNoneBasket = "none"; } $arViewed = array(); $dbViewsList = CSaleViewedProduct::GetList(array("DATE_VISIT" => "DESC"), array("FUSER_ID" => $arFuserItems["ID"], ">PRICE" => 0, "!CURRENCY" => "", "LID" => $str_LID), false, array('nTopCount' => 10), array('ID', 'PRODUCT_ID', 'LID', 'MODULE', 'NAME', 'DETAIL_PAGE_URL', 'PRICE', 'CURRENCY', 'PREVIEW_PICTURE', 'DETAIL_PICTURE')); while ($arViews = $dbViewsList->Fetch()) { $arViewed[] = $arViews; } $arViewedResult = fDeleteDoubleProduct($arViewed, $arFilterRecomendet, 'N'); if (count($arViewedResult["ITEMS"]) <= 0) { $displayNoneViewed = "none"; } $tabBasket = "tabs"; $tabViewed = "tabs"; if ($displayNoneBasket == 'none' && $displayNone == 'none' && $displayNoneViewed == 'block') { $tabViewed .= " active"; } if ($displayNoneBasket == 'block' && $displayNone == 'none') { $tabBasket .= " active"; }
/** * The function add viewed product * * @param array $arFields - params for add * @return true false */ public static function Add($arFields) { global $DB; global $USER; global $APPLICATION; foreach (GetModuleEvents("sale", "OnBeforeViewedAdd", true) as $arEvent) { if (ExecuteModuleEventEx($arEvent, array(&$arFields)) === false) { return false; } } if (isset($arFields["ID"])) { unset($arFields["ID"]); } $arFields["PRODUCT_ID"] = IntVal($arFields["PRODUCT_ID"]); $arFields["USER_ID"] = IntVal($arFields["USER_ID"]); $arFields["FUSER_ID"] = IntVal($arFields["FUSER_ID"]); $arFields["IBLOCK_ID"] = IntVal($arFields["IBLOCK_ID"]); if (strlen($arFields["CALLBACK_FUNC"]) <= 0) { $arFields["CALLBACK_FUNC"] = "CatalogViewedProductCallback"; } if (strlen($arFields["MODULE"]) <= 0) { $arFields["MODULE"] = "catalog"; } if (strlen($arFields["PRODUCT_PROVIDER_CLASS"]) <= 0 && $arFields["MODULE"] == "catalog") { $arFields["PRODUCT_PROVIDER_CLASS"] = "CCatalogProductProvider"; } if ($arFields["PRODUCT_ID"] <= 0) { return false; } if (strlen($arFields["LID"]) <= 0) { return false; } if (\Bitrix\Main\Loader::includeModule("catalog")) { if (\Bitrix\Main\Config\Option::get("sale", "viewed_capability", "") == "Y") { return \Bitrix\Catalog\CatalogViewedProductTable::refresh($arFields["PRODUCT_ID"], CSaleBasket::GetBasketUserID(), $arFields["LID"]); } } $arFilter = array(); $arFilter["PRODUCT_ID"] = $arFields["PRODUCT_ID"]; if ($arFields["USER_ID"] > 0) { $arFuserItems = CSaleUser::GetList(array("USER_ID" => $arFields["USER_ID"])); $FUSER_ID = $arFuserItems["ID"]; } elseif (IntVal($arFields["FUSER_ID"]) > 0) { $FUSER_ID = $arFields["FUSER_ID"]; } else { $FUSER_ID = CSaleBasket::GetBasketUserID(); } $arFilter["FUSER_ID"] = $FUSER_ID; $arFields["FUSER_ID"] = $FUSER_ID; $db_res = CSaleViewedProduct::GetList(array(), $arFilter, false, false, array('ID')); if (!($arItems = $db_res->Fetch())) { if (CModule::IncludeModule('catalog')) { /** @var $productProvider IBXSaleProductProvider */ if ($productProvider = CSaleBasket::GetProductProvider($arFields)) { $arResultTmp = $productProvider::ViewProduct(array("PRODUCT_ID" => $arFields["PRODUCT_ID"], "USER_ID" => $arFields["USER_ID"], "SITE_ID" => $arFields["LID"])); } else { $arResultTmp = CSaleBasket::ExecuteCallbackFunction($arFields["CALLBACK_FUNC"], $arFields["MODULE"], $arFields["PRODUCT_ID"], $arFields["USER_ID"], $arFields["LID"]); } if ($arResultTmp && count($arResultTmp) > 0) { $arFields = array_merge($arFields, $arResultTmp); } if (strlen($arFields["NAME"]) <= 0) { return false; } $arInsert = $DB->PrepareInsert("b_sale_viewed_product", $arFields); //chance deleted $rnd = mt_rand(0, 1000); if ($rnd < 100) { $db_res = CSaleViewedProduct::GetList(array(), array("FUSER_ID" => $FUSER_ID), array("COUNT" => "ID"), false); $arCount = $db_res->Fetch(); $viewedCount = COption::GetOptionString("sale", "viewed_count", "100"); if ($arCount["ID"] > IntVal($viewedCount)) { $limit = $arCount["ID"] - $viewedCount + $viewedCount * 0.2; CSaleViewedProduct::DeleteForUser($FUSER_ID, $limit); } } $strSql = "INSERT INTO b_sale_viewed_product (" . $arInsert[0] . ", DATE_VISIT) VALUES(" . $arInsert[1] . ", " . $DB->GetNowFunction() . ")"; $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__); $ID = IntVal($DB->LastID()); } } else { $ID = IntVal($arItems["ID"]); $arFields["DATE_VISIT"] = $DB->GetNowFunction(); $arInsert = $DB->PrepareInsert("b_sale_viewed_product", $arFields); CSaleViewedProduct::Update($ID, $arFields); } foreach (GetModuleEvents("sale", "OnViewedAdd", true) as $arEvent) { ExecuteModuleEventEx($arEvent, array($arFields)); } return $ID; }
<?php require $_SERVER["DOCUMENT_ROOT"] . "/bitrix/modules/main/include/prolog_before.php"; if (CModule::IncludeModule("sale")) { CSaleViewedProduct::DeleteForUser(CSaleBasket::GetBasketUserID(), $LIMIT = NULL); }
} else { $arViews = CSaleBasket::ExecuteCallbackFunction('CatalogBasketCallback', 'catalog', $PRODUCT_ID, 1, $LID); } if (count($arViews) <= 0) { $viewedError = GetMessage('BUYER_VIEWED_ERROR_PRODUCT_FAIL'); $viewedMessage = ""; } else { $dbProduct = CIBlockElement::GetList(array(), array("ID" => $PRODUCT_ID), false, false, array('ID', 'NAME', "XML_ID", "IBLOCK_EXTERNAL_ID")); $arProduct = $dbProduct->Fetch(); $arViews['NAME'] = $arProduct["NAME"]; $arViews['PRODUCT_ID'] = $arProduct["ID"]; $arViews['MODULE'] = "catalog"; $arViews["LID"] = $LID; } } else { $dbViewsList = CSaleViewedProduct::GetList(array(), array("FUSER_ID" => $arFuserItems["ID"], "PRODUCT_ID" => $PRODUCT_ID), false, false); $arViews = $dbViewsList->Fetch(); } if (strlen($viewedError) <= 0) { $arFields = array("PROPS" => array()); $arParentSku = CCatalogSku::GetProductInfo($PRODUCT_ID); if ($arParentSku && count($arParentSku) > 0) { $arPropsSku = array(); $dbProduct = CIBlockElement::GetList(array(), array("ID" => $PRODUCT_ID), false, false, array('IBLOCK_ID')); $arProduct = $dbProduct->Fetch(); $dbOfferProperties = CIBlock::GetProperties($arProduct["IBLOCK_ID"], array(), array("!XML_ID" => "CML2_LINK")); while ($arOfferProperties = $dbOfferProperties->Fetch()) { $arPropsSku[] = $arOfferProperties["CODE"]; } $arFields["PROPS"] = CIBlockPriceTools::GetOfferProperties($PRODUCT_ID, $arParentSku["IBLOCK_ID"], $arPropsSku); }
'CURRENCY_ID' => $arParams['CURRENCY_ID'], 'HIDE_NOT_AVAILABLE' => $arParams["HIDE_NOT_AVAILABLE"], "SHOW_PRODUCTS_".$arParams["IBLOCK_ID"] => "Y", "PROPERTY_CODE_".$arRecomData['OFFER_IBLOCK_ID'] => array( ), "OFFER_TREE_PROPS_".$arRecomData['OFFER_IBLOCK_ID'] => $arParams["OFFER_TREE_PROPS"], "SECTION_NAME" => GetMessage("SF_ELEMENT_BUYS") ), $component ); } } $frame = $this->createFrame()->begin(); global $viewedProductIds; $viewedProductIds = Array(); $db_get = CSaleViewedProduct::GetList(Array("DATE_VISIT" => "DESC"), Array(), false, false, Array("PRODUCT_ID"));//\Bitrix\Catalog\CatalogViewedProductTable::getList(Array("filter" => Array("SITE_ID" => SITE_ID, "FUSER_ID" => CSaleBasket::GetBasketUserID()), "select" => Array("ID", "PRODUCT_ID"), "order" => array("DATE_VISIT" => "DESC"), "limit" => 15)); while ($ar_get = $db_get->Fetch()) { $viewedProductIds[] = $ar_get["PRODUCT_ID"]; } $viewedProductIds = array_values(array_unique($viewedProductIds)); if (count($viewedProductIds) > 0) { global $arrFilter1; $arrFilter1 = Array("ID" => $viewedProductIds, "ACTIVE" => "Y", "ACTIVE_DATE" => "Y", "SECTION_GLOBAL_ACTIVE" => "Y"); ?><?$intSectionID = $APPLICATION->IncludeComponent( "bitrix:catalog.section", "viewedProduct", array( "IBLOCK_TYPE" => $arParams["IBLOCK_TYPE"], "IBLOCK_ID" => $arParams["IBLOCK_ID"], "ELEMENT_SORT_FIELD" => "", "ELEMENT_SORT_ORDER" => "", "ELEMENT_SORT_FIELD2" => "",
$arDate["MI"] = 59; $arDate["SS"] = 59; } $filter_date_visit_to = date($DB->DateFormatToPHP(CSite::GetDateFormat("FULL", SITE_ID)), mktime($arDate["HH"], $arDate["MI"], $arDate["SS"], $arDate["MM"], $arDate["DD"], $arDate["YYYY"])); $arFilter["DATE_TO"] = $filter_date_visit_to; } else { $filter_date_visit_to = ""; } } if (strlen(trim($filter_date_visit_from_DAYS_TO_BACK)) > 0) { $dateBack = IntVal($filter_date_visit_from_DAYS_TO_BACK); $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); $dbViewsList = CSaleViewedProduct::GetList($arViewSort, $arFilter, false, false, array()); $dbViewsList = new CAdminResult($dbViewsList, $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" => "LID", "content" => GetMessage("BUYER_V_LID"), "sort" => "LID", "default" => true); } $lAdmin_tab5->AddHeaders($viewedHeader); while ($arViews = $dbViewsList->Fetch()) { $row =& $lAdmin_tab5->AddRow($arViews["PRODUCT_ID"], $arViews, '', ''); $name = "[" . $arViews["PRODUCT_ID"] . "] <a href=\"" . $arViews["DETAIL_PAGE_URL"] . "\">" . $arViews["NAME"] . "</a>"; if (floatVal($arViews["PRICE"]) <= 0) { $name .= "<div class=\"dont_can_buy\">(" . GetMessage('BUYER_DONT_CAN_BUY') . ")</div>"; } $name .= "<input type=\"hidden\" name=\"table_id\" value=\"" . $sTableID_tab5 . "\">";
$obCache = new CPHPCache(); $cache_id = "admin_products_" . md5(serialize($arFilter)) . "_" . $arGadgetParams["LIMIT"]; if ($obCache->InitCache($cache_time, $cache_id, "/")) { $arResult = $obCache->GetVars(); } else { $arResult = array(); $arResult["SEL"] = array(); $arFilter["PAYED"] = "Y"; $dbR = CSaleProduct::GetBestSellerList("AMOUNT", array(), $arFilter, $arGadgetParams["LIMIT"]); while ($arR = $dbR->Fetch()) { $arResult["SEL"][] = $arR; } $arResult["VIEWED"] = array(); $arFilter[">=DATE_VISIT"] = $arFilter[">=DATE_INSERT"]; unset($arFilter[">=DATE_INSERT"]); $dbR = CSaleViewedProduct::GetList(array("ID" => "DESC"), $arFilter, array("PRODUCT_ID", "NAME", "CURRENCY", "COUNT" => "ID", "AVG" => "PRICE"), array("nTopCount" => $arGadgetParams["LIMIT"])); while ($arR = $dbR->Fetch()) { $arResult["VIEWED"][] = $arR; } } if ($obCache->StartDataCache()) { $obCache->EndDataCache($arResult); } ?> <script type="text/javascript"> var gdSaleProductsTabControl_<?php echo $arGadgetParams["RND_STRING"]; ?> = false; BX.ready(function(){ gdSaleProductsTabControl_<?php