diff --git a/src/module-elasticsuite-catalog/Model/ProductSorter/AbstractPreview.php b/src/module-elasticsuite-catalog/Model/ProductSorter/AbstractPreview.php index df10a27ec..7006b992f 100644 --- a/src/module-elasticsuite-catalog/Model/ProductSorter/AbstractPreview.php +++ b/src/module-elasticsuite-catalog/Model/ProductSorter/AbstractPreview.php @@ -42,6 +42,11 @@ abstract class AbstractPreview implements PreviewInterface */ private $size; + /** + * @var string + */ + private $search; + /** * @var integer */ @@ -59,20 +64,23 @@ abstract class AbstractPreview implements PreviewInterface * @param ItemDataFactory $itemFactory Preview item factory. * @param QueryFactory $queryFactory ES query factory. * @param integer $storeId Store id. - * @param number $size Preview size. + * @param integer $size Preview size. + * @param string $search Preview search. */ public function __construct( ProductCollectionFactory $collectionFactory, ItemDataFactory $itemFactory, QueryFactory $queryFactory, $storeId, - $size = 10 + $size = 10, + $search = '' ) { $this->collectionFactory = $collectionFactory; $this->itemFactory = $itemFactory; $this->queryFactory = $queryFactory; $this->storeId = $storeId; $this->size = $size; + $this->search = $search; } /** @@ -147,7 +155,10 @@ private function getProductCollection() */ private function getUnsortedProductData() { - $productCollection = $this->getProductCollection()->setPageSize($this->size); + $productCollection = $this->getProductCollection() + ->setSearchQuery($this->search) + ->setPageSize($this->size) + ; return ['products' => $productCollection->getItems(), 'size' => $productCollection->getSize()]; } diff --git a/src/module-elasticsuite-catalog/i18n/de_DE.csv b/src/module-elasticsuite-catalog/i18n/de_DE.csv index 6ea800aef..9f4a55661 100755 --- a/src/module-elasticsuite-catalog/i18n/de_DE.csv +++ b/src/module-elasticsuite-catalog/i18n/de_DE.csv @@ -77,3 +77,5 @@ Pinned,Angeheftet Products,Produkte Categories,Kategorien Attributes,Attribute +"Clear search","Suche abbrechen" +"Your search returned no results.","Ihre Suche ergab keine Treffer." \ No newline at end of file diff --git a/src/module-elasticsuite-catalog/i18n/en_US.csv b/src/module-elasticsuite-catalog/i18n/en_US.csv index 4f4c35ddf..602d2de8b 100755 --- a/src/module-elasticsuite-catalog/i18n/en_US.csv +++ b/src/module-elasticsuite-catalog/i18n/en_US.csv @@ -77,3 +77,5 @@ Pinned,Pinned Products,Products Categories,Categories Attributes,Attributes +"Clear search","Clear search" +"Your search returned no results.","Your search returned no results." \ No newline at end of file diff --git a/src/module-elasticsuite-catalog/i18n/fr_FR.csv b/src/module-elasticsuite-catalog/i18n/fr_FR.csv index e9a996795..ca6c8d7cd 100755 --- a/src/module-elasticsuite-catalog/i18n/fr_FR.csv +++ b/src/module-elasticsuite-catalog/i18n/fr_FR.csv @@ -77,3 +77,5 @@ No,Non Products,Produits Categories,Catégories Attributes,Attributs +"Clear search","Annuler la recherche" +"Your search returned no results.","Votre recherche n'a donné aucun résultat." diff --git a/src/module-elasticsuite-catalog/view/adminhtml/ui_component/search_term_preview.xml b/src/module-elasticsuite-catalog/view/adminhtml/ui_component/search_term_preview.xml index c20f7f3a8..dbdb09d1d 100644 --- a/src/module-elasticsuite-catalog/view/adminhtml/ui_component/search_term_preview.xml +++ b/src/module-elasticsuite-catalog/view/adminhtml/ui_component/search_term_preview.xml @@ -81,6 +81,7 @@ 20 true true + false diff --git a/src/module-elasticsuite-catalog/view/adminhtml/web/css/source/_module.less b/src/module-elasticsuite-catalog/view/adminhtml/web/css/source/_module.less index c7776c1d7..d4a3c76e2 100644 --- a/src/module-elasticsuite-catalog/view/adminhtml/web/css/source/_module.less +++ b/src/module-elasticsuite-catalog/view/adminhtml/web/css/source/_module.less @@ -22,6 +22,12 @@ letter-spacing: .025em; } + .top-search { + a.action-reset { + margin: 0 1rem; + } + } + .bottom-links { clear: both; width: 40%; diff --git a/src/module-elasticsuite-catalog/view/adminhtml/web/js/form/element/product-sorter.js b/src/module-elasticsuite-catalog/view/adminhtml/web/js/form/element/product-sorter.js index e7781d3d8..f7b1bd779 100644 --- a/src/module-elasticsuite-catalog/view/adminhtml/web/js/form/element/product-sorter.js +++ b/src/module-elasticsuite-catalog/view/adminhtml/web/js/form/element/product-sorter.js @@ -16,8 +16,9 @@ define([ 'Magento_Ui/js/form/element/abstract', 'jquery', 'Smile_ElasticsuiteCatalog/js/form/element/product-sorter/item', - 'MutationObserver' -], function (Component, $, Product) { + 'MutationObserver', + 'ko' +], function (Component, $, Product, MutationObserver, ko) { 'use strict'; return Component.extend({ @@ -38,10 +39,14 @@ define([ emptyText : $.mage.__('Your product selection is empty.'), automaticSort : $.mage.__('Automatic Sort'), manualSort : $.mage.__('Manual Sort'), + search : $.mage.__('Search'), + clearSearch : $.mage.__('Clear search'), + noResultsText : $.mage.__('Your search returned no results.'), showMore : $.mage.__('Show more') }, forceLoading : false, allowBlacklist : false, + allowSearch: false, blacklistedProducts: [], modules: { provider: '${ $.provider }' @@ -59,6 +64,7 @@ define([ this.pageSize = parseInt(this.pageSize, 10); this.currentSize = this.pageSize; this.enabled = this.loadUrl != null; + this.search = ko.observable(""); this.observe(['products', 'countTotalProducts', 'currentSize', 'editPositions', 'loading', 'showSpinner', 'blacklistedProducts']); @@ -93,7 +99,7 @@ define([ }); } }, - + refreshProductList: function () { if (this.refreshRateLimiter !== undefined) { clearTimeout(); @@ -108,26 +114,27 @@ define([ }.bind(this)); formData['page_size'] = this.currentSize(); + formData['search'] = this.search(); if (this.enabled) { this.loadXhr = $.post(this.loadUrl, this.formData, this.onProductListLoad.bind(this)); } }.bind(this), this.maxRefreshInterval); }, - + onProductListLoad: function (loadedData) { var products = this.sortProduct(loadedData.products.map(this.createProduct.bind(this))); this.products(products); this.countTotalProducts(parseInt(loadedData.size, 10)); this.currentSize(Math.max(this.currentSize(), this.products().length)); - + var productIds = products.map(function (product) { return product.getId() }); var editPositions = this.editPositions(); for (var productId in editPositions) { if ($.inArray(parseInt(productId, 10), productIds) < 0) { delete editPositions[productId]; - } + } } this.editPositions(editPositions); @@ -155,6 +162,24 @@ define([ return this.products().length < this.countTotalProducts(); }, + enterSearch: function (d, e) { + e.keyCode === 13 && this.refreshProductList(); + return true; + }, + + resetSearch: function () { + this.search(''); + this.refreshProductList(); + }, + + hasSearch: function () { + return (this.search() !== ''); + }, + + searchProducts: function () { + this.refreshProductList(); + }, + showMoreProducts: function () { this.currentSize(this.currentSize() + this.pageSize); this.refreshProductList(); @@ -216,11 +241,11 @@ define([ this.products(this.sortProduct(products)); this.editPositions(editPositions); }, - + toggleSortType: function (product) { var products = this.products(); var editPositions = this.editPositions(); - + if (product.getPosition() !== undefined) { var lastProduct = products[products.length -1]; if (lastProduct.hasPosition() || lastProduct.getScore() >= product.getScore()) { diff --git a/src/module-elasticsuite-catalog/view/adminhtml/web/template/form/element/product-sorter.html b/src/module-elasticsuite-catalog/view/adminhtml/web/template/form/element/product-sorter.html index dd97236f5..a46afc069 100644 --- a/src/module-elasticsuite-catalog/view/adminhtml/web/template/form/element/product-sorter.html +++ b/src/module-elasticsuite-catalog/view/adminhtml/web/template/form/element/product-sorter.html @@ -7,20 +7,27 @@ - + - +
-
+
+
- + + +
- +
- +

- +
- + diff --git a/src/module-elasticsuite-virtual-category/Controller/Adminhtml/Category/Virtual/Preview.php b/src/module-elasticsuite-virtual-category/Controller/Adminhtml/Category/Virtual/Preview.php index 76c9e7707..0c452c382 100644 --- a/src/module-elasticsuite-virtual-category/Controller/Adminhtml/Category/Virtual/Preview.php +++ b/src/module-elasticsuite-virtual-category/Controller/Adminhtml/Category/Virtual/Preview.php @@ -92,8 +92,9 @@ private function getPreviewObject() { $category = $this->getCategory(); $pageSize = $this->getPageSize(); + $search = $this->getRequest()->getParam('search'); - return $this->previewModelFactory->create(['category' => $category, 'size' => $pageSize]); + return $this->previewModelFactory->create(['category' => $category, 'size' => $pageSize, 'search' => $search]); } /** diff --git a/src/module-elasticsuite-virtual-category/Model/Preview.php b/src/module-elasticsuite-virtual-category/Model/Preview.php index 6857328a6..166ba9067 100644 --- a/src/module-elasticsuite-virtual-category/Model/Preview.php +++ b/src/module-elasticsuite-virtual-category/Model/Preview.php @@ -50,15 +50,17 @@ class Preview extends \Smile\ElasticsuiteCatalog\Model\ProductSorter\AbstractPre * @param ItemDataFactory $previewItemFactory Preview item factory. * @param QueryFactory $queryFactory QueryInterface factory. * @param int $size Preview size. + * @param string $search Preview search. */ public function __construct( CategoryInterface $category, FulltextCollectionFactory $productCollectionFactory, ItemDataFactory $previewItemFactory, QueryFactory $queryFactory, - $size = 10 + $size = 10, + $search = '' ) { - parent::__construct($productCollectionFactory, $previewItemFactory, $queryFactory, $category->getStoreId(), $size); + parent::__construct($productCollectionFactory, $previewItemFactory, $queryFactory, $category->getStoreId(), $size, $search); $this->category = $category; $this->queryFactory = $queryFactory; } diff --git a/src/module-elasticsuite-virtual-category/view/adminhtml/ui_component/category_form.xml b/src/module-elasticsuite-virtual-category/view/adminhtml/ui_component/category_form.xml index 9da3158f2..8f8d324a1 100644 --- a/src/module-elasticsuite-virtual-category/view/adminhtml/ui_component/category_form.xml +++ b/src/module-elasticsuite-virtual-category/view/adminhtml/ui_component/category_form.xml @@ -143,6 +143,7 @@ sorted_products 20 true + true manual page for more informations.]]>