/** * Common function, used to update/insert any product. * * @param int $productId Id of product. * @param int $fuserId User basket id. * @param string $siteId Site id. * @param int $elementId Parent id. * @param string $recommendationId Bigdata recommendation id. * * @return int */ public static function refresh($productId, $fuserId, $siteId = SITE_ID, $elementId = 0, $recommendationId = '') { $productId = (int) $productId; $fuserId = (int) $fuserId; $siteId = (string) $siteId; $elementId = (int) $elementId; $recommendationId = (string) $recommendationId; if ($productId <= 0 || $fuserId <= 0 || $siteId == '') { return -1; } if (Main\Loader::includeModule('statictic') && isset($_SESSION['SESS_SEARCHER_ID']) && (int) $_SESSION['SESS_SEARCHER_ID'] > 0) { return -1; } $filter = array('=FUSER_ID' => $fuserId, '=SITE_ID' => $siteId); $connection = Application::getConnection(); $helper = $connection->getSqlHelper(); $sqlSiteId = $helper->forSql($siteId); if ($elementId > 0) { $filter["=ELEMENT_ID"] = $elementId; // Delete parent product id (for capability) if ($elementId != $productId) { $connection->query("delete from b_catalog_viewed_product where PRODUCT_ID = " . $elementId . " and FUSER_ID = " . $fuserId . " and SITE_ID = '" . $sqlSiteId . "'"); } } else { $productInfo = \CCatalogSKU::getProductInfo($productId); // Real SKU ID if (!empty($productInfo)) { $elementId = $productInfo['ID']; $siblings = array(); // Delete parent product id (for capability) $connection->query("delete from b_catalog_viewed_product\n\t\t\t\t\t\t\t\t\twhere PRODUCT_ID = " . $productInfo['ID'] . " and FUSER_ID = " . $fuserId . " and SITE_ID = '" . $sqlSiteId . "'"); $skus = \CIBlockElement::getList(array(), array('IBLOCK_ID' => $productInfo['OFFER_IBLOCK_ID'], '=PROPERTY_' . $productInfo['SKU_PROPERTY_ID'] => $productInfo['ID']), false, false, array('ID', 'IBLOCK_ID')); while ($oneSku = $skus->fetch()) { $siblings[] = $oneSku['ID']; } unset($oneSku, $skus); $filter['@PRODUCT_ID'] = $siblings; } else { $elementId = $productId; $filter['=PRODUCT_ID'] = $productId; } } // recommendation if (!empty($elementId)) { global $APPLICATION; $recommendationCookie = $APPLICATION->get_cookie(Main\Analytics\Catalog::getCookieLogName()); if (!empty($recommendationCookie)) { $recommendations = Main\Analytics\Catalog::decodeProductLog($recommendationCookie); if (is_array($recommendations) && isset($recommendations[$elementId])) { $recommendationId = $recommendations[$elementId][0]; } } } $iterator = static::getList(array('select' => array('ID', 'FUSER_ID', 'DATE_VISIT', 'PRODUCT_ID', 'SITE_ID', 'VIEW_COUNT'), 'filter' => $filter)); if ($row = $iterator->fetch()) { $update = array("PRODUCT_ID" => $productId, "DATE_VISIT" => new Main\Type\DateTime(), 'VIEW_COUNT' => $row['VIEW_COUNT'] + 1, "ELEMENT_ID" => $elementId); if (!empty($recommendationId)) { $update["RECOMMENDATION"] = $recommendationId; } $result = static::update($row['ID'], $update); return $result->isSuccess(true) ? $row['ID'] : -1; } else { $result = static::add(array("FUSER_ID" => $fuserId, "DATE_VISIT" => new Main\Type\DateTime(), "PRODUCT_ID" => $productId, "ELEMENT_ID" => $elementId, "SITE_ID" => $siteId, "VIEW_COUNT" => 1, "RECOMMENDATION" => $recommendationId)); return $result->isSuccess(true) ? $result->getId() : -1; } }
if ($bCatalog) { // catalog hit stats $productTitle = !empty($arResult["IPROPERTY_VALUES"]["ELEMENT_PAGE_TITLE"]) ? $arResult["IPROPERTY_VALUES"]["ELEMENT_PAGE_TITLE"] : $arResult["NAME"]; $categoryId = ''; $categoryPath = array(); $recommendationId = 0; $rcmLogCookie = $APPLICATION->get_cookie(\Bitrix\Main\Analytics\Catalog::getCookieLogName()); if (!empty($rcmLogCookie)) { $rcmLog = \Bitrix\Main\Analytics\Catalog::decodeProductLog($rcmLogCookie); if (!empty($rcmLog[$arResult['ID']])) { $recommendationId = $rcmLog[$arResult['ID']][0]; } } if (isset($arResult['SECTION']['ID'])) { $categoryId = $arResult['SECTION']['ID']; } if (isset($arResult['SECTION']['PATH']))
if (isset($_POST['AJAX']) && $_POST['AJAX'] == 'Y') { if (isset($_POST['PRODUCT_ID']) && isset($_POST['SITE_ID'])) { $productID = (int)$_POST['PRODUCT_ID']; $parentID = (int)$_POST['PARENT_ID']; $siteID = substr((string)$_POST['SITE_ID'], 0, 2); if ($productID > 0 && $siteID !== '' && \Bitrix\Main\Loader::includeModule('catalog') && \Bitrix\Main\Loader::includeModule('sale')) { // check if there was a recommendation $recommendationId = ''; $recommendationCookie = $APPLICATION->get_cookie(Bitrix\Main\Analytics\Catalog::getCookieLogName()); if (!empty($recommendationCookie)) { $recommendations = \Bitrix\Main\Analytics\Catalog::decodeProductLog($recommendationCookie); if (is_array($recommendations) && isset($recommendations[$parentID])) { $recommendationId = $recommendations[$parentID][0]; } } // add record CatalogViewedProductTable::refresh( $productID, CSaleBasket::GetBasketUserID(), $siteID, $parentID, $recommendationId );