diff --git a/composer.json b/composer.json index c1f18b161..a64bc64bc 100644 --- a/composer.json +++ b/composer.json @@ -38,8 +38,7 @@ "smile-sa/module-elasticsuite-catalog": "self.version", "smile-sa/module-elasticsuite-swatches": "self.version", "smile-sa/module-elasticsuite-thesaurus": "self.version", - "smile-sa/module-elasticsuite-tracker": "self.version", - "smile-sa/module-elasticsuite-catalog-autocomplete": "self.version" + "smile-sa/module-elasticsuite-tracker": "self.version" }, "require-dev": { "phpunit/phpunit": "*", @@ -56,16 +55,14 @@ "src/module-elasticsuite-catalog/registration.php", "src/module-elasticsuite-swatches/registration.php", "src/module-elasticsuite-thesaurus/registration.php", - "src/module-elasticsuite-tracker/registration.php", - "src/module-elasticsuite-catalog-autocomplete/registration.php" + "src/module-elasticsuite-tracker/registration.php" ], "psr-4" : { "Smile\\ElasticSuiteCore\\" : "src/module-elasticsuite-core", "Smile\\ElasticSuiteCatalog\\" : "src/module-elasticsuite-catalog", "Smile\\ElasticSuiteSwatches\\" : "src/module-elasticsuite-swatches", "Smile\\ElasticSuiteThesaurus\\" : "src/module-elasticsuite-thesaurus", - "Smile\\ElasticSuiteTracker\\" : "src/module-elasticsuite-tracker", - "Smile\\ElasticSuiteCatalogAutocomplete\\" : "src/module-elasticsuite-catalog-autocomplete" + "Smile\\ElasticSuiteTracker\\" : "src/module-elasticsuite-tracker" } }, "extra": { diff --git a/src/module-elasticsuite-catalog-autocomplete/composer.json b/src/module-elasticsuite-catalog-autocomplete/composer.json deleted file mode 100644 index c86a2ffc3..000000000 --- a/src/module-elasticsuite-catalog-autocomplete/composer.json +++ /dev/null @@ -1,42 +0,0 @@ -{ - "name" : "smile-sa/module-elasticsuite-catalog-autocomplete", - "type" : "magento2-module", - "license" : "OSL-3.0", - "authors" : [{ - "name" : "Aurélien FOUCRET", - "email" : "aurelien.foucret@smile.fr" - }, - { - "name" : "Romain RUAUD", - "email" : "romain.ruaud@smile.fr" - } - ], - "description" : "Smile ElasticSuite - Catalog search module.", - "homepage" : "https://github.com/Smile-SA/module-elasticsuite-catalog-autocomplete", - "keywords" : [ - "magento", - "magento2", - "elasticsearch", - "search", - "merchandising", - "core", - "setup" - ], - "require" : { - "magento/framework" : "*", - "magento/module-store" : "*", - "magento/module-backend" : "*", - "magento/module-catalog" : "*", - "magento/module-catalog-search" : "*", - "magento/magento-composer-installer" : "*", - "elasticsearch/elasticsearch" : "2.1.*" - }, - "autoload" : { - "files" : [ - "registration.php" - ], - "psr-4" : { - "Smile\\ElasticSuiteCatalogAutocomplete\\" : "" - } - } -} diff --git a/src/module-elasticsuite-catalog-autocomplete/etc/module.xml b/src/module-elasticsuite-catalog-autocomplete/etc/module.xml deleted file mode 100644 index 33f568afe..000000000 --- a/src/module-elasticsuite-catalog-autocomplete/etc/module.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - - - - - - - diff --git a/src/module-elasticsuite-catalog-autocomplete/registration.php b/src/module-elasticsuite-catalog-autocomplete/registration.php deleted file mode 100644 index 032d139a3..000000000 --- a/src/module-elasticsuite-catalog-autocomplete/registration.php +++ /dev/null @@ -1,20 +0,0 @@ - - * @copyright 2016 Smile - * @license Open Software License ("OSL") v. 3.0 - */ - -\Magento\Framework\Component\ComponentRegistrar::register( - \Magento\Framework\Component\ComponentRegistrar::MODULE, - 'Smile_ElasticSuiteCatalogAutocomplete', - __DIR__ -); diff --git a/src/module-elasticsuite-catalog-autocomplete/Model/Autocomplete/Product/DataProvider.php b/src/module-elasticsuite-catalog/Model/Autocomplete/Product/DataProvider.php similarity index 74% rename from src/module-elasticsuite-catalog-autocomplete/Model/Autocomplete/Product/DataProvider.php rename to src/module-elasticsuite-catalog/Model/Autocomplete/Product/DataProvider.php index ccf66135c..e198a3c3a 100644 --- a/src/module-elasticsuite-catalog-autocomplete/Model/Autocomplete/Product/DataProvider.php +++ b/src/module-elasticsuite-catalog/Model/Autocomplete/Product/DataProvider.php @@ -6,28 +6,34 @@ * versions in the future. * * @category Smile - * @package Smile_ElasticSuiteCatalogAutocomplete + * @package Smile_ElasticSuiteCatalog * @author Aurelien FOUCRET * @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 */ 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,7 +170,7 @@ private function getProductCollection() $productCollection = $this->productCollectionFactory->create(); $productCollection->addSearchFilter($terms); - $productCollection->setPageSize(5); + $productCollection->setPageSize($this->getResultsPageSize()); $productCollection ->addAttributeToSelect('name') ->addAttributeToSelect('small_image') @@ -148,4 +178,14 @@ private function getProductCollection() return $productCollection; } + + /** + * Retrieve number of products to display in autocomplete results + * + * @return int + */ + private function getResultsPageSize() + { + return $this->configurationHelper->getMaxSize($this->getType()); + } } diff --git a/src/module-elasticsuite-catalog/etc/adminhtml/system.xml b/src/module-elasticsuite-catalog/etc/adminhtml/system.xml new file mode 100644 index 000000000..04effe64f --- /dev/null +++ b/src/module-elasticsuite-catalog/etc/adminhtml/system.xml @@ -0,0 +1,30 @@ + + + +
+ + + + + integer + + + +
+
+
diff --git a/src/module-elasticsuite-catalog/etc/config.xml b/src/module-elasticsuite-catalog/etc/config.xml index fdffb6bf9..3a0b62747 100644 --- a/src/module-elasticsuite-catalog/etc/config.xml +++ b/src/module-elasticsuite-catalog/etc/config.xml @@ -1,5 +1,5 @@ - - + - +
separator-top smile_elasticsuite Magento_Catalog::config_smile_elasticsuite_core_base_settings - + @@ -45,7 +45,7 @@ validate-number - + @@ -64,5 +64,18 @@
+
+ + smile_elasticsuite + Magento_Backend::smile_elasticsuite_autocomplete + + + + + integer + + + +
diff --git a/src/module-elasticsuite-core/etc/config.xml b/src/module-elasticsuite-core/etc/config.xml index fcf7bf761..4cb477dba 100644 --- a/src/module-elasticsuite-core/etc/config.xml +++ b/src/module-elasticsuite-core/etc/config.xml @@ -1,5 +1,5 @@ -