Skip to content

Commit

Permalink
Merge branch '2.2.x' into 'master'
Browse files Browse the repository at this point in the history
  • Loading branch information
romainruaud committed Sep 26, 2016
2 parents f9d83b1 + e305179 commit 912bfdc
Show file tree
Hide file tree
Showing 108 changed files with 3,550 additions and 1,373 deletions.
12 changes: 6 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@
}
],
"require": {
"magento/framework": "*",
"magento/module-store": "*",
"magento/module-backend": "*",
"magento/module-catalog": "*",
"magento/module-catalog-search": "*",
"magento/framework": ">=100.1.0",
"magento/module-store": ">=100.1.0",
"magento/module-backend": ">=100.1.0",
"magento/module-catalog": ">=100.1.0",
"magento/module-catalog-search": ">=100.1.0",
"magento/magento-composer-installer": "*",
"elasticsearch/elasticsearch": "2.1.*"
"elasticsearch/elasticsearch": "^2.1"
},
"replace": {
"smile/module-elasticsuite-core": "self.version",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,17 @@ public function getAttributeCollection()
if ($this->attributeCollection === null) {
$this->attributeCollection = $this->attributeCollectionFactory->create();

$mapping = $this->getMapping();
$mapping = $this->getMapping();
$attributeNameMapping = array_flip($this->fieldNameMapping);

$arrayNameCb = function (FieldInterface $field) {
return $field->getName();
$arrayNameCb = function (FieldInterface $field) use ($attributeNameMapping) {
$attributeName = $field->getName();

if (isset($attributeNameMapping[$attributeName])) {
$attributeName = $attributeNameMapping[$attributeName];
}

return $attributeName;
};

$attributeFilterCb = function (FieldInterface $field) use ($mapping) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php
/**
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade Smile Elastic Suite to newer
* versions in the future.
*
*
* @category Smile
* @package Smile\ElasticsuiteCatalogRule
* @author Aurelien FOUCRET <[email protected]>
* @copyright 2016 Smile
* @license Open Software License ("OSL") v. 3.0
*/
namespace Smile\ElasticsuiteCatalogRule\Model\Rule\Condition\Product;

use Smile\ElasticsuiteCore\Search\Request\QueryInterface;

/**
* Allow to apply automatic filters on nested field during rule query conversion.
*
* @category Smile
* @package Smile\ElasticsuiteCatalogRule
* @author Aurelien FOUCRET <[email protected]>
*/
interface NestedFilterInterface
{
/**
* @return \Smile\ElasticsuiteCore\Search\Request\QueryInterface
*/
public function getFilter();
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,23 @@ class QueryBuilder
*/
private $attributeList;

/**
* @var NestedFilterInterface[]
*/
private $nestedFilters;

/**
* Constructor.
*
* @param AttributeList $attributeList Search rule product attributes list
* @param QueryFactory $queryFactory Search query factory.
* @param AttributeList $attributeList Search rule product attributes list
* @param QueryFactory $queryFactory Search query factory.
* @param NestedFilterInterface[] $nestedFilters Filters applied to nested fields during query building.
*/
public function __construct(AttributeList $attributeList, QueryFactory $queryFactory)
public function __construct(AttributeList $attributeList, QueryFactory $queryFactory, $nestedFilters = [])
{
$this->queryFactory = $queryFactory;
$this->attributeList = $attributeList;
$this->nestedFilters = $nestedFilters;
}

/**
Expand All @@ -59,7 +66,7 @@ public function __construct(AttributeList $attributeList, QueryFactory $queryFac
*/
public function getSearchQuery(ProductCondition $productCondition)
{
$query = null;
$query = null;

$this->prepareFieldValue($productCondition);

Expand All @@ -84,7 +91,19 @@ public function getSearchQuery(ProductCondition $productCondition)
$field = $this->getSearchField($productCondition);

if ($field->isNested()) {
$nestedQueryParams = ['query' => $query, 'path' => $field->getNestedPath()];
$nestedPath = $field->getNestedPath();
$nestedQueryParams = ['query' => $query, 'path' => $nestedPath];

if (isset($this->nestedFilters[$nestedPath])) {
$nestedFilterClauses = [];
$nestedFilterClauses['must'][] = $this->nestedFilters[$nestedPath]->getFilter();
$nestedFilterClauses['must'][] = $nestedQueryParams['query'];

$nestedFilter = $this->queryFactory->create(QueryInterface::TYPE_BOOL, $nestedFilterClauses);

$nestedQueryParams['query'] = $nestedFilter;
}

$query = $this->queryFactory->create(QueryInterface::TYPE_NESTED, $nestedQueryParams);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/module-elasticsuite-catalog-rule/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
],
"require": {
"php": "~5.5.0|~5.6.0|~7.0.0",
"magento/framework": "*",
"magento/framework": ">=100.1.0",
"smile/module-elasticsuite-catalog": "self.version"
},
"version": "2.1.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,25 @@
<?php
/**
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade Smile Elastic Suite to newer
* versions in the future.
*
*
* @category Smile
* @package Smile\ElasticsuiteCatalogRule
* @author Aurelien FOUCRET <[email protected]>
* @copyright 2016 Smile
* @license Open Software License ("OSL") v. 3.0
*
* Product search rule admin form rendering.
*/
?>

<?php

/** @var \Smile\ElasticsuiteCatalogRule\Block\Product\Conditions $block */

$element = $block->getElement();
$fieldId = ($element->getHtmlContainerId()) ? ' id="' . $element->getHtmlContainerId() . '"' : '';
$fieldClass = "field admin__field field-{$element->getId()} {$element->getCssClass()}";
Expand All @@ -17,12 +38,11 @@ $fieldAttributes = $fieldId . ' class="' . $fieldClass . '" ' . $block->getUiId(
</div>
</div>


<script>
require([
"Magento_Rule/rules",
"prototype"
], function(VarienRulesForm){
window.<?php echo $block->getHtmlId() ?> = new VarienRulesForm('<?php echo $block->getHtmlId() ?>', '<?php /* @escapeNotVerified */ echo $block->getNewChildUrl() ?>');
window.<?php echo $block->getHtmlId(); ?> = new VarienRulesForm("<?php echo $block->getHtmlId() ?>", "<?php /* @escapeNotVerified */ echo $block->getNewChildUrl() ?>");
});
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// /**
// * DISCLAIMER
// *
// * Do not edit or add to this file if you wish to upgrade Smile Elastic Suite to newer
// * versions in the future.
// *
// *
// * @category Smile
// * @package Smile\ElasticsuiteCatalogRule
// * @author Aurelien FOUCRET <[email protected]>
// * @copyright 2016 Smile
// * @license Open Software License ("OSL") v. 3.0
// */

// Display fieldsets legend into catalog category merchandising tab.
.admin__fieldset.virtual-rule-fieldset {
padding: 0
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
/**
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade Smile Elastic Suite to newer
* versions in the future.
*
*
* @category Smile
* @package Smile\ElasticsuiteCatalogRule
* @author Aurelien FOUCRET <[email protected]>
* @copyright 2016 Smile
* @license Open Software License ("OSL") v. 3.0
*/

define([
'Magento_Ui/js/form/components/html',
'jquery',
'MutationObserver'
], function (Component, $) {
'use strict';

return Component.extend({
defaults: {
value: {},
links: {
value: '${ $.provider }:${ $.dataScope }'
},
additionalClasses: "admin__fieldset virtual-rule-fieldset"
},
initialize: function () {
this._super();
this.initRuleListener();
},

initObservable: function () {
this._super();
this.ruleObject = {};
this.observe('ruleObject value');

return this;
},

initRuleListener: function () {
var observer = new MutationObserver(function () {
var rootNode = document.getElementById(this.index);
if (rootNode !== null) {
this.rootNode = document.getElementById(this.index);
observer.disconnect();
var ruleObserver = new MutationObserver(this.updateRule.bind(this));
var ruleObserverConfig = {childList:true, subtree: true, attributes: true};
ruleObserver.observe(rootNode, ruleObserverConfig);
this.updateRule();
}
}.bind(this));
var observerConfig = {childList: true, subtree: true};
observer.observe(document, observerConfig)
},

updateRule: function () {
var ruleObject = {};
var hashValues = [];

$(this.rootNode).find("[name*=" + this.index + "]").each(function () {
hashValues.push(this.name + this.value.toString());
var currentRuleObject = ruleObject;

var path = this.name.match(/\[([^[\[\]]+)\]/g)
.map(function (pathItem) { return pathItem.substr(1, pathItem.length-2); });

while (path.length > 1) {
var currentKey = path.shift();

if (currentRuleObject[currentKey] === undefined) {
currentRuleObject[currentKey] = {};
}

currentRuleObject = currentRuleObject[currentKey];
}

currentKey = path.shift();
currentRuleObject[currentKey] = $(this).val();
});

var newHashValue = hashValues.sort().join('');

if (newHashValue !== this.currentHashValue) {
if (this.currentHashValue !== undefined) {
this.bubble('update', true);
}
this.currentHashValue = newHashValue;
this.ruleObject(ruleObject);
this.value(ruleObject);
}
}
})
});

This file was deleted.

Loading

0 comments on commit 912bfdc

Please sign in to comment.