예제 #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
파일: catalog.php 프로젝트: rasuldev/torino
 public static function catchCatalogBasket($id, $arFields)
 {
     if (!static::isOn()) {
         return;
     }
     // select site user id
     $siteUserId = 0;
     if (\COption::GetOptionString("sale", "encode_fuser_id", "N") == "Y") {
         $filter = array('CODE' => $arFields['FUSER_ID']);
     } else {
         $filter = array('ID' => $arFields['FUSER_ID']);
     }
     $result = \CSaleUser::getList($filter);
     if (!empty($result)) {
         $siteUserId = $result['USER_ID'];
     }
     // prepare data
     $data = array('product_id' => $arFields['PRODUCT_ID'], 'user_id' => $siteUserId, 'bx_user_id' => static::getBxUserId(), 'domain' => Context::getCurrent()->getServer()->getHttpHost(), 'recommendation' => '0', 'date' => date(DATE_ISO8601));
     CounterDataTable::add(array('TYPE' => 'basket', 'DATA' => $data));
 }
예제 #3
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);
     }
 }