Skip to content

Commit 7fd0116

Browse files
Merge pull request #527 from magento/422_adding-conditions-combination-to-conditions-filter-fix
#422: Adding Conditions Combination to C…
2 parents bf625cc + 539c630 commit 7fd0116

File tree

4 files changed

+109
-2
lines changed

4 files changed

+109
-2
lines changed

app/code/Magento/PageBuilder/Component/Form/HtmlCode.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@
88

99
use Magento\Backend\Model\UrlInterface as BackendUrlInterface;
1010
use Magento\Cms\Helper\Wysiwyg\Images;
11+
use Magento\Framework\App\ObjectManager;
1112
use Magento\Framework\View\Element\UiComponentFactory;
1213
use Magento\Framework\View\Element\UiComponent\ContextInterface;
14+
use Magento\Ui\Component\Form\Element\DataType\Media\OpenDialogUrl;
1315
use Magento\Variable\Model\Variable\Config as VariableConfig;
1416

1517
/**
@@ -39,12 +41,18 @@ class HtmlCode extends \Magento\Ui\Component\Form\Field
3941
*/
4042
private $currentTreePath;
4143

44+
/**
45+
* @var OpenDialogUrl
46+
*/
47+
private $openDialogUrl;
48+
4249
/**
4350
* @param ContextInterface $context
4451
* @param UiComponentFactory $uiComponentFactory
4552
* @param BackendUrlInterface $backendUrl
4653
* @param Images $imagesHelper
4754
* @param VariableConfig $variableConfig
55+
* @param OpenDialogUrl|null $openDialogUrl
4856
* @param string $currentTreePath
4957
* @param array $components
5058
* @param array $data
@@ -55,6 +63,7 @@ public function __construct(
5563
BackendUrlInterface $backendUrl,
5664
Images $imagesHelper,
5765
VariableConfig $variableConfig,
66+
OpenDialogUrl $openDialogUrl = null,
5867
$currentTreePath = 'wysiwyg',
5968
$components = [],
6069
array $data = []
@@ -63,6 +72,7 @@ public function __construct(
6372
$this->imagesHelper = $imagesHelper;
6473
$this->variableConfig = $variableConfig;
6574
$this->currentTreePath = $currentTreePath;
75+
$this->openDialogUrl = $openDialogUrl ?: ObjectManager::getInstance()->get(OpenDialogUrl::class);
6676
parent::__construct($context, $uiComponentFactory, $components, $data);
6777
}
6878

@@ -82,7 +92,7 @@ public function prepare()
8292
]
8393
);
8494
$config['imageUrl'] = $this->backendUrl->getUrl(
85-
'cms/wysiwyg_images/index',
95+
$this->openDialogUrl->get(),
8696
[
8797
'current_tree_path' => $this->imagesHelper->idEncode($this->currentTreePath),
8898
'target_element_id' => self::HTML_ID_PLACEHOLDER
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
<actionGroups xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
9+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/actionGroupSchema.xsd">
10+
<actionGroup name="AddConditionsCombinationToProducts">
11+
<annotations>
12+
<description value="Add nested conditions combinations for the product content type"/>
13+
</annotations>
14+
<arguments>
15+
<argument name="index" defaultValue="1" type="string"/>
16+
</arguments>
17+
<waitForElementVisible selector="{{ProductsContentTypeForm.conditionsList}}" stepKey="waitForConditionsToLoad"/>
18+
<waitForElementVisible selector="{{ProductsContentTypeForm.conditionsListAddButton(index)}}" stepKey="waitForAddConditionButton"/>
19+
<click selector="{{ProductsContentTypeForm.conditionsListAddButton(index)}}" stepKey="clickAddConditionButton"/>
20+
<selectOption selector="{{ProductsContentTypeForm.conditionsListAddTypeSelect(index)}}" userInput="{{PageBuilderProductsConditionCombination.value}}" stepKey="selectCombinationOption"/>
21+
<waitForPageLoad stepKey="waitForConditionsCombinationTemplateToLoad"/>
22+
</actionGroup>
23+
</actionGroups>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
<tests xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
9+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/testSchema.xsd">
10+
<test name="ProductConditionsAddDoubleConditionsCombinationTest">
11+
<annotations>
12+
<features value="PageBuilder"/>
13+
<stories value="Products"/>
14+
<title value="Product conditions rule with a combination of double conditions"/>
15+
<description value="Verify user can successfully set nested conditions combinations for the Product content type"/>
16+
<severity value="MAJOR"/>
17+
<group value="pagebuilder"/>
18+
<group value="pagebuilder-products"/>
19+
</annotations>
20+
<before>
21+
<actionGroup ref="AdminLoginActionGroup" stepKey="loginAsAdmin"/>
22+
<actionGroup ref="navigateToAPageWithPageBuilder" stepKey="navigateToAPageWithPageBuilder"/>
23+
<actionGroup ref="switchToPageBuilderStage" stepKey="switchToPageBuilderStage"/>
24+
</before>
25+
<after>
26+
<actionGroup ref="AdminLogoutActionGroup" stepKey="logout"/>
27+
</after>
28+
<actionGroup ref="expandPageBuilderPanelMenuSection" stepKey="expandPageBuilderPanelMenuSection">
29+
<argument name="contentType" value="PageBuilderProductsContentType"/>
30+
</actionGroup>
31+
<actionGroup ref="dragContentTypeToStage" stepKey="dragProductsOntoStage">
32+
<argument name="contentType" value="PageBuilderProductsContentType"/>
33+
</actionGroup>
34+
<actionGroup ref="openPageBuilderEditPanel" stepKey="openEditAfterDrop">
35+
<argument name="contentType" value="PageBuilderProductsContentType"/>
36+
</actionGroup>
37+
<actionGroup ref="chooseVisualSelectOption" stepKey="chooseSelectProductsBy">
38+
<argument name="property" value="PageBuilderProductsSelectProductsByCondition"/>
39+
</actionGroup>
40+
<actionGroup ref="AddConditionsCombinationToProducts" stepKey="addProductsConditionCombination"/>
41+
<actionGroup ref="saveEditPanelSettings" stepKey="saveEditPanelSettings"/>
42+
<actionGroup ref="openPageBuilderEditPanel" stepKey="openEditAfterDropAgain">
43+
<argument name="contentType" value="PageBuilderProductsContentType"/>
44+
</actionGroup>
45+
<!-- Validate No JS Errors -->
46+
<dontSeeJsError stepKey="doNotSeeAnyJSErrors"/>
47+
<actionGroup ref="AddConditionsCombinationToProducts" stepKey="addProductsConditionCombinationAgain"/>
48+
<actionGroup ref="AddConditionsCombinationToProducts" stepKey="addProductsConditionCombinationAgainSecondTime"/>
49+
<actionGroup ref="saveEditPanelSettings" stepKey="saveEditPanelSettingsAgain"/>
50+
<actionGroup ref="openPageBuilderEditPanel" stepKey="openEditAfterDropAgainSecondTimeAgain">
51+
<argument name="contentType" value="PageBuilderProductsContentType"/>
52+
</actionGroup>
53+
<!-- Validate No JS Errors -->
54+
<dontSeeJsError stepKey="doNotSeeAnyJSErrorsAgain" />
55+
</test>
56+
</tests>

app/code/Magento/PageBuilder/view/adminhtml/web/js/form/provider/conditions-data-processor.js

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,29 @@ define([
2626
if (key.indexOf('parameters[' + attribute + ']') === 0) {
2727
// Remove the bad, un-normalized data.
2828
delete data[key];
29-
3029
pairs[key] = element;
3130
}
3231
});
3332

33+
/*
34+
* The Combine Condition rule needs to have children,
35+
* if does not have, we cannot parse the rule in the backend.
36+
*/
37+
_.each(pairs, function (element, key) {
38+
var keyIds = key.match(/[\d?-]+/g),
39+
combineElement = 'Magento\\CatalogWidget\\Model\\Rule\\Condition\\Combine',
40+
nextPairsFirstKey = 'parameters[condition_source][NEXT_ITEM--1][type]',
41+
nextPairsSecondKey = 'parameters[condition_source][NEXT_ITEM--2][type]';
42+
43+
if (keyIds !== null && element === combineElement) {
44+
if (pairs[nextPairsFirstKey.replace('NEXT_ITEM', keyIds[0])] === undefined ||
45+
pairs[nextPairsFirstKey.replace('NEXT_ITEM', keyIds[0])] === combineElement &&
46+
pairs[nextPairsSecondKey.replace('NEXT_ITEM', keyIds[0])] === undefined) {
47+
pairs[key] = '';
48+
}
49+
}
50+
});
51+
3452
/*
3553
* Add pairs in case conditions source is not rules configurator
3654
*/

0 commit comments

Comments
 (0)