Ejemplo n.º 1
0
 /**
  * @inheritdoc
  */
 public function search(Criteria $criteria, StoreFrontBundle\Struct\ProductContextInterface $context)
 {
     $numberResult = $this->searchGateway->search($criteria, $context);
     $numbers = array_keys($numberResult->getProducts());
     $products = $this->productService->getList($numbers, $context);
     $products = $this->assignAttributes($products, $numberResult->getProducts());
     $result = new ProductSearchResult($products, $numberResult->getTotalCount(), $numberResult->getFacets());
     $result->addAttributes($numberResult->getAttributes());
     return $result;
 }
Ejemplo n.º 2
0
 /**
  * @param string $mode
  * @param int $category
  * @return int
  */
 protected function getRandomArticle($mode, $category = 0)
 {
     $category = (int) $category;
     $context = $this->contextService->getShopContext();
     if (empty($category)) {
         $category = $context->getShop()->getCategory()->getId();
     }
     $criteria = $this->storeFrontCriteriaFactory->createBaseCriteria([$category], $context);
     $criteria->offset(0);
     switch ($mode) {
         case 'top':
             $criteria->addSorting(new PopularitySorting(SortingInterface::SORT_DESC));
             $criteria->limit(10);
             break;
         case 'new':
             $criteria->addSorting(new ReleaseDateSorting(SortingInterface::SORT_DESC));
             $criteria->limit(1);
             break;
         default:
             $criteria->addSorting(new ReleaseDateSorting(SortingInterface::SORT_DESC));
             $criteria->limit(100);
     }
     $result = $this->productNumberSearch->search($criteria, $context);
     $ids = array_map(function (BaseProduct $product) {
         return $product->getId();
     }, $result->getProducts());
     $diff = array_diff($ids, $this->cachePromotions);
     if (empty($diff)) {
         $diff = $ids;
     }
     if ($mode == 'new') {
         $value = current($diff);
     } else {
         shuffle($diff);
         $value = $diff[array_rand($diff)];
     }
     $this->cachePromotions[] = $value;
     return $value;
 }