Esempio n. 1
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();
 }
Esempio n. 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;
 }
Esempio n. 3
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();
 }
Esempio n. 4
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'];
         }
     }
 }