/** * @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; }
/** * @inheritdoc */ public function getList(array $numbers, Struct\ProductContextInterface $context) { $products = $this->service->getList($numbers, $context); $categories = $this->seoCategoryService->getList($products, $context); /**@var $product Struct\ListProduct*/ foreach ($products as $product) { $productId = $product->getId(); if (!isset($categories[$productId])) { continue; } $attribute = new Struct\Attribute(['category' => $categories[$productId]]); $product->addAttribute('swag_plugin_system', $attribute); } return $products; }
/** * @inheritdoc */ public function getList($products, Struct\ProductContextInterface $context) { /** * returns an array which is associated with the different product numbers. * Each array contains a list of product numbers which are related to the reference product. */ $numbers = $this->gateway->getList($products); //loads the list product data for the selected numbers. //all numbers are joined in the extractNumbers function to prevent that a product will be //loaded multiple times $listProducts = $this->listProductService->getList($this->extractNumbers($numbers), $context); $result = []; foreach ($products as $product) { if (!isset($numbers[$product->getId()])) { continue; } $result[$product->getNumber()] = $this->getProductsByNumbers($listProducts, $numbers[$product->getId()]); } return $result; }
/** * @param array $numbers * @param Struct\ProductContextInterface $context * @return Struct\ListProduct[] */ public function getList(array $numbers, Struct\ProductContextInterface $context) { $getSortedNumbers = $this->sortingComponent->sortByNumber($numbers); $products = $this->coreService->getList($getSortedNumbers, $context); return $products; }