Skip to content

Commit

Permalink
Merge branch 'master' into fix_optimizer-json-backend
Browse files Browse the repository at this point in the history
  • Loading branch information
romainruaud authored Oct 25, 2018
2 parents 2b84ec4 + 8a6424d commit 315b7a5
Show file tree
Hide file tree
Showing 29 changed files with 686 additions and 126 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@

Due to an update of the Unit test framework in Magento 2.2, we cannot ensure compatibility between ElasticSuite >2.4 and Magento 2.1.x versions.

If your project is based on Magento 2.2.x you can start working with ElasticSuite today using the latest **2.5.x release**.
If your project is based on Magento 2.2.x you can start working with ElasticSuite today using the latest **2.6.x release**.

**Which version should I use ?**

Magento Version | ElasticSuite Latest Version
----------------------------------------------------|------------------------------------------------------------------------
Magento **2.0.x** Opensource (CE) / Commerce (EE) |ElasticSuite **2.1.x** latest release : ```composer require smile/elasticsuite ^2.1.0```
Magento **2.1.x** Opensource (CE) / Commerce (EE) |ElasticSuite **2.3.x** latest release : ```composer require smile/elasticsuite ^2.3.0```
Magento **2.2.x** Opensource (CE) / Commerce (EE) |ElasticSuite **2.5.x** latest release : ```composer require smile/elasticsuite ^2.5.0```
Magento **2.2.x** Opensource (CE) / Commerce (EE) |ElasticSuite **2.6.x** latest release : ```composer require smile/elasticsuite ^2.6.0```

### Magento2 B2B Compatibility

Expand Down Expand Up @@ -68,9 +68,9 @@ A demonstration store including the latest version of ElasticSuite is available

### Current version

The current version **2.5.0** has been focused on the **Elasticsearch 5.x compatibility**, **Search Terms Merchandiser**, **Facet management by category** and **Behavioral data tracking** features.
The current version **2.6.0** has been focused on the **Elasticsearch 6.x compatibility**, improving **Merchandising features** and technical update that aims to bring support for **Magento 2.3.x**.

Feel free to read the whole changelog of this version [here](https://github.com/Smile-SA/elasticsuite/releases/tag/2.5.0)
Feel free to read the whole changelog of this version [here](https://github.com/Smile-SA/elasticsuite/releases/tag/2.6.0)

This version is designed to be used on both Magento Open Source and Commerce versions >2.2.

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
]
],
"branch-alias" : {
"dev-master" : "2.6.x-dev"
"dev-master" : "2.7.x-dev"
}
},
"minimum-stability": "dev",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class Limitation extends \Magento\Framework\Model\ResourceModel\Db\AbstractDb
*/
public function getApplicableOptimizerIdsByCategoryId($categoryId)
{
return $this->getApplicationData('category_id', $categoryId);
return $this->getApplicationData('catalog_view_container', 'category_id', $categoryId);
}

/**
Expand All @@ -44,7 +44,7 @@ public function getApplicableOptimizerIdsByCategoryId($categoryId)
*/
public function getApplicableOptimizerIdsByQueryId($queryId)
{
return $this->getApplicationData('query_id', $queryId);
return $this->getApplicationData('quick_search_container', 'query_id', $queryId);
}

/**
Expand Down Expand Up @@ -86,7 +86,7 @@ public function saveLimitation($optimizer, $limitationData)
$optimizerId = (int) $optimizer->getId();

$this->getConnection()->delete(
OptimizerInterface::TABLE_NAME_LIMITATION,
$this->getMainTable(),
$this->getConnection()->quoteInto(OptimizerInterface::OPTIMIZER_ID . " = ?", $optimizerId)
);

Expand Down Expand Up @@ -126,7 +126,7 @@ private function getLimitationData(OptimizerInterface $optimizer, $column)
{
$select = $this->getConnection()
->select()
->from(OptimizerInterface::TABLE_NAME_LIMITATION, $column)
->from($this->getMainTable(), $column)
->where($this->getConnection()->quoteInto(OptimizerInterface::OPTIMIZER_ID . " = ?", (int) $optimizer->getId()));

return $this->getConnection()->fetchCol($select);
Expand All @@ -135,23 +135,35 @@ private function getLimitationData(OptimizerInterface $optimizer, $column)
/**
* Retrieve applicable optimizer ids for a given entity_id (could be a category_id or query_id).
*
* @param string $column The column to filter on (category_id or query_id).
* @param int $idValue The id of entity to filter
* @param string $container The search container to filter on (quick_search_container or catalog_view_container).
* @param string $column The column to filter on (category_id or query_id).
* @param int $idValue The id of entity to filter
*
* @return array
* @throws \Magento\Framework\Exception\LocalizedException
*/
private function getApplicationData($column, $idValue)
private function getApplicationData($container, $column, $idValue)
{
$select = $this->getConnection()
->select()
->from(['main_table' => $this->getMainTable()], [])
->from(['o' => $this->getTable(OptimizerInterface::TABLE_NAME)], [OptimizerInterface::OPTIMIZER_ID])
->joinInner(
['osc' => $this->getTable(OptimizerInterface::TABLE_NAME_SEARCH_CONTAINER)],
"osc.optimizer_id = main_table.optimizer_id OR osc.apply_to = 0",
[OptimizerInterface::OPTIMIZER_ID]
"o.optimizer_id = osc.optimizer_id",
[]
)
->joinLeft(
['main_table' => $this->getMainTable()],
"o.optimizer_id = main_table.optimizer_id",
[]
)
->where($this->getConnection()->quoteInto("osc.search_container = ?", (string) $container))
->where(
$this->getConnection()->quoteInto(
"osc.apply_to = 0 OR (osc.apply_to = 1 AND main_table.{$column} = ?)",
(int) $idValue
)
)
->where($this->getConnection()->quoteInto("main_table.{$column} = ?", (int) $idValue))
->group(OptimizerInterface::OPTIMIZER_ID);

return $this->getConnection()->fetchCol($select);
Expand Down
50 changes: 50 additions & 0 deletions src/module-elasticsuite-catalog-optimizer/i18n/de_DE.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
Back,Zurück
Delete,Löschen
"Are you sure you want to do this?","Sind Sie sicher?"
Save,Speichern
"Save and Continue Edit","Speichern und weiter bearbeiten"
"Rule conditions","Regelbedingungen"
Optimizer,Optimizer
"New Optimizer","Neuer Optimizer"
"This optimizer no longer exists.","Dieser Optimizer existiert nicht mehr."
"You deleted the optimizer %1.","Der Optimizer %1 wurde gelöscht."
"Edit %1","%1 bearbeiten"
"Something went wrong while editing the optimizer.","Etwas ging schief beim Bearbeiten des Optimizers."
"Optimizers List","Liste des Optimizers"
Optimizers,Optimizers
"You saved the optimizer %1.","Der Optimizer %1 wurde gespeichert."
"End Date must follow Start Date.","Das Enddatum muss nach dem Startdatum liegen."
"Could not save the optimizer: %1","Der Optimizer konnte nicht gespeichert werden: %1"
label,Label
Edit,Bearbeiten
"Delete ${ $.$data.name }","Lösche ${ $.$data.name }"
"Are you sure you want to delete ${ $.$data.name } ?","${ $.$data.name } sicher löschen?"
"Search Query","Suchanfrage"
Preview,Vorschau
"Base Results","Standardergebnisse"
"Optimized Results","Optimierte Ergebnisse"
"Show more","Mehr zeigen"
"Score : ","Treffer: "
"Optimizer Information","Optimizer Information"
"Enable optimizer","Aktiviere Optimizer"
"Store View","Store View"
Constant,Konstant
Model,Modell
"Optimizer Name","Optimizer Name"
"Active from","Aktiv ab"
"Active to","Aktiv bis"
"Request type","Anfragetyp"
Configuration,Einstellung
"Boost value (%)","Boost Wert (%)"
"From -99 to 10000","Von -99 bis 10000"
"Apply to products","Auf Produkte anwenden"
"Query Text","Anfragetext"
"Category Preview","Kategorie-Vorschau"
"Add New Optimizer","Neuen Optimizer hinzufügen"
"All Store Views","Alle Store Views"
ID,ID
Name,Name
"Constant Score","Konstante Treffer"
Active,Aktiv
Inactive,Inaktiv
Status,Status
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@
<update handle="styles"/>
<update handle="editor"/>
<body>
<referenceContainer name="page.main.actions">
<block class="Magento\Backend\Block\Store\Switcher" name="optimizer.store.switcher" template="Magento_Backend::store/switcher.phtml"/>
</referenceContainer>
<referenceBlock name="page.title">
<action method="setTitleClass">
<argument name="class" xsi:type="string">complex</argument>
Expand Down
5 changes: 5 additions & 0 deletions src/module-elasticsuite-catalog-rule/i18n/de_DE.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
"Conditions Combination","Kombination von Bedingungen"
"Product Attribute","Produktattribute"
"Only in stock products","Nur Produkte auf Lager"
"Only discounted products","Nur reduzierte Produkte"
"Only products with image","Nur Produkte mit Bildern"
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,11 @@ private function initAttributes()

$this->initField($attribute);
}

if ($attribute->getAttributeCode() === 'sku') {
// SKU has no backend table.
$this->initField($attribute);
}
}

return $this;
Expand Down
14 changes: 14 additions & 0 deletions src/module-elasticsuite-catalog/Model/Layer/Filter/Decimal.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,4 +143,18 @@ private function formatValue($value)

return $value;
}

/**
* Create the proper query filter for price, according to current customer group Id.
*
* @SuppressWarnings(PHPMD.UnusedPrivateMethod)
*
* @param array $bounds The price bounds to apply
*
* @return array
*/
private function getRangeCondition($bounds)
{
return $bounds;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
trait DecimalFilterTrait
{
/**
* Apply decimal range filter
* Apply price range filter
*
* @param \Magento\Framework\App\RequestInterface $request The request
*
Expand All @@ -50,9 +50,11 @@ public function apply(\Magento\Framework\App\RequestInterface $request)
list($fromValue, $toValue) = $filter;
$this->setCurrentValue(['from' => $fromValue, 'to' => $toValue]);

$bounds = array_filter(['gte' => $fromValue, 'lt' => $toValue]);

$this->getLayer()->getProductCollection()->addFieldToFilter(
$this->getAttributeModel()->getAttributeCode(),
array_filter(['gte' => $fromValue, 'lt' => $toValue])
$this->getRangeCondition($bounds)
);

$this->getLayer()->getState()->addFilter(
Expand Down
47 changes: 47 additions & 0 deletions src/module-elasticsuite-catalog/Model/Layer/Filter/Price.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
namespace Smile\ElasticsuiteCatalog\Model\Layer\Filter;

use Smile\ElasticsuiteCore\Search\Request\BucketInterface;
use Smile\ElasticsuiteCore\Search\Request\QueryInterface;

/**
* Product price filter implementation.
Expand Down Expand Up @@ -43,6 +44,11 @@ class Price extends \Magento\CatalogSearch\Model\Layer\Filter\Price implements F
*/
private $priceCurrency;

/**
* @var \Smile\ElasticsuiteCore\Search\Request\Query\QueryFactory
*/
private $queryFactory;

/**
* Constructor.
*
Expand All @@ -58,6 +64,7 @@ class Price extends \Magento\CatalogSearch\Model\Layer\Filter\Price implements F
* @param \Magento\Framework\Pricing\PriceCurrencyInterface $priceCurrency Price currency.
* @param \Magento\Catalog\Model\Layer\Filter\Dynamic\AlgorithmFactory $algorithmFactory Algorithm factory.
* @param \Magento\Catalog\Model\Layer\Filter\DataProvider\PriceFactory $dataProviderFactory Data provider.
* @param \Smile\ElasticsuiteCore\Search\Request\Query\QueryFactory $queryFactory Query Factory.
* @param array $data Custom data.
*/
public function __construct(
Expand All @@ -71,6 +78,7 @@ public function __construct(
\Magento\Framework\Pricing\PriceCurrencyInterface $priceCurrency,
\Magento\Catalog\Model\Layer\Filter\Dynamic\AlgorithmFactory $algorithmFactory,
\Magento\Catalog\Model\Layer\Filter\DataProvider\PriceFactory $dataProviderFactory,
\Smile\ElasticsuiteCore\Search\Request\Query\QueryFactory $queryFactory,
array $data = []
) {
parent::__construct(
Expand All @@ -90,6 +98,7 @@ public function __construct(
$this->dataProvider = $dataProviderFactory->create(['layer' => $this->getLayer()]);
$this->customerSession = $customerSession;
$this->priceCurrency = $priceCurrency;
$this->queryFactory = $queryFactory;
}

/**
Expand Down Expand Up @@ -144,4 +153,42 @@ private function getFilterField()
{
return 'price.price';
}

/**
* Create the proper query filter for price, according to current customer group Id.
*
* @SuppressWarnings(PHPMD.UnusedPrivateMethod)
*
* @param array $bounds The price bounds to apply
*
* @return \Smile\ElasticsuiteCore\Search\Request\QueryInterface
*/
private function getRangeCondition($bounds)
{
$customerGroupId = $this->customerSession->getCustomerGroupId();

$priceQuery = $this->queryFactory->create(
QueryInterface::TYPE_NESTED,
[
'path' => 'price',
'query' => $this->queryFactory->create(
QueryInterface::TYPE_BOOL,
[
'must' => [
$this->queryFactory->create(
QueryInterface::TYPE_TERM,
['field' => 'price.customer_group_id', 'value' => $customerGroupId]
),
$this->queryFactory->create(
QueryInterface::TYPE_RANGE,
['field' => 'price.price', 'bounds' => $bounds]
),
],
]
),
]
);

return $priceQuery;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,8 @@ public function loadChildrens($productIds, $storeId)

/**
* Allow to filter an attribute collection on attributes that are indexed into the search engine.
* Overriden to enforce "status" attribute indexing for products.
*
* Inherited to enforce "status" and "sku" attribute indexing for products.
*
* @param \Magento\Eav\Model\ResourceModel\Entity\Attribute\Collection $attributeCollection Attribute Collection
*
Expand All @@ -129,7 +130,7 @@ public function addIndexedFilterToAttributeCollection(
) {
$attributeCollection = parent::addIndexedFilterToAttributeCollection($attributeCollection);

$attributeCollection->getSelect()->orWhere("attribute_code = 'status'");
$attributeCollection->getSelect()->orWhere("attribute_code IN ('status', 'sku')");

return $attributeCollection;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
<field name="stock.is_in_stock" type="boolean" />
<field name="stock.qty" type="integer" />

<!-- Static fields handled by the "prices" datasource -->
<!-- Static fields handled by the "categories" datasource -->
<field name="category.category_id" type="integer" nestedPath="category" />
<field name="category.position" type="integer" nestedPath="category" />
<field name="category.is_parent" type="boolean" nestedPath="category" />
Expand Down
Loading

0 comments on commit 315b7a5

Please sign in to comment.