示例#1
0
 /**
  * Return viewed product ids map.
  *
  * @return array("KEY" => "VALUE")
  */
 protected function getProductIdsMap()
 {
     $map = array();
     if (!Main\Loader::includeModule('sale')) {
         return 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 {
         $emptyProducts = array();
         $siteId = Main\Application::getInstance()->getContext()->getSite();
         $filter = array('FUSER_ID' => $basketUserId, 'SITE_ID' => $siteId);
         if ($this->arParams['SECTION_ELEMENT_ID'] > 0) {
             $filter['!ELEMENT_ID'] = $this->arParams['SECTION_ELEMENT_ID'];
         }
         $viewedIterator = CatalogViewedProductTable::GetList(array('select' => array('PRODUCT_ID', 'ELEMENT_ID'), 'filter' => $filter, 'order' => array('DATE_VISIT' => 'DESC'), 'limit' => $this->arParams['PAGE_ELEMENT_COUNT']));
         unset($filter);
         while ($viewedProduct = $viewedIterator->fetch()) {
             $viewedProduct['ELEMENT_ID'] = (int) $viewedProduct['ELEMENT_ID'];
             $viewedProduct['PRODUCT_ID'] = (int) $viewedProduct['PRODUCT_ID'];
             $map[$viewedProduct['PRODUCT_ID']] = $viewedProduct['ELEMENT_ID'];
             if ($viewedProduct['ELEMENT_ID'] <= 0) {
                 $emptyProducts[] = $viewedProduct['PRODUCT_ID'];
             }
         }
         if (!empty($emptyProducts)) {
             $emptyProducts = CatalogViewedProductTable::getProductsMap($emptyProducts);
             if (!empty($emptyProducts)) {
                 foreach ($emptyProducts as $product => $parent) {
                     if ($parent == $this->arParams['SECTION_ELEMENT_ID']) {
                         unset($map[$product]);
                     } else {
                         $map[$product] = $parent;
                     }
                 }
             }
         }
     }
     return $map;
 }
示例#2
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;
 }