示例#1
0
 public static function submitData($limit = 5)
 {
     if (!Catalog::isOn()) {
         return '\\' . __METHOD__ . '(5);';
     }
     $ids = array();
     $rows = array();
     $r = static::getList(array('order' => array('ID' => 'ASC'), 'limit' => $limit));
     while ($row = $r->fetch()) {
         $rows[] = array('type' => $row['TYPE'], 'data' => $row['DATA']);
         $ids[] = $row['ID'];
     }
     if (!empty($rows)) {
         // get queue size
         $totalCount = static::getCount();
         $queueSize = $totalCount > $limit ? $totalCount - $limit : 0;
         // send data
         $data = \http_build_query(array('op' => 'e', 'aid' => Counter::getAccountId(), 'ad[cd][value]' => base64_encode(json_encode($rows)), 'ad[cd][queue]' => $queueSize));
         if (strlen($data) > 30000) {
             if ($limit > 1) {
                 return '\\' . __METHOD__ . '(' . max(1, $limit - 1) . ');';
             }
         }
         $f = fsockopen('bitrix.info', 80, $errno, $errstr, 3);
         if ($f) {
             $out = "POST /bx_stat HTTP/1.1\r\n";
             $out .= "Host: bitrix.info\r\n";
             $out .= "Content-type: application/x-www-form-urlencoded\r\n";
             $out .= "Content-length: " . strlen($data) . "\r\n";
             $out .= "User-Agent: Bitrix Stats Counter\r\n";
             $out .= "Connection: Close\r\n";
             $out .= "\r\n";
             $out .= $data . "\r\n\r\n";
             fwrite($f, $out);
             $response = '';
             while (!feof($f)) {
                 $response .= fgets($f, 128);
             }
             fclose($f);
             // delete rows if service received data
             if (strpos($response, 'uid')) {
                 foreach ($ids as $id) {
                     static::delete($id);
                 }
             }
         }
     }
     return '\\' . __METHOD__ . '(5);';
 }
示例#2
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;
 }
示例#3
0
	else
	{
		$this->AbortResultCache();
		ShowError(GetMessage("CATALOG_ELEMENT_NOT_FOUND"));
		@define("ERROR_404", "Y");
		if($arParams["SET_STATUS_404"]==="Y")
			CHTTP::SetStatus("404 Not Found");
	}
}

if(isset($arResult["ID"]))
{
	if (isset($arResult['counterData']))
	{
		// send counter data
		if (\Bitrix\Main\Analytics\Catalog::isOn())
		{
			\Bitrix\Main\Analytics\Counter::sendData('ct', $arResult['counterData']);
		}
	}

	if ('N' != $arParams['USE_ELEMENT_COUNTER'])
	{
		if (Loader::includeModule('iblock'))
		{
			CIBlockElement::CounterInc($arResult["ID"]);
		}
	}

	if (!isset($_SESSION["VIEWED_ENABLE"]) && isset($_SESSION["VIEWED_PRODUCT"]) && $_SESSION["VIEWED_PRODUCT"] != $arResult["ID"] && Loader::includeModule("sale"))
	{
示例#4
0
?>
			</div>
			<div class="clb"></div>
		</div>
	</div>

	<div class="adm-c-bigdata-activate">
		<div class="adm-c-bigdata-activate-title"><?php 
echo GetMessage('BIGDATA_HOWTO_ENABLE');
?>
</div>
		<div class="adm-c-bigdata-activate-content">
			<ul class="adm-c-bigdata-activate-content-task-list">

				<?php 
$available = \Bitrix\Main\Analytics\Catalog::isOn();
?>
				<li <?php 
echo $available ? 'class="good"' : '';
?>
>
					<?php 
echo GetMessage('BIGDATA_ENABLED');
?>
					<?php 
if (!$available) {
    ?>
						<div class="adm-c-bigdata-activate-content-task-list-warning"><span><?php 
    echo GetMessage('BIGDATA_DISABLED');
    ?>
</span></div>
 /**
  * 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;
     }
 }
示例#6
0
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
			);
示例#7
0
 public static function submitData($limit = 50)
 {
     if (!Catalog::isOn()) {
         return '\\' . __METHOD__ . '();';
     }
     $rows = array();
     $r = static::getList(array('order' => array('ID' => 'ASC'), 'limit' => $limit));
     while ($row = $r->fetch()) {
         $rows[$row['ID']] = array('type' => $row['TYPE'], 'data' => $row['DATA']);
     }
     if (!empty($rows)) {
         // get queue size
         $totalCount = static::getCount();
         $queueSize = $totalCount > $limit ? $totalCount - $limit : 0;
         // set limit
         $dataSizeLimit = 45000;
         // make an optimal dataset
         $dataSize = strlen(base64_encode(json_encode(array_values($rows))));
         // records to delete
         $toDelete = array();
         if ($dataSize > $dataSizeLimit) {
             $reducedRows = array();
             foreach ($rows as $id => $row) {
                 $rowSize = strlen(base64_encode(json_encode(array_values($row))));
                 $reducedDataSize = strlen(base64_encode(json_encode(array_values($reducedRows))));
                 if ($rowSize > $dataSizeLimit) {
                     // abnormally big row, delete it
                     $toDelete[] = $id;
                 } elseif (!empty($reducedRows) && $reducedDataSize + $rowSize > $dataSizeLimit) {
                     // it's enough
                     break;
                 } else {
                     $reducedRows[$id] = $row;
                 }
             }
             $rows = $reducedRows;
         }
         if (!empty($rows)) {
             // if there are still some data, send it
             $data = \http_build_query(array('op' => 'e', 'aid' => Counter::getAccountId(), 'ad[cd][value]' => base64_encode(json_encode(array_values($rows))), 'ad[cd][queue]' => $queueSize));
             $f = fsockopen('bitrix.info', 80, $errno, $errstr, 3);
             if ($f) {
                 $out = "POST /bx_stat HTTP/1.1\r\n";
                 $out .= "Host: bitrix.info\r\n";
                 $out .= "Content-type: application/x-www-form-urlencoded\r\n";
                 $out .= "Content-length: " . strlen($data) . "\r\n";
                 $out .= "User-Agent: Bitrix Stats Counter\r\n";
                 $out .= "Connection: Close\r\n";
                 $out .= "\r\n";
                 $out .= $data . "\r\n\r\n";
                 fwrite($f, $out);
                 $response = '';
                 while (!feof($f)) {
                     $response .= fgets($f, 128);
                 }
                 fclose($f);
                 // delete rows if service received data
                 if (strpos($response, '200 OK')) {
                     $toDelete = array_merge($toDelete, array_keys($rows));
                 }
             }
         }
         // delete abnormally big and sent rows
         foreach ($toDelete as $id) {
             static::delete($id);
         }
     }
     return '\\' . __METHOD__ . '();';
 }
示例#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';
             // 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;
 }