Skip to content

Commit b2068a5

Browse files
author
Silvan Laroo
committed
Fixed price displaying 0, added screenshot
1 parent b0d73c6 commit b2068a5

File tree

5 files changed

+33
-25
lines changed

5 files changed

+33
-25
lines changed

Model/Autocomplete/SearchDataProvider.php

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,16 @@
1212
*/
1313
namespace Sebwite\SmartSearch\Model\Autocomplete;
1414

15-
use Magento\Framework\Pricing\PriceCurrencyInterface;
16-
use Magento\Search\Model\QueryFactory;
17-
use Magento\Search\Model\Autocomplete\DataProviderInterface;
18-
use Magento\Search\Model\Autocomplete\ItemFactory;
15+
use Magento\Catalog\Api\ProductRepositoryInterface;
16+
use Magento\Framework\Api\FilterBuilder;
17+
use Magento\Framework\Api\Search\FilterGroupBuilder;
1918
use Magento\Framework\Api\Search\SearchCriteriaFactory as FullTextSearchCriteriaFactory;
2019
use Magento\Framework\Api\Search\SearchInterface as FullTextSearchApi;
21-
use Magento\Framework\Api\Search\FilterGroupBuilder;
22-
use Magento\Framework\Api\FilterBuilder;
2320
use Magento\Framework\Api\SearchCriteriaBuilder;
24-
use Magento\Catalog\Api\ProductRepositoryInterface;
21+
use Magento\Framework\Pricing\PriceCurrencyInterface;
22+
use Magento\Search\Model\Autocomplete\DataProviderInterface;
23+
use Magento\Search\Model\Autocomplete\ItemFactory;
24+
use Magento\Search\Model\QueryFactory;
2525
use Magento\Store\Model\StoreManagerInterface;
2626

2727
/**
@@ -62,20 +62,24 @@ class SearchDataProvider implements DataProviderInterface
6262
* @var PriceCurrencyInterface
6363
*/
6464
private $priceCurrency;
65+
/**
66+
* @var ProductHelper
67+
*/
68+
private $productHelper;
6569

6670
/**
6771
* Initialize dependencies.
6872
*
69-
* @param QueryFactory $queryFactory
70-
* @param ItemFactory $itemFactory
71-
* @param FullTextSearchApi $search
72-
* @param FullTextSearchCriteriaFactory $searchCriteriaFactory
73-
* @param FilterGroupBuilder $searchFilterGroupBuilder
74-
* @param FilterBuilder $filterBuilder
75-
* @param ProductRepositoryInterface $productRepository
76-
* @param SearchCriteriaBuilder $searchCriteriaBuilder
77-
* @param StoreManagerInterface $storeManager
78-
* @param \Magento\Framework\Pricing\PriceCurrencyInterface $priceCurrency
73+
* @param QueryFactory $queryFactory
74+
* @param ItemFactory $itemFactory
75+
* @param FullTextSearchApi $search
76+
* @param FullTextSearchCriteriaFactory $searchCriteriaFactory
77+
* @param FilterGroupBuilder $searchFilterGroupBuilder
78+
* @param FilterBuilder $filterBuilder
79+
* @param ProductRepositoryInterface $productRepository
80+
* @param SearchCriteriaBuilder $searchCriteriaBuilder
81+
* @param StoreManagerInterface $storeManager
82+
* @param \Magento\Framework\Pricing\PriceCurrencyInterface $priceCurrency
7983
*/
8084
public function __construct(
8185
QueryFactory $queryFactory,
@@ -121,13 +125,8 @@ public function getItems()
121125

122126
foreach ($products->getItems() as $product) {
123127

124-
// $price = number_format($product->getPrice(), 2);
125-
// $product->getFormatedPrice();
126128
$resultItem = $this->itemFactory->create([
127-
128-
/** Feel free to add here necessary product data and then render in template */
129-
'title' => $product->getName(),
130-
'price' => $this->priceCurrency->format($product->getPrice(), false),
129+
'title' => $product->getName(), 'price' => $this->priceCurrency->format($product->getFinalPrice(), false),
131130
'special_price' => $this->priceCurrency->format($product->getSpecialPrice(), false),
132131
'has_special_price' => $product->getSpecialPrice() > 0 ? true : false,
133132
'image' => str_replace('index.php/', '', $baseUrl) . '/pub/media/catalog/product' . $product->getImage(),
@@ -149,6 +148,7 @@ public function getItems()
149148
private function searchProductsFullText($query)
150149
{
151150
$searchCriteria = $this->fullTextSearchCriteriaFactory->create();
151+
152152
/** To get list of available request names see Magento/CatalogSearch/etc/search_request.xml */
153153
$searchCriteria->setRequestName('quick_search_container');
154154
$filter = $this->filterBuilder->setField('search_term')->setValue($query)->setConditionType('like')->create();

README.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,20 @@
11
# Magento 2.0 SmartSearch
2-
Magento 2 SmartSearch implementation. This is a basic extension without any config options that replaces the default Magento autocomplete with a smart search implementation.
2+
Magento 2 type ahead search implementation. Shows a list of found products under the searchbar without reloading the page.
3+
This is a basic extension without any config options that replaces the default Magento autocomplete with a smart search implementation.
34

45
## Installation with composer
56
* Include the repository: `composer require sebwite/magento2-smartsearch`
67
* Enable the extension: `php bin/magento --clear-static-content module:enable Sebwite_SmartSearch`
78
* Upgrade db scheme: `php bin/magento setup:upgrade`
89
* Clear cache
910

11+
## Installation without composer
12+
* Download zip file of this extension
13+
* Place all the files of the extension in your Magento 2 installation in the folder app/code/Sebwite/SmartSearch
14+
* Enable the extension: `php bin/magento --clear-static-content module:enable Sebwite_SmartSearch`
15+
* Upgrade db scheme: `php bin/magento setup:upgrade`
16+
* Clear cache
17+
1018
After these steps the default Magento 2 searchbar will be transformed into a smartsearch searchbar.
1119

1220
##Todo's:

composer.json

100755100644
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "sebwite/magento2-smartsearch",
33
"description": "Magento 2.0 SmartSearch",
44
"type": "magento2-module",
5-
"version": "1.0.0",
5+
"version": "1.0.1",
66
"license": [
77
"OSL-3.0",
88
"AFL-3.0"

etc/module.xml

100755100644
File mode changed.

screenshot.png

277 KB
Loading

0 commit comments

Comments
 (0)