Пример #1
0
 public static function catchCatalogBasket($id, $arFields)
 {
     global $APPLICATION;
     // alter b_sale_basket - add recommendation, update it here
     if (!static::isOn()) {
         return;
     }
     // get product id by offer id
     $productInfo = \CCatalogSKU::GetProductInfo($arFields['PRODUCT_ID']);
     if (!empty($productInfo['ID'])) {
         $realProductId = $productInfo['ID'];
     } else {
         $realProductId = $arFields['PRODUCT_ID'];
     }
     // select site user id & recommendation id
     $siteUserId = 0;
     $recommendationId = '';
     // first, try to find in cookies
     $recommendationCookie = $APPLICATION->get_cookie(static::getCookieLogName());
     if (!empty($recommendationCookie)) {
         $recommendations = static::decodeProductLog($recommendationCookie);
         if (is_array($recommendations) && isset($recommendations[$realProductId])) {
             $recommendationId = $recommendations[$realProductId][0];
         }
     }
     if (empty($recommendationId)) {
         // ok then, lets see in views history
         //if(\COption::GetOptionString("sale", "encode_fuser_id", "N") == "Y")
         if (!is_numeric($arFields['FUSER_ID'])) {
             $filter = array('CODE' => $arFields['FUSER_ID']);
         } else {
             $filter = array('ID' => $arFields['FUSER_ID']);
         }
         $result = \CSaleUser::getList($filter);
         if (!empty($result)) {
             $siteUserId = $result['USER_ID'];
             // select recommendation id
             $fuser = $result['ID'];
             $viewResult = CatalogViewedProductTable::getList(array('select' => array('RECOMMENDATION'), 'filter' => array('=FUSER_ID' => $fuser, '=PRODUCT_ID' => $arFields['PRODUCT_ID']), 'order' => array('DATE_VISIT' => 'DESC')))->fetch();
             if (!empty($viewResult['RECOMMENDATION'])) {
                 $recommendationId = $viewResult['RECOMMENDATION'];
             }
         }
     }
     // prepare data
     $data = array('product_id' => $realProductId, 'user_id' => $siteUserId, 'bx_user_id' => static::getBxUserId(), 'domain' => Context::getCurrent()->getServer()->getHttpHost(), 'recommendation' => $recommendationId, 'date' => date(DATE_ISO8601));
     CounterDataTable::add(array('TYPE' => 'basket', 'DATA' => $data));
     // update basket with recommendation id
     if (!empty($recommendationId)) {
         $conn = Application::getConnection();
         $helper = $conn->getSqlHelper();
         $conn->query("UPDATE " . $helper->quote('b_sale_basket') . " SET RECOMMENDATION='" . $helper->forSql($recommendationId) . "' WHERE ID=" . (int) $id);
     }
 }
Пример #2
0
<?php

use Bitrix\Catalog\CatalogViewedProductTable;
require $_SERVER["DOCUMENT_ROOT"] . "/bitrix/modules/main/include/prolog_before.php";
if (isset($_POST['AJAX']) && $_POST['AJAX'] == 'Y') {
    if (\Bitrix\Main\Loader::includeModule("catalog") && \Bitrix\Main\Loader::includeModule("sale")) {
        if (isset($_POST['PRODUCT_ID'])) {
            CatalogViewedProductTable::refresh((int) $_POST['PRODUCT_ID'], CSaleBasket::GetBasketUserID(), $_POST['SITE_ID']);
            echo CUtil::PhpToJSObject(array("STATUS" => "SUCCESS"));
        } else {
            echo CUtil::PhpToJSObject(array("STATUS" => "ERROR", "TEXT" => "UNDEFINED PRODUCT"));
        }
    }
    die;
}
Пример #3
0
 /**
  * The function select viewed product
  *
  * @param array $arOrder - array to sort
  * @param array $arFilter - array to filter
  * @param array $arGroupBy - array to group records
  * @param array $arNavStartParams - array to parameters
  * @param array $arSelectFields - array to selectes fields
  * @return object $dbRes - object result
  */
 public static function GetList($arOrder = array("ID" => "DESC"), $arFilter = array(), $arGroupBy = false, $arNavStartParams = false, $arSelectFields = array())
 {
     global $DB;
     if (array_key_exists("DATE_FROM", $arFilter)) {
         $arFilter[">=DATE_VISIT"] = trim($arFilter["DATE_FROM"]);
         unset($arFilter["DATE_FROM"]);
     }
     if (array_key_exists("DATE_TO", $arFilter)) {
         $arFilter["<=DATE_VISIT"] = trim($arFilter["DATE_TO"]);
         unset($arFilter["DATE_TO"]);
     }
     if (!$arSelectFields || count($arSelectFields) <= 0 || in_array("*", $arSelectFields)) {
         $arSelectFields = array("ID", "FUSER_ID", "DATE_VISIT", "PRODUCT_ID", "MODULE", "LID", "NAME", "DETAIL_PAGE_URL", "CURRENCY", "PRICE", "NOTES", "PREVIEW_PICTURE", "DETAIL_PICTURE", "CALLBACK_FUNC", "PRODUCT_PROVIDER_CLASS");
     }
     if (\Bitrix\Main\Loader::includeModule("catalog")) {
         if (\Bitrix\Main\Config\Option::get("sale", "viewed_capability", "") == "Y") {
             foreach ($arFilter as $key => $value) {
                 if ($key == "LID") {
                     $arFilter['SITE_ID'] = $value;
                     unset($arFilter['LID']);
                 }
             }
             $limit = 100;
             if (is_array($arNavStartParams) && IntVal($arNavStartParams["nTopCount"]) >= 0) {
                 $limit = IntVal($arNavStartParams["nTopCount"]);
             }
             $viewedIterator = \Bitrix\Catalog\CatalogViewedProductTable::getList(array("filter" => $arFilter, "select" => array("ID", "PRODUCT_ID", "DATE_VISIT", "LID" => "SITE_ID", "NAME" => "ELEMENT.NAME"), "order" => array("DATE_VISIT" => "DESC"), "limit" => $limit));
             $viewed = array();
             while ($row = $viewedIterator->fetch()) {
                 $row['MODULE'] = "catalog";
                 $row['DATE_VISIT'] = $row['DATE_VISIT']->toString();
                 $viewed[$row['PRODUCT_ID']] = $row;
             }
             if (count($viewed)) {
                 // Map to parent sku
                 $newIds = array();
                 $ids = array_keys($viewed);
                 $catalogIterator = CCatalog::getList();
                 while ($catalog = $catalogIterator->fetch()) {
                     if ($catalog['IBLOCK_TYPE_ID'] == "offers") {
                         $elementIterator = CIBlockElement::getList(array(), array("ID" => $ids, "IBLOCK_ID" => $catalog['IBLOCK_ID']), false, false, array("ID", "IBLOCK_ID", "PROPERTY_" . $catalog['SKU_PROPERTY_ID']));
                         while ($item = $elementIterator->fetch()) {
                             $propertyName = "PROPERTY_" . $catalog['SKU_PROPERTY_ID'] . "_VALUE";
                             $parentId = $item[$propertyName];
                             if (!empty($parentId)) {
                                 $newIds[$item['ID']] = $parentId;
                             } else {
                                 $newIds[$item['ID']] = $item['ID'];
                             }
                         }
                     }
                 }
                 // Push missing
                 foreach ($ids as $id) {
                     if (!isset($newIds[$id])) {
                         $newIds[$id] = $id;
                     }
                 }
                 $filter = array("ID" => array_values($newIds));
                 if (!count($filter['ID'])) {
                     $filter = array("ID" => -1);
                 }
                 $mapped = array();
                 if (in_array("DETAIL_PAGE_URL", $arSelectFields) || in_array("PREVIEW_PICTURE", $arSelectFields) || in_array("DETAIL_PICTURE", $arSelectFields)) {
                     $elementIterator = CIBlockElement::GetList(array(), $filter);
                     while ($elementObj = $elementIterator->GetNextElement()) {
                         $fields = $elementObj->GetFields();
                         $mapped[$fields['ID']]['PREVIEW_PICTURE'] = $fields['PREVIEW_PICTURE'];
                         $mapped[$fields['ID']]['DETAIL_PICTURE'] = $fields['DETAIL_PICTURE'];
                     }
                 }
                 foreach ($newIds as $natural => $tr) {
                     $viewed[$natural]['PREVIEW_PICTURE'] = $mapped[$tr]['DETAIL_PICTURE'];
                     $viewed[$natural]['DETAIL_PICTURE'] = $mapped[$tr]['PREVIEW_PICTURE'];
                     $viewed[$natural]['PRODUCT_ID'] = $tr;
                 }
                 if (in_array("CURRENCY", $arSelectFields) || in_array("PRICE", $arSelectFields)) {
                     // Prices
                     $priceIterator = CPrice::getList(array(), array("PRODUCT_ID" => $ids), false, false, array("PRODUCT_ID", "PRICE", "CURRENCY"));
                     while ($price = $priceIterator->fetch()) {
                         if (!isset($viewed[$price['PRODUCT_ID']]['PRICE'])) {
                             $viewed[$price['PRODUCT_ID']]['PRICE'] = $price['PRICE'];
                             $viewed[$price['PRODUCT_ID']]['CURRENCY'] = $price['CURRENCY'];
                         }
                     }
                 }
             }
             // resort
             $dbresult = new CDBResult();
             $dbresult->InitFromArray(array_values($viewed));
             return $dbresult;
         }
     }
     $arFields = array("ID" => array("FIELD" => "V.ID", "TYPE" => "int"), "FUSER_ID" => array("FIELD" => "V.FUSER_ID", "TYPE" => "int"), "DATE_VISIT" => array("FIELD" => "V.DATE_VISIT", "TYPE" => "datetime"), "PRODUCT_ID" => array("FIELD" => "V.PRODUCT_ID", "TYPE" => "int"), "MODULE" => array("FIELD" => "V.MODULE", "TYPE" => "string"), "LID" => array("FIELD" => "V.LID", "TYPE" => "string"), "NAME" => array("FIELD" => "V.NAME", "TYPE" => "string"), "DETAIL_PAGE_URL" => array("FIELD" => "V.DETAIL_PAGE_URL", "TYPE" => "string"), "CURRENCY" => array("FIELD" => "V.CURRENCY", "TYPE" => "string"), "PRICE" => array("FIELD" => "V.PRICE", "TYPE" => "double"), "NOTES" => array("FIELD" => "V.NOTES", "TYPE" => "string"), "PREVIEW_PICTURE" => array("FIELD" => "V.PREVIEW_PICTURE", "TYPE" => "string"), "DETAIL_PICTURE" => array("FIELD" => "V.DETAIL_PICTURE", "TYPE" => "string"), "CALLBACK_FUNC" => array("FIELD" => "V.CALLBACK_FUNC", "TYPE" => "string"), "PRODUCT_PROVIDER_CLASS" => array("FIELD" => "V.PRODUCT_PROVIDER_CLASS", "TYPE" => "string"));
     $arSqls = CSaleOrder::PrepareSql($arFields, $arOrder, $arFilter, $arGroupBy, $arSelectFields);
     $arSqls["SELECT"] = str_replace("%%_DISTINCT_%%", "", $arSqls["SELECT"]);
     $strSql = "SELECT " . $arSqls["SELECT"] . " " . "FROM b_sale_viewed_product V ";
     if (strlen($arSqls["WHERE"]) > 0) {
         $strSql .= "WHERE " . $arSqls["WHERE"] . " ";
     }
     if (strlen($arSqls["GROUPBY"]) > 0) {
         $strSql .= "GROUP BY " . $arSqls["GROUPBY"] . " ";
     }
     if (strlen($arSqls["ORDERBY"]) > 0) {
         $strSql .= "ORDER BY " . $arSqls["ORDERBY"] . " ";
     }
     if (is_array($arGroupBy) && count($arGroupBy) == 0) {
         $dbRes = $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__);
         if ($arRes = $dbRes->Fetch()) {
             return $arRes["CNT"];
         } else {
             return false;
         }
     }
     if (is_array($arNavStartParams) && IntVal($arNavStartParams["nTopCount"]) <= 0) {
         $strSql_tmp = "SELECT COUNT('x') as CNT " . "FROM b_sale_viewed_product B ";
         if (strlen($arSqls["WHERE"]) > 0) {
             $strSql_tmp .= "WHERE " . $arSqls["WHERE"] . " ";
         }
         if (strlen($arSqls["GROUPBY"]) > 0) {
             $strSql_tmp .= "GROUP BY " . $arSqls["GROUPBY"] . " ";
         }
         $dbRes = $DB->Query($strSql_tmp, false, "File: " . __FILE__ . "<br>Line: " . __LINE__);
         $cnt = 0;
         if (strlen($arSqls["GROUPBY"]) <= 0) {
             if ($arRes = $dbRes->Fetch()) {
                 $cnt = $arRes["CNT"];
             }
         } else {
             $cnt = $dbRes->SelectedRowsCount();
         }
         $dbRes = new CDBResult();
         $dbRes->NavQuery($strSql, $cnt, $arNavStartParams);
     } else {
         $strSql = $DB->TopSql($strSql, $arNavStartParams["nTopCount"]);
         $dbRes = $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__);
     }
     return $dbRes;
 }
Пример #4
0
*			"IMAGE" 				- путь к изображению
*			"REVIEW_COUNT" 			- количество коментариев к товару
*		]
*	]
*/
use Bitrix\Main;
use Bitrix\Iblock;
use Bitrix\Catalog;
if ($this->StartResultCache()) {
    if (!Main\Loader::IncludeModule("iblock") || !Main\Loader::includeModule('catalog') || !Main\Loader::includeModule('sale') || !Main\Loader::includeModule('blog')) {
        $this->AbortResultCache();
        return;
    }
    $arFilterV["SITE_ID"] = SITE_ID;
    $arFilterV["FUSER_ID"] = CSaleBasket::GetBasketUserID();
    $viewedIterator = \Bitrix\Catalog\CatalogViewedProductTable::getList(array('order' => array("DATE_VISIT" => "DESC"), 'filter' => $arFilterV, 'select' => array("ELEMENT_ID", "PRODUCT_ID"), 'limit' => $arParams["PAGE_ELEMENT_COUNT"]));
    while ($arItems = $viewedIterator->fetch()) {
        $arResult[$arItems["ELEMENT_ID"]] = $arItems["PRODUCT_ID"];
    }
    unset($arItems, $viewedIterator);
    if (!empty($arResult)) {
        $arIblockId = array();
        $strImageStorePath = COption::GetOptionString("main", "upload_dir", "upload");
        $arSelect = array("ID", "NAME", "IBLOCK_SECTION_ID", "IBLOCK_TYPE_ID", "IBLOCK_ID", "DETAIL_PAGE_URL", "CATALOG_GROUP_RETAIL", "PREVIEW_PICTURE", "DETAIL_PICTURE");
        $elementIterator = CIBlockElement::GetList(array(), array("ID" => array_keys($arResult), "IBLOCK_TYPE_ID" => $arParams["IBLOCK_TYPE_ID"]), false, array(), $arSelect);
        unset($arSelect);
        while ($el = $elementIterator->GetNext()) {
            $iProductId = $arResult[$el["ID"]];
            //Если запрос не вернул цену товара, то возможно это товар с торговым предложением, поэтому получаем его базовую цену этого товара
            if ($el["CATALOG_PURCHASING_PRICE"] == "") {
                $arPrice = CPrice::GetBasePrice($iProductId);
Пример #5
0
 public static function catchCatalogBasket($id, $arFields)
 {
     // exclude empty cookie
     if (!static::getBxUserId()) {
         return;
     }
     if (!isset($arFields['MODULE']) || $arFields['MODULE'] != 'catalog') {
         // catalog items only
         return;
     }
     global $APPLICATION;
     // alter b_sale_basket - add recommendation, update it here
     if (!static::isOn()) {
         return;
     }
     // get product id by offer id
     $productInfo = \CCatalogSKU::GetProductInfo($arFields['PRODUCT_ID']);
     $iblockId = 0;
     if (!empty($productInfo['ID'])) {
         $realProductId = $productInfo['ID'];
         $iblockId = $productInfo['IBLOCK_ID'];
     } else {
         $realProductId = $arFields['PRODUCT_ID'];
         // get iblock id
         $element = \Bitrix\Iblock\ElementTable::getRow(array('select' => array('IBLOCK_ID'), 'filter' => array('=ID' => $realProductId)));
         if (!empty($element)) {
             $iblockId = $element['IBLOCK_ID'];
         }
     }
     // select site user id & recommendation id
     $siteUserId = 0;
     $recommendationId = '';
     // first, try to find in cookies
     $recommendationCookie = $APPLICATION->get_cookie(static::getCookieLogName());
     if (!empty($recommendationCookie)) {
         $recommendations = static::decodeProductLog($recommendationCookie);
         if (is_array($recommendations) && isset($recommendations[$realProductId])) {
             $recommendationId = $recommendations[$realProductId][0];
         }
     }
     if (empty($recommendationId)) {
         // ok then, lets see in views history
         //if(\COption::GetOptionString("sale", "encode_fuser_id", "N") == "Y")
         if (!is_numeric($arFields['FUSER_ID'])) {
             $filter = array('CODE' => $arFields['FUSER_ID']);
         } else {
             $filter = array('ID' => $arFields['FUSER_ID']);
         }
         $result = \CSaleUser::getList($filter);
         if (!empty($result)) {
             $siteUserId = $result['USER_ID'];
             // select recommendation id
             $fuser = $result['ID'];
             $viewResult = CatalogViewedProductTable::getList(array('select' => array('RECOMMENDATION'), 'filter' => array('=FUSER_ID' => $fuser, '=PRODUCT_ID' => $arFields['PRODUCT_ID']), 'order' => array('DATE_VISIT' => 'DESC')))->fetch();
             if (!empty($viewResult['RECOMMENDATION'])) {
                 $recommendationId = $viewResult['RECOMMENDATION'];
             }
         }
     }
     // prepare data
     $data = array('product_id' => $realProductId, 'iblock_id' => $iblockId, 'user_id' => $siteUserId, 'bx_user_id' => static::getBxUserId(), 'domain' => Context::getCurrent()->getServer()->getHttpHost(), 'recommendation' => $recommendationId, 'date' => date(DATE_ISO8601));
     // debug info
     global $USER;
     $data['real_user_id'] = $USER->getId() ?: 0;
     $data['is_admin'] = (int) $USER->IsAdmin();
     $data['admin_section'] = (int) (defined('ADMIN_SECTION') && ADMIN_SECTION);
     $data['admin_panel'] = (int) \CTopPanel::shouldShowPanel();
     // try to guess unnatural baskets
     $data['artificial_basket'] = (int) ($data['user_id'] > 0 && $data['user_id'] != $data['real_user_id'] || $data['is_admin'] || $data['admin_section'] || $data['admin_panel']);
     // save
     CounterDataTable::add(array('TYPE' => 'basket', 'DATA' => $data));
     // update basket with recommendation id
     if (!empty($recommendationId)) {
         $conn = Application::getConnection();
         $helper = $conn->getSqlHelper();
         $conn->query("UPDATE " . $helper->quote('b_sale_basket') . " SET RECOMMENDATION='" . $helper->forSql($recommendationId) . "' WHERE ID=" . (int) $id);
     }
 }
Пример #6
0
 /**
  * Get main data - viewed products.
  * @return void
  */
 protected function prepareData()
 {
     $this->data = $this->getReferences();
     $this->productIds = $this->getProductIds();
     if (is_null($this->productIds)) {
         $this->productIdsMap = $this->getProductIdsMap();
         $this->productIds = array_keys($this->productIdsMap);
     } else {
         $this->productIdsMap = CatalogViewedProductTable::getProductsMap($this->productIds);
     }
     $this->data['CATALOG_PRICES'] = $this->getCatalogPrices($this->arParams["PRICE_CODE"]);
     $this->prepareFilter();
     $this->prepareSelectFields();
     $this->items = $this->getItems();
     $this->resortItemsByIds($this->productIds);
     $this->setItemsPrices();
     $this->setItemsMeasure();
     $this->setItemsOffers();
 }
Пример #7
0
    if (!empty($arResult['BACKGROUND_IMAGE']) && is_array($arResult['BACKGROUND_IMAGE'])) {
        $APPLICATION->SetPageProperty("backgroundImage", 'style="background-image: url(\'' . $arResult['BACKGROUND_IMAGE']['SRC'] . '\')"');
    }
    if ($arParams["ADD_SECTIONS_CHAIN"] && !empty($arResult["SECTION"]["PATH"]) && is_array($arResult["SECTION"]["PATH"])) {
        foreach ($arResult["SECTION"]["PATH"] as $arPath) {
            if ($arPath["IPROPERTY_VALUES"]["SECTION_PAGE_TITLE"] != "") {
                $APPLICATION->AddChainItem($arPath["IPROPERTY_VALUES"]["SECTION_PAGE_TITLE"], $arPath["~SECTION_PAGE_URL"]);
            } else {
                $APPLICATION->AddChainItem($arPath["NAME"], $arPath["~SECTION_PAGE_URL"]);
            }
        }
    }
    if ($arParams["ADD_ELEMENT_CHAIN"]) {
        if ($arResult["IPROPERTY_VALUES"]["ELEMENT_PAGE_TITLE"] != "") {
            $APPLICATION->AddChainItem($arResult["IPROPERTY_VALUES"]["ELEMENT_PAGE_TITLE"]);
        } else {
            $APPLICATION->AddChainItem($arResult["NAME"]);
        }
    }
    if ($arParams["SET_LAST_MODIFIED"] && $arResult["TIMESTAMP_X"]) {
        Context::getCurrent()->getResponse()->setLastModified(DateTime::createFromUserTime($arResult["TIMESTAMP_X"]));
    }
    if ($arParams['SET_VIEWED_IN_COMPONENT'] == 'Y' && !empty($arResult['VIEWED_PRODUCT'])) {
        if (Loader::includeModule('catalog') && Loader::includeModule('sale')) {
            \Bitrix\Catalog\CatalogViewedProductTable::refresh($arResult['VIEWED_PRODUCT']['OFFER_ID'], CSaleBasket::GetBasketUserID(), SITE_ID, $arResult['VIEWED_PRODUCT']['PRODUCT_ID']);
        }
    }
    return $arResult["ID"];
} else {
    return 0;
}
Пример #8
0
 protected function getProductIds()
 {
     $ids = array();
     if (!empty($this->ajaxItemsIds)) {
         $recommendationId = Main\Context::getCurrent()->getRequest()->get('RID');
         $ids = $this->ajaxItemsIds;
     } else {
         $bestsellers = parent::getProductIds();
         if (!empty($bestsellers)) {
             $recommendationId = 'bestsellers';
             $ids = Main\Analytics\Catalog::getProductIdsByOfferIds($bestsellers);
         }
         if (empty($ids)) {
             $recommendationId = 'mostviewed';
             $dublicate = array();
             // top viewed
             $result = CatalogViewedProductTable::getList(array('select' => array('ELEMENT_ID', new Main\Entity\ExpressionField('SUM_HITS', 'SUM(%s)', 'VIEW_COUNT')), 'filter' => array('=SITE_ID' => $this->getSiteId(), '>ELEMENT_ID' => 0), 'order' => array('SUM_HITS' => 'DESC'), 'limit' => $this->arParams['PAGE_ELEMENT_COUNT']));
             while ($row = $result->fetch()) {
                 if (!isset($dublicate[$row['ELEMENT_ID']])) {
                     $ids[] = $row['ELEMENT_ID'];
                 }
                 $dublicate[$row['ELEMENT_ID']] = true;
             }
             unset($row, $result, $dublicate);
         }
     }
     if (!empty($ids) && $this->arParams['HIDE_NOT_AVAILABLE'] == 'Y') {
         $filter = count($ids) > 1000 ? array('ID' => $ids) : array('@ID' => $ids);
         $ids = array_fill_keys($ids, true);
         $productIterator = CCatalogProduct::GetList(array(), $filter, false, false, array('ID', 'QUANTITY', 'QUANTITY_TRACE', 'CAN_BUY_ZERO'));
         while ($product = $productIterator->Fetch()) {
             if (isset($ids[$product['ID']]) && !CCatalogProduct::isAvailable($product)) {
                 unset($ids[$product['ID']]);
             }
         }
         unset($product, $productIterator, $filter);
         $ids = array_keys($ids);
     }
     $ids = array_slice($ids, 0, $this->arParams['PAGE_ELEMENT_COUNT']);
     // remember recommendation id
     $this->arResult['RID'] = $recommendationId;
     return $ids;
 }
Пример #9
0
			// 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
			);
			echo CUtil::PhpToJSObject(array("STATUS" => "SUCCESS"));
		}
		else
		{
			echo CUtil::PhpToJSObject(array("STATUS" => "ERROR", "TEXT" => "UNDEFINED PRODUCT"));
		}
	}
	die();
}
Пример #10
0
 /**
  * Returns viewed product ids.
  * @return integer[]
  */
 protected function getProductIds()
 {
     $basketUserID = (int) CSaleBasket::GetBasketUserID(false);
     if ($basketUserID <= 0) {
         return array();
     }
     $sectionSearch = $this->arParams["SECTION_ID"] > 0 || $this->arParams["SECTION_CODE"] !== '';
     $sectionByItemSearch = $this->arParams["SECTION_ELEMENT_ID"] > 0 || $this->arParams["SECTION_ELEMENT_CODE"] !== '';
     $ids = array();
     if (!$sectionSearch && !$sectionByItemSearch) {
         $viewedIterator = CatalogViewedProductTable::GetList(array('select' => array('PRODUCT_ID'), 'filter' => array('FUSER_ID' => $basketUserID, 'SITE_ID' => SITE_ID), 'order' => array('DATE_VISIT' => 'DESC'), 'limit' => $this->arParams['PAGE_ELEMENT_COUNT']));
         while ($viewedProduct = $viewedIterator->fetch()) {
             $ids[] = $viewedProduct['PRODUCT_ID'];
         }
     } else {
         if ($sectionSearch) {
             $section = $this->checkSection($this->arParams["SECTION_ID"], $this->arParams["SECTION_CODE"]);
         } else {
             $section = $this->checkSectionByElement($this->arParams["SECTION_ELEMENT_ID"], $this->arParams["SECTION_ELEMENT_CODE"]);
         }
         if (!$section) {
             return array();
         }
         $viewedIterator = CatalogViewedProductTable::GetList(array('select' => array('PRODUCT_ID'), 'filter' => array('FUSER_ID' => $basketUserID, 'SITE_ID' => SITE_ID), 'order' => array('DATE_VISIT' => 'DESC'), 'limit' => self::MAX_VIEWED_COUNT));
         while ($viewedProduct = $viewedIterator->fetch()) {
             $ids[] = $viewedProduct['PRODUCT_ID'];
         }
         if (empty($ids)) {
             return array();
         }
         $mappedIds = CatalogViewedProductTable::getProductsMap($ids);
         if (empty($mappedIds)) {
             return array();
         }
         $elementIterator = CIBlockElement::getList(array(), array('ID' => array_values($mappedIds), 'IBLOCK_ID' => $this->arParams['IBLOCK_ID'], 'SECTION_ID' => $section, 'INCLUDE_SUBSECTIONS' => 'Y'), false, array('nTopCount' => $this->arParams['PAGE_ELEMENT_COUNT']), array('ID', 'IBLOCK_ID'));
         $ids = array();
         while ($element = $elementIterator->fetch()) {
             $ids[] = $element['ID'];
         }
         // resort by original
         $newIds = array();
         foreach ($mappedIds as $original => $mapped) {
             if (in_array($mapped, $ids)) {
                 $newIds[] = $mapped;
             }
         }
         $ids = $newIds;
     }
     return $ids;
 }
Пример #11
0
     $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();
Пример #12
0
     }
     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']) {
             $viewedProducts[$row['PRODUCT_ID']]['SORT_PRICE'] = $row['SORT_PRICE'];
             $viewedProducts[$row['PRODUCT_ID']]['PRICE'] = $row['PRICE'];
             $viewedProducts[$row['PRODUCT_ID']]['CURRENCY'] = $row['CURRENCY'];
             $viewedProducts[$row['PRODUCT_ID']]['CURRENCY_RATE'] = $row['CURRENCY_RATE'];
             $viewedProducts[$row['PRODUCT_ID']]['RATE'] = $row['RATE'];
         }
     }
 }
 unset($row);
 $productsMap = ViewedProducts::getProductsMap(array_keys($viewedProducts));
 // Group by Parent product id
 $groupViewedProducts = array();
 foreach ($viewedProducts as $product) {
     $parentId = $productsMap[$product['PRODUCT_ID']];
     if (!isset($groupViewedProducts[$parentId])) {
         $groupViewedProducts[$parentId] = $product;
     } else {
         $groupViewedProducts[$parentId]['VIEW_COUNT'] += $product['VIEW_COUNT'];
         // Min Price
         if ((double) $groupViewedProducts[$parentId]['SORT_PRICE'] > (double) $product['SORT_PRICE']) {
             $groupViewedProducts[$parentId]['PRICE'] = $product['PRICE'];
             $groupViewedProducts[$parentId]['CURRENCY'] = $product['CURRENCY'];
         }
     }
 }
Пример #13
0
 /**
  * Return viewed product ids map.
  *
  * @return array("KEY" => "VALUE")
  */
 protected function getProductIdsMap()
 {
     $map = array();
     $basketUserId = (int) CSaleBasket::GetBasketUserID(false);
     if ($basketUserId <= 0) {
         return array();
     }
     $useSectionFilter = $this->arParams["SHOW_FROM_SECTION"] == "Y";
     $sectionSearch = $this->arParams["SECTION_ID"] > 0 || $this->arParams["SECTION_CODE"] !== '';
     $sectionByItemSearch = $this->arParams["SECTION_ELEMENT_ID"] > 0 || $this->arParams["SECTION_ELEMENT_CODE"] !== '';
     if ($useSectionFilter && ($sectionSearch || $sectionByItemSearch)) {
         if ($sectionSearch) {
             $sectionId = $this->arParams["SECTION_ID"] > 0 ? $this->arParams["SECTION_ID"] : $this->getSectionIdByCode($this->arParams["SECTION_CODE"]);
         } else {
             $sectionId = $this->getSectionIdByElement($this->arParams["SECTION_ELEMENT_ID"], $this->arParams["SECTION_ELEMENT_CODE"]);
         }
         $map = CatalogViewedProductTable::getProductSkuMap($this->arParams['IBLOCK_ID'], $sectionId, $basketUserId, $this->arParams['SECTION_ELEMENT_ID'], $this->arParams['PAGE_ELEMENT_COUNT'], $this->arParams['DEPTH']);
     } else {
         $siteId = Main\Application::getInstance()->getContext()->getSite();
         $viewedIterator = CatalogViewedProductTable::GetList(array('select' => array('PRODUCT_ID', 'ELEMENT_ID'), 'filter' => array('FUSER_ID' => $basketUserId, 'SITE_ID' => $siteId, '!ELEMENT_ID' => array($this->arParams['SECTION_ELEMENT_ID'], 0)), 'order' => array('DATE_VISIT' => 'DESC'), 'limit' => $this->arParams['PAGE_ELEMENT_COUNT']));
         while ($viewedProduct = $viewedIterator->fetch()) {
             $map[$viewedProduct['PRODUCT_ID']] = $viewedProduct['ELEMENT_ID'];
         }
     }
     return $map;
 }
Пример #14
0
										$arTmp[] = $arCartWithoutSetItems[1];
										$arCartWithoutSetItems = $arTmp;
									}
									if ($basketCnt <= 0)
										$displayNoneBasket = "none";

									///
									$arViewed = array();
									$arViewedIds = array();
									$viewedCount = 0;
									$mapViewed = array();
									if (CModule::includeModule("catalog"))
									{
										$viewedIterator = \Bitrix\Catalog\CatalogViewedProductTable::getList(array(
											'order' => array("DATE_VISIT" => "DESC"),
											'filter' => array('FUSER_ID' => $arFuserItems["ID"], "SITE_ID" =>$arOrder["LID"] ),
											'select' => array("ID", "FUSER_ID", "DATE_VISIT", "PRODUCT_ID", "LID" => "SITE_ID", "NAME" => "ELEMENT.NAME", "PREVIEW_PICTURE" => "ELEMENT.PREVIEW_PICTURE", "DETAIL_PICTURE" => "ELEMENT.DETAIL_PICTURE" )
										));

										while($viewed = $viewedIterator->fetch())
										{
											$viewed['MODULE'] = 'catalog';
											$arViewed[$viewedCount] = $viewed;
											$arViewedIds[] = $viewed['PRODUCT_ID'];
											$mapViewed[$viewed['PRODUCT_ID']] = $viewedCount;
											$viewedCount++;
										}
										unset($viewedCount);
										$baseGroup = CCatalogGroup::getBaseGroup();
										if (!empty($arViewedIds))
										{
Пример #15
0
<?
define('NO_AGENT_CHECK', true);
define("STOP_STATISTICS", true);

use \Bitrix\Catalog\CatalogViewedProductTable as CatalogViewedProductTable;

require($_SERVER['DOCUMENT_ROOT'].'/bitrix/modules/main/include/prolog_before.php');
if (isset($_POST['AJAX']) && $_POST['AJAX'] == 'Y')
{
	if (isset($_POST['PRODUCT_ID']) && isset($_POST['SITE_ID']))
	{
		$productID = (int)$_POST['PRODUCT_ID'];
		$siteID = substr((string)$_POST['SITE_ID'], 0, 2);
		if ($productID > 0 && $siteID !== '' && \Bitrix\Main\Loader::includeModule('catalog') && \Bitrix\Main\Loader::includeModule('sale'))
		{
			CatalogViewedProductTable::refresh(
				$productID,
				CSaleBasket::GetBasketUserID(),
				$siteID
			);
			echo CUtil::PhpToJSObject(array("STATUS" => "SUCCESS"));
		}
		else
		{
			echo CUtil::PhpToJSObject(array("STATUS" => "ERROR", "TEXT" => "UNDEFINED PRODUCT"));
		}
	}
	die();
}
Пример #16
0
							}
						}
						$arShoppingCart = fDeleteDoubleProduct($arCartWithoutSetItems, $arFilterRecommended, 'N');
						if (empty($arShoppingCart["ITEMS"]))
							$displayNoneBasket = "none";


						//
						$viewedIterator = \Bitrix\Catalog\CatalogViewedProductTable::getList(
							array(
								"filter" => array("FUSER_ID" => $arFuserItems["ID"], "SITE_ID" => $str_LID),
								"select" => array(
									"ID",
									"PRODUCT_ID",
									"LID" => "SITE_ID",
									"NAME" => "ELEMENT.NAME",
									"PREVIEW_PICTURE" => "ELEMENT.PREVIEW_PICTURE",
									"DETAIL_PICTURE" => "ELEMENT.DETAIL_PICTURE",
								),
								"order" => array("DATE_VISIT" => "DESC"),
								"limit" => 10
							)
						);

						$viewed = array();
						while($row = $viewedIterator->fetch())
						{
							$row['MODULE'] = "catalog";
							$viewed[$row['PRODUCT_ID']] = $row;
						}
Пример #17
0
 /**
  * Get main data - viewed products.
  * @return void
  */
 protected function prepareData()
 {
     $this->fillUrlTemplates();
     $this->data = $this->getReferences();
     $this->prepareSystemData();
     $this->productIds = $this->getProductIds();
     if (is_null($this->productIds)) {
         $this->productIdsMap = $this->getProductIdsMap();
         $this->productIds = array_keys($this->productIdsMap);
     } else {
         $this->productIdsMap = Catalog\CatalogViewedProductTable::getProductsMap($this->productIds);
     }
     $this->iblockItems = array();
     $this->linkItems = array();
     $this->prepareFilter();
     $this->prepareSelectFields();
     $this->items = $this->getItems();
     $this->resortItemsByIds($this->productIds);
     $this->setItemsMeasure();
     $this->setItemsOffers();
     $this->setItemsPrices();
 }
Пример #18
0
<?php

// в модуле интернет-магазина нужно включить на стройку - "Использовать совместимость для просмотренных товаров каталога"
$countViewedProducts = 0;
$GLOBALS['arViewedProducts'] = array();
if (\Bitrix\Main\Loader::includeModule("catalog") && \Bitrix\Main\Loader::includeModule("sale")) {
    $arFilter["FUSER_ID"] = CSaleBasket::GetBasketUserID();
    if (\Bitrix\Main\Config\Option::get("sale", "viewed_capability", "") == "Y") {
        $viewedIterator = \Bitrix\Catalog\CatalogViewedProductTable::getList(array("filter" => $arFilter, "select" => array("ID", "PRODUCT_ID"), "order" => array("DATE_VISIT" => "DESC")));
        while ($row = $viewedIterator->fetch()) {
            $GLOBALS['arViewedProducts'][] = $row['PRODUCT_ID'];
            $countViewedProducts++;
        }
    }
}
Пример #19
0
 protected function getProductIds()
 {
     $ids = array();
     if (!empty($this->ajaxItemsIds)) {
         $recommendationId = Main\Context::getCurrent()->getRequest()->get('RID');
         $ids = $this->ajaxItemsIds;
     } else {
         $bestsellers = parent::getProductIds();
         if (!empty($bestsellers)) {
             $recommendationId = 'bestsellers';
             $ids = Main\Analytics\Catalog::getProductIdsByOfferIds($bestsellers);
         }
         if (empty($ids)) {
             $recommendationId = 'mostviewed';
             // top viewed
             $result = CatalogViewedProductTable::getList(array('select' => array('ELEMENT_ID', new Main\Entity\ExpressionField('SUM_HITS', 'SUM(%s)', 'VIEW_COUNT')), 'filter' => array('=SITE_ID' => SITE_ID, '>ELEMENT_ID' => 0), 'order' => array('SUM_HITS' => 'DESC'), 'limit' => $this->arParams['PAGE_ELEMENT_COUNT']));
             while ($row = $result->fetch()) {
                 $ids[] = $row['ELEMENT_ID'];
             }
         }
     }
     $ids = array_slice($ids, 0, $this->arParams['PAGE_ELEMENT_COUNT']);
     // remember recommendation id
     $this->arResult['RID'] = $recommendationId;
     return $ids;
 }