Skip to content

Commit

Permalink
Fixed price displaying 0, added screenshot
Browse files Browse the repository at this point in the history
  • Loading branch information
Silvan Laroo committed Jan 15, 2016
1 parent b0d73c6 commit b2068a5
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 25 deletions.
46 changes: 23 additions & 23 deletions Model/Autocomplete/SearchDataProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@
*/
namespace Sebwite\SmartSearch\Model\Autocomplete;

use Magento\Framework\Pricing\PriceCurrencyInterface;
use Magento\Search\Model\QueryFactory;
use Magento\Search\Model\Autocomplete\DataProviderInterface;
use Magento\Search\Model\Autocomplete\ItemFactory;
use Magento\Catalog\Api\ProductRepositoryInterface;
use Magento\Framework\Api\FilterBuilder;
use Magento\Framework\Api\Search\FilterGroupBuilder;
use Magento\Framework\Api\Search\SearchCriteriaFactory as FullTextSearchCriteriaFactory;
use Magento\Framework\Api\Search\SearchInterface as FullTextSearchApi;
use Magento\Framework\Api\Search\FilterGroupBuilder;
use Magento\Framework\Api\FilterBuilder;
use Magento\Framework\Api\SearchCriteriaBuilder;
use Magento\Catalog\Api\ProductRepositoryInterface;
use Magento\Framework\Pricing\PriceCurrencyInterface;
use Magento\Search\Model\Autocomplete\DataProviderInterface;
use Magento\Search\Model\Autocomplete\ItemFactory;
use Magento\Search\Model\QueryFactory;
use Magento\Store\Model\StoreManagerInterface;

/**
Expand Down Expand Up @@ -62,20 +62,24 @@ class SearchDataProvider implements DataProviderInterface
* @var PriceCurrencyInterface
*/
private $priceCurrency;
/**
* @var ProductHelper
*/
private $productHelper;

/**
* Initialize dependencies.
*
* @param QueryFactory $queryFactory
* @param ItemFactory $itemFactory
* @param FullTextSearchApi $search
* @param FullTextSearchCriteriaFactory $searchCriteriaFactory
* @param FilterGroupBuilder $searchFilterGroupBuilder
* @param FilterBuilder $filterBuilder
* @param ProductRepositoryInterface $productRepository
* @param SearchCriteriaBuilder $searchCriteriaBuilder
* @param StoreManagerInterface $storeManager
* @param \Magento\Framework\Pricing\PriceCurrencyInterface $priceCurrency
* @param QueryFactory $queryFactory
* @param ItemFactory $itemFactory
* @param FullTextSearchApi $search
* @param FullTextSearchCriteriaFactory $searchCriteriaFactory
* @param FilterGroupBuilder $searchFilterGroupBuilder
* @param FilterBuilder $filterBuilder
* @param ProductRepositoryInterface $productRepository
* @param SearchCriteriaBuilder $searchCriteriaBuilder
* @param StoreManagerInterface $storeManager
* @param \Magento\Framework\Pricing\PriceCurrencyInterface $priceCurrency
*/
public function __construct(
QueryFactory $queryFactory,
Expand Down Expand Up @@ -121,13 +125,8 @@ public function getItems()

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

// $price = number_format($product->getPrice(), 2);
// $product->getFormatedPrice();
$resultItem = $this->itemFactory->create([

/** Feel free to add here necessary product data and then render in template */
'title' => $product->getName(),
'price' => $this->priceCurrency->format($product->getPrice(), false),
'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(),
Expand All @@ -149,6 +148,7 @@ public function getItems()
private function searchProductsFullText($query)
{
$searchCriteria = $this->fullTextSearchCriteriaFactory->create();

/** To get list of available request names see Magento/CatalogSearch/etc/search_request.xml */
$searchCriteria->setRequestName('quick_search_container');
$filter = $this->filterBuilder->setField('search_term')->setValue($query)->setConditionType('like')->create();
Expand Down
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
# Magento 2.0 SmartSearch
Magento 2 SmartSearch implementation. This is a basic extension without any config options that replaces the default Magento autocomplete with a smart search implementation.
Magento 2 type ahead search implementation. Shows a list of found products under the searchbar without reloading the page.
This is a basic extension without any config options that replaces the default Magento autocomplete with a smart search implementation.

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

## Installation without composer
* Download zip file of this extension
* Place all the files of the extension in your Magento 2 installation in the folder app/code/Sebwite/SmartSearch
* Enable the extension: `php bin/magento --clear-static-content module:enable Sebwite_SmartSearch`
* Upgrade db scheme: `php bin/magento setup:upgrade`
* Clear cache

After these steps the default Magento 2 searchbar will be transformed into a smartsearch searchbar.

##Todo's:
Expand Down
2 changes: 1 addition & 1 deletion composer.json
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "sebwite/magento2-smartsearch",
"description": "Magento 2.0 SmartSearch",
"type": "magento2-module",
"version": "1.0.0",
"version": "1.0.1",
"license": [
"OSL-3.0",
"AFL-3.0"
Expand Down
Empty file modified etc/module.xml
100755 → 100644
Empty file.
Binary file added screenshot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit b2068a5

Please sign in to comment.