-
Notifications
You must be signed in to change notification settings - Fork 340
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'romainruaud-fix_refactor-autocomplete-module'
- Loading branch information
Showing
25 changed files
with
293 additions
and
169 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 0 additions & 42 deletions
42
src/module-elasticsuite-catalog-autocomplete/composer.json
This file was deleted.
Oops, something went wrong.
25 changes: 0 additions & 25 deletions
25
src/module-elasticsuite-catalog-autocomplete/etc/module.xml
This file was deleted.
Oops, something went wrong.
20 changes: 0 additions & 20 deletions
20
src/module-elasticsuite-catalog-autocomplete/registration.php
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,28 +6,34 @@ | |
* versions in the future. | ||
* | ||
* @category Smile | ||
* @package Smile_ElasticSuiteCatalogAutocomplete | ||
* @package Smile_ElasticSuiteCatalog | ||
* @author Aurelien FOUCRET <[email protected]> | ||
* @copyright 2016 Smile | ||
* @license Open Software License ("OSL") v. 3.0 | ||
*/ | ||
namespace Smile\ElasticSuiteCatalogAutocomplete\Model\Autocomplete\Product; | ||
namespace Smile\ElasticSuiteCatalog\Model\Autocomplete\Product; | ||
|
||
use Magento\Search\Model\Autocomplete\DataProviderInterface; | ||
use Magento\Search\Model\Autocomplete\ItemFactory; | ||
use Magento\Search\Model\QueryFactory; | ||
use Smile\ElasticSuiteCatalogAutocomplete\Model\Autocomplete\Terms\DataProvider as TermDataProvider; | ||
use Smile\ElasticSuiteCore\Helper\Autocomplete as ConfigurationHelper; | ||
use Smile\ElasticSuiteCatalog\Model\ResourceModel\Product\Fulltext\CollectionFactory as ProductCollectionFactory; | ||
use Smile\ElasticSuiteCore\Model\Autocomplete\Terms\DataProvider as TermDataProvider; | ||
|
||
/** | ||
* Catalog product autocomplete data provider. | ||
* | ||
* @category Smile | ||
* @package Smile_ElasticSuiteCatalogAutocomplete | ||
* @package Smile_ElasticSuiteCatalog | ||
* @author Aurelien FOUCRET <[email protected]> | ||
*/ | ||
class DataProvider implements DataProviderInterface | ||
{ | ||
/** | ||
* Autocomplete type | ||
*/ | ||
const AUTOCOMPLETE_TYPE = "product"; | ||
|
||
/** | ||
* Autocomplete result item factory | ||
* | ||
|
@@ -57,6 +63,16 @@ class DataProvider implements DataProviderInterface | |
*/ | ||
protected $imageHelper; | ||
|
||
/** | ||
* @var ConfigurationHelper | ||
*/ | ||
protected $configurationHelper; | ||
|
||
/** | ||
* @var string Autocomplete result type | ||
*/ | ||
private $type; | ||
|
||
/** | ||
* Constructor. | ||
* | ||
|
@@ -65,20 +81,35 @@ class DataProvider implements DataProviderInterface | |
* @param TermDataProvider $termDataProvider Search terms suggester. | ||
* @param ProductCollectionFactory $productCollectionFactory Product collection factory. | ||
* @param \Magento\Catalog\Helper\Product $productHelper Catalog Image helper. | ||
* @param ConfigurationHelper $configurationHelper Autocomplete configuration helper. | ||
* @param string $type Autocomplete provider type. | ||
*/ | ||
public function __construct( | ||
ItemFactory $itemFactory, | ||
QueryFactory $queryFactory, | ||
TermDataProvider $termDataProvider, | ||
ProductCollectionFactory $productCollectionFactory, | ||
\Magento\Catalog\Helper\Product $productHelper | ||
\Magento\Catalog\Helper\Product $productHelper, | ||
ConfigurationHelper $configurationHelper, | ||
$type = self::AUTOCOMPLETE_TYPE | ||
) { | ||
$this->itemFactory = $itemFactory; | ||
$this->queryFactory = $queryFactory; | ||
$this->termDataProvider = $termDataProvider; | ||
$this->productCollectionFactory = $productCollectionFactory; | ||
$this->imageHelper = $productHelper; | ||
$this->configurationHelper = $configurationHelper; | ||
$this->type = $type; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getType() | ||
{ | ||
return $this->type; | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
|
@@ -87,7 +118,6 @@ public function getItems() | |
$result = []; | ||
$productCollection = $this->getProductCollection(); | ||
if ($productCollection) { | ||
\Magento\Catalog\Model\Product::ATTRIBUTE_SET_ID; | ||
foreach ($productCollection as $product) { | ||
$result[] = $this->itemFactory->create( | ||
[ | ||
|
@@ -96,7 +126,7 @@ public function getItems() | |
'url' => $product->getProductUrl(), | ||
'price' => $product->getFinalPrice(), | ||
'final_price' => $product->getPrice(), // The getPrice method returns always 0. | ||
'type' => 'product', | ||
'type' => $this->getType(), | ||
] | ||
); | ||
} | ||
|
@@ -140,12 +170,22 @@ private function getProductCollection() | |
|
||
$productCollection = $this->productCollectionFactory->create(); | ||
$productCollection->addSearchFilter($terms); | ||
$productCollection->setPageSize(5); | ||
$productCollection->setPageSize($this->getResultsPageSize()); | ||
$productCollection | ||
->addAttributeToSelect('name') | ||
->addAttributeToSelect('small_image') | ||
->addPriceData(); | ||
|
||
return $productCollection; | ||
} | ||
|
||
/** | ||
* Retrieve number of products to display in autocomplete results | ||
* | ||
* @return int | ||
*/ | ||
private function getResultsPageSize() | ||
{ | ||
return $this->configurationHelper->getMaxSize($this->getType()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<!-- | ||
/** | ||
* Smile ElasticSuiteCatalog module configuration | ||
* | ||
* DISCLAIMER | ||
* | ||
* Do not edit or add to this file if you wish to upgrade Smile Searchandising Suite to newer | ||
* versions in the future. | ||
* | ||
* @category Smile | ||
* @package Smile_ElasticSuiteCatalog | ||
* @author Romain RUAUD <[email protected]> | ||
* @copyright 2016 Smile | ||
* @license Apache License Version 2.0 | ||
*/ | ||
--> | ||
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Config:etc/system_file.xsd"> | ||
<system> | ||
<section id="smile_elasticsuite_core_autocomplete_settings"> | ||
<group id="product_autocomplete" translate="label" type="text" sortOrder="20" showInDefault="1" showInWebsite="1" showInStore="1"> | ||
<label>Product Autocomplete</label> | ||
<field id="max_size" translate="label" type="text" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1"> | ||
<label>Max size</label> | ||
<validate>integer</validate> | ||
<comment><![CDATA[Maximum number of products to display in autocomplete results.]]></comment> | ||
</field> | ||
</group> | ||
</section> | ||
</system> | ||
</config> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,7 @@ | |
* | ||
* | ||
* @category Smile | ||
* @package Smile_ElasticSuiteCatalogAutocomplete | ||
* @package Smile_ElasticSuiteCatalog | ||
* @author Romain Ruaud <[email protected]> | ||
* @copyright 2016 Smile | ||
* @license Open Software License ("OSL") v. 3.0 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,7 @@ | |
* | ||
* | ||
* @category Smile | ||
* @package Smile_ElasticSuiteCatalogAutocomplete | ||
* @package Smile_ElasticSuiteCatalog | ||
* @author Romain Ruaud <[email protected]> | ||
* @copyright 2016 Smile | ||
* @license Open Software License ("OSL") v. 3.0 | ||
|
Oops, something went wrong.