Пример #1
0
 /**
  * {@inheritdoc}
  */
 public function getItems()
 {
     $collection = $this->getSuggestCollection();
     $query = $this->queryFactory->get()->getQueryText();
     $result = [];
     foreach ($collection as $item) {
         $resultItem = $this->itemFactory->create(['title' => $item->getQueryText(), 'num_results' => $item->getNumResults()]);
         if ($resultItem->getTitle() == $query) {
             array_unshift($result, $resultItem);
         } else {
             $result[] = $resultItem;
         }
     }
     return $result;
 }
Пример #2
0
 /**
  * {@inheritDoc}
  */
 public function create(array $data)
 {
     $data['title'] = $data['value'];
     $data['url'] = $this->getUrl($data);
     unset($data['value']);
     return parent::create($data);
 }
Пример #3
0
 /**
  * {@inheritdoc}
  */
 public function getItems()
 {
     if ($this->items === null) {
         $collection = $this->getSuggestCollection();
         $this->items = [];
         foreach ($collection as $item) {
             $resultItem = $this->itemFactory->create(['title' => $item->getQueryText(), 'num_results' => $item->getNumResults(), 'type' => $this->getType()]);
             $this->items[] = $resultItem;
         }
     }
     return $this->items;
 }
 /**
  * getItems method
  *
  * @return array
  */
 public function getItems()
 {
     $result = [];
     $query = $this->queryFactory->get()->getQueryText();
     $productIds = $this->searchProductsFullText($query);
     // Check if products are found
     if ($productIds) {
         $searchCriteria = $this->searchCriteriaBuilder->addFilter('entity_id', $productIds, 'in')->create();
         $products = $this->productRepository->getList($searchCriteria);
         foreach ($products->getItems() as $product) {
             $image = $this->imageHelper->init($product, 'product_page_image_small')->getUrl();
             $resultItem = $this->itemFactory->create(['title' => $product->getName(), 'price' => $this->priceCurrency->format($product->getPriceInfo()->getPrice('regular_price')->getAmount()->getValue(), false), 'special_price' => $this->priceCurrency->format($product->getPriceInfo()->getPrice('special_price')->getAmount()->getValue(), false), 'has_special_price' => $product->getSpecialPrice() > 0 ? true : false, 'image' => $image, 'url' => $product->getProductUrl()]);
             $result[] = $resultItem;
         }
     }
     return $result;
 }
 /**
  * {@inheritdoc}
  */
 public function getItems()
 {
     $result = [];
     $query = $this->queryFactory->get()->getQueryText();
     $productIds = $this->searchProductsFullText($query);
     // Check if products are found
     if ($productIds) {
         $searchCriteria = $this->searchCriteriaBuilder->addFilter('entity_id', $productIds, 'in')->create();
         $products = $this->productRepository->getList($searchCriteria);
         $baseUrl = $this->storeManager->getStore()->getBaseUrl();
         // Loop through products
         foreach ($products->getItems() as $product) {
             $resultItem = $this->itemFactory->create(['title' => $product->getName(), 'price' => $this->priceCurrency->format($product->getFinalPrice(), false), 'special_price' => $this->priceCurrency->format($product->getSpecialPrice(), false), 'has_special_price' => $product->getSpecialPrice() > 0 ? true : false, 'image' => str_replace('index.php/', '', $baseUrl) . '/pub/media/catalog/product' . $product->getImage(), 'url' => $product->getProductUrl()]);
             $result[] = $resultItem;
         }
     }
     return $result;
 }
Пример #6
0
 /**
  * {@inheritDoc}
  */
 public function create(array $data)
 {
     $data = $this->addCategoryData($data);
     unset($data['category']);
     return parent::create($data);
 }
Пример #7
0
 /**
  * {@inheritDoc}
  */
 public function create(array $data)
 {
     $data = $this->addProductData($data);
     unset($data['product']);
     return parent::create($data);
 }