Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix refactor autocomplete module #25

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": "*",
Expand All @@ -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": {
Expand Down
42 changes: 0 additions & 42 deletions src/module-elasticsuite-catalog-autocomplete/composer.json

This file was deleted.

25 changes: 0 additions & 25 deletions src/module-elasticsuite-catalog-autocomplete/etc/module.xml

This file was deleted.

20 changes: 0 additions & 20 deletions src/module-elasticsuite-catalog-autocomplete/registration.php

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down Expand Up @@ -57,6 +63,16 @@ class DataProvider implements DataProviderInterface
*/
protected $imageHelper;

/**
* @var ConfigurationHelper
*/
protected $configurationHelper;

/**
* @var string Autocomplete result type
*/
private $type;

/**
* Constructor.
*
Expand All @@ -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}
*/
Expand All @@ -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(
[
Expand All @@ -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(),
]
);
}
Expand Down Expand Up @@ -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());
}
}
30 changes: 30 additions & 0 deletions src/module-elasticsuite-catalog/etc/adminhtml/system.xml
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>
7 changes: 6 additions & 1 deletion src/module-elasticsuite-catalog/etc/config.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0"?>
<!--
<!--
/**
* DISCLAIMER
*
Expand All @@ -21,5 +21,10 @@
<engine>elasticsuite</engine>
</search>
</catalog>
<smile_elasticsuite_autocomplete_settings>
<product_autocomplete>
<max_size>5</max_size>
</product_autocomplete>
</smile_elasticsuite_autocomplete_settings>
</default>
</config>
21 changes: 21 additions & 0 deletions src/module-elasticsuite-catalog/etc/frontend/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,25 @@
</arguments>
</virtualType>

<type name="Magento\Search\Model\Autocomplete">
<arguments>
<argument name="dataProviders" xsi:type="array">
<item name="20" xsi:type="object">Smile\ElasticSuiteCatalog\Model\Autocomplete\Product\DataProvider</item>
</argument>
</arguments>
</type>
<type name="Smile\ElasticSuiteCore\Block\Search\Form\Autocomplete">
<arguments>
<argument name="rendererList" xsi:type="array">
<item name="product" xsi:type="array">
<item name="title" xsi:type="string">Products</item>
<item name="template" xsi:type="string">Smile_ElasticSuiteCatalog/autocomplete/product</item>
</item>
<item name="category" xsi:type="array">
<item name="title" xsi:type="string">Categories</item>
<item name="template" xsi:type="string">Smile_ElasticSuiteCatalog/autocomplete/category</item>
</item>
</argument>
</arguments>
</type>
</config>
3 changes: 3 additions & 0 deletions src/module-elasticsuite-catalog/i18n/fr_FR.csv
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,6 @@ OK,OK
"Is Spellchecked","Recherche Approchante"
Yes,Yes
No,No
"Product Autocomplete","Autocomplétion des produits"
"Max size","Taille maximum"
"Maximum number of products to display in autocomplete results.","Nombre maximum de produits à afficher dans les résultats de l'autocomplétion."
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,25 @@
border-bottom: none;
font-weight: bold;
}

.smile-elasticsuite-autocomplete-result {
.product-image-box {
float: left;
padding: 0 5px;
width: 55px;
}

.product-shop {
float: left;
margin: 0 10px 0 0;
padding: 0;
white-space: normal;
width: 60%;
}

.product-item {
.price-box {
margin: 5px 0;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading