Ejemplo n.º 1
0
					$counterData['price'] = (isset($arResult['MIN_PRICE']) ? $arResult['MIN_PRICE']['DISCOUNT_VALUE'] : '');
					$counterData['currency'] = (isset($arResult['MIN_PRICE']) ? $arResult['MIN_PRICE']['CURRENCY'] : '');
				}
				else
				{
					$offer = current($arResult["OFFERS"]);
					$counterData['price'] = (isset($offer['MIN_PRICE']) ? $offer['MIN_PRICE']['DISCOUNT_VALUE'] : '');
					$counterData['currency'] = (isset($offer['MIN_PRICE']) ? $offer['MIN_PRICE']['CURRENCY'] : '');
					unset($offer);
				}

				// make sure it is in utf8
				$counterData = \Bitrix\Main\Text\Encoding::convertEncodingArray($counterData, SITE_CHARSET, 'UTF-8');

				// pack value and protocol version
				$rcmLogCookieName = COption::GetOptionString("main", "cookie_name", "BITRIX_SM")."_".\Bitrix\Main\Analytics\Catalog::getCookieLogName();

				$arResult['counterData'] = array(
					'item' => base64_encode(json_encode($counterData)),
					'user_id' => new \Bitrix\Main\Text\JsExpression(
						"function() {
							return BX.message(\"USER_ID\") ? BX.message(\"USER_ID\") : 0;
						}"
					),
					'recommendation' => new \Bitrix\Main\Text\JsExpression(
						"function() {

							var rcmId = \"\";

							var cookieValue = BX.getCookie(\"{$rcmLogCookieName}\");
							var productId = {$arResult["ID"]};
Ejemplo n.º 2
0
				"SECTION",
				"IPROPERTY_VALUES",
			);

			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']))
				{
Ejemplo n.º 3
0
 /**
  * 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;
     }
 }