コード例 #1
0
ファイル: class.php プロジェクト: Satariall/izurit
 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;
 }
コード例 #2
0
ファイル: class.php プロジェクト: ASDAFF/1C_Bitrix_info_site
 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;
 }