Skip to content

Commit

Permalink
Merge pull request #4909 from magento-obsessive-owls/PB-48
Browse files Browse the repository at this point in the history
[Owls] PB-48: The order of product SKU is not respected if combined with category condition
  • Loading branch information
eug123 authored Oct 29, 2019
2 parents e90ddc6 + ed4c4ab commit 3dcdba7
Show file tree
Hide file tree
Showing 7 changed files with 164 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@
<description>Goes to the Storefront. Validates that the 2 provided Products appear in the correct order.</description>
</annotations>
<arguments>
<argument name="page" defaultValue="{{StorefrontHomePage.url}}" type="string"/>
<argument name="product_1"/>
<argument name="product_2"/>
</arguments>

<amOnPage url="{{StorefrontHomePage.url}}" stepKey="goToHomePage"/>
<amOnPage url="{{page}}" stepKey="goToHomePage"/>
<waitForPageLoad stepKey="waitForPageLoad5"/>
<grabAttributeFrom selector="{{StorefrontCategoryProductSection.ProductImageByNumber('1')}}" userInput="alt" stepKey="grabFirstProductName1_1"/>
<assertEquals expected="{{product_1.name}}" actual="($grabFirstProductName1_1)" message="notExpectedOrder" stepKey="compare1"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@

<waitForElementVisible selector="{{MediaGallerySection.imageOrImageCopy(Image.fileName, Image.extension)}}" stepKey="waitForInitialImages"/>
<grabMultiple selector="{{MediaGallerySection.imageOrImageCopy(Image.fileName, Image.extension)}}" stepKey="initialImages"/>
<click selector="{{MediaGallerySection.imageOrImageCopy(Image.fileName, Image.extension)}}" stepKey="selectImage"/>
<waitForElementVisible selector="{{MediaGallerySection.lastImageOrImageCopy(Image.fileName, Image.extension)}}" stepKey="waitForLastImage"/>
<click selector="{{MediaGallerySection.lastImageOrImageCopy(Image.fileName, Image.extension)}}" stepKey="selectImage"/>
<waitForElementVisible selector="{{MediaGallerySection.DeleteSelectedBtn}}" stepKey="waitForDeleteBtn"/>
<click selector="{{MediaGallerySection.DeleteSelectedBtn}}" stepKey="clickDeleteSelected"/>
<waitForPageLoad stepKey="waitForPageLoad1"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@

<actionGroup name="attachImage">
<annotations>
<description>Uploads the provided Image to Media Gallery.</description>
<description>Uploads the provided Image to Media Gallery.
If you use this action group, you MUST add steps to delete the image in the "after" steps.</description>
</annotations>
<arguments>
<argument name="Image"/>
Expand Down
1 change: 1 addition & 0 deletions app/code/Magento/Cms/Test/Mftf/Section/TinyMCESection.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
<element name="BrowseUploadImage" type="file" selector=".fileupload" />
<element name="image" type="text" selector="//small[text()='{{var1}}']" parameterized="true"/>
<element name="imageOrImageCopy" type="text" selector="//div[contains(@class,'media-gallery-modal')]//img[contains(@alt, '{{arg1}}.{{arg2}}')]|//img[contains(@alt,'{{arg1}}_') and contains(@alt,'.{{arg2}}')]" parameterized="true"/>
<element name="lastImageOrImageCopy" type="text" selector="(//div[contains(@class,'media-gallery-modal')]//img[contains(@alt, '{{arg1}}.{{arg2}}')]|//img[contains(@alt,'{{arg1}}_') and contains(@alt,'.{{arg2}}')])[last()]" parameterized="true"/>
<element name="imageSelected" type="text" selector="//small[text()='{{var1}}']/parent::*[@class='filecnt selected']" parameterized="true"/>
<element name="ImageSource" type="input" selector=".mce-combobox.mce-abs-layout-item.mce-last.mce-has-open" />
<element name="ImageDescription" type="input" selector=".mce-textbox.mce-abs-layout-item.mce-last" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->

<tests xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/testSchema.xsd">
<test name="CheckOrderOfProdsInWidgetOnCMSPageTest">
<annotations>
<features value="Catalog"/>
<stories value="Widgets"/>
<title value="Checking order of products in a widget on a CMS page - SKU condition"/>
<description value="Checking order of products in a widget on a CMS page - SKU condition"/>
<severity value="CRITICAL"/>
<testCaseId value="MC-13718"/>
<useCaseId value="MC-5906"/>
<group value="Catalog"/>
</annotations>
<before>
<actionGroup ref="LoginAsAdmin" stepKey="loginAsAdmin"/>
<actionGroup ref="EnabledWYSIWYG" stepKey="enableWYSIWYG"/>
<actionGroup ref="SwitchToVersion4ActionGroup" stepKey="enableTinyMCE4"/>
<waitForPageLoad stepKey="waitConfigToSave"/>
<createData entity="ApiCategory" stepKey="createFirstCategory"/>
<createData entity="ApiSimpleProduct" stepKey="product1">
<requiredEntity createDataKey="createFirstCategory"/>
</createData>
<createData entity="ApiSimpleProduct" stepKey="product2">
<requiredEntity createDataKey="createFirstCategory"/>
</createData>
<createData entity="_defaultCmsPage" stepKey="createCMSPage"/>
</before>
<after>
<actionGroup ref="DisabledWYSIWYG" stepKey="disableWYSIWYG"/>
<deleteData createDataKey="createFirstCategory" stepKey="deleteCategory"/>
<deleteData createDataKey="product1" stepKey="deleteProduct1"/>
<deleteData createDataKey="product2" stepKey="deleteProduct2"/>
<deleteData createDataKey="createCMSPage" stepKey="deletePreReqCMSPage"/>
<actionGroup ref="logout" stepKey="logoutOfAdmin"/>
</after>
<actionGroup ref="navigateToCreatedCMSPage" stepKey="navigateToCreatedCMSPage1">
<argument name="CMSPage" value="$$createCMSPage$$"/>
</actionGroup>
<conditionalClick selector="{{CmsNewPagePageContentSection.header}}"
dependentSelector="{{CmsNewPagePageContentSection.header}}._show" visible="false"
stepKey="clickContentTab1"/>
<waitForPageLoad stepKey="waitForContentSectionLoad1"/>
<waitForElementNotVisible selector="{{CmsWYSIWYGSection.CheckIfTabExpand}}" stepKey="waitForTabExpand1"/>
<click selector="{{CmsNewPagePageActionsSection.showHideEditor}}" stepKey="showHiddenButtons"/>
<seeElement selector="{{TinyMCESection.InsertWidgetBtn}}" stepKey="seeWidgetButton"/>
<click selector="{{TinyMCESection.InsertWidgetBtn}}" stepKey="clickInsertWidgetButton"/>
<waitForPageLoad stepKey="waitForPageLoad1"/>
<see userInput="Inserting a widget does not create a widget instance." stepKey="seeMessage"/>
<see selector="{{WidgetSection.InsertWidgetBtnDisabled}}" userInput="Insert Widget"
stepKey="seeInsertWidgetDisabled"/>
<see selector="{{WidgetSection.CancelBtnEnabled}}" userInput="Cancel" stepKey="seeCancelBtnEnabled"/>
<selectOption selector="{{WidgetSection.WidgetType}}" userInput="Catalog Products List"
stepKey="selectCatalogProductsList"/>
<waitForPageLoad stepKey="waitBeforeClickingOnAddParamBtn"/>
<click selector="{{WidgetSection.AddParam}}" stepKey="clickAddParamBtn"/>
<waitForElement selector="{{WidgetSection.ConditionsDropdown}}" stepKey="addingWaitForConditionsDropDown"/>
<waitForElementVisible selector="{{WidgetSection.ConditionsDropdown}}" stepKey="waitForDropdownVisible"/>
<selectOption selector="{{WidgetSection.ConditionsDropdown}}" userInput="SKU"
stepKey="selectCategoryCondition"/>
<waitForPageLoad stepKey="waitBeforeClickingOnRuleParam"/>
<click selector="{{WidgetSection.RuleParam1('3')}}" stepKey="clickOnRuleParam1"/>
<waitForElementVisible selector="{{WidgetSection.RuleParamSelect('1','1')}}"
stepKey="waitDropdownToAppear"/>
<selectOption selector="{{WidgetSection.RuleParamSelect('1','1')}}" userInput="is one of"
stepKey="selectOption"/>
<waitForElement selector="{{WidgetSection.RuleParam}}" stepKey="waitForRuleParam"/>
<click selector="{{WidgetSection.RuleParam}}" stepKey="clickOnRuleParam"/>
<waitForElementVisible selector="{{WidgetSection.Chooser}}" stepKey="waitForElement"/>
<click selector="{{WidgetSection.Chooser}}" stepKey="clickChooser"/>
<waitForPageLoad stepKey="waitForPageToLoad"/>
<fillField selector="{{WidgetSection.ChooserName}}" userInput="$$product1.name$$"
stepKey="fillProduct1Name"/>
<waitForPageLoad stepKey="waitForPageToLoadBeforeClickingOnSearchFilter1"/>
<click selector="{{AdminNewWidgetSection.searchBlock}}" stepKey="searchFilter1"/>
<waitForPageLoad stepKey="waitForPageToLoadBeforeSelectingProduct"/>
<click selector="{{WidgetSection.PreCreateProduct('$$product1.name$$')}}" stepKey="selectProduct1"/>
<click selector="{{AdminWidgetsSection.resetFilter}}" stepKey="resetFilter1"/>
<waitForPageLoad stepKey="waitForPageToLoadBeforeFillingProductName"/>
<fillField selector="{{WidgetSection.ChooserName}}" userInput="$$product2.name$$"
stepKey="fillProduct2Name"/>
<click selector="{{AdminNewWidgetSection.searchBlock}}" stepKey="clickOnSearch"/>
<waitForPageLoad stepKey="waitForPageToLoadBeforeSelectingProduct2"/>
<click selector="{{WidgetSection.PreCreateProduct('$$product2.name$$')}}" stepKey="selectProduct2"/>
<click selector="{{AdminNewWidgetSection.applyParameter}}" stepKey="applyProducts"/>
<click selector="{{WidgetSection.InsertWidget}}" stepKey="clickOnInsertWidgetButton"/>
<waitForPageLoad stepKey="waitForPageToLoadBeforeClickingOnSaveWidget1"/>
<click selector="{{InsertWidgetSection.save}}" stepKey="saveWidget"/>
<waitForPageLoad stepKey="waitForSaveComplete"/>
<actionGroup ref="CompareTwoProductsOrder" stepKey="compareProductOrders1">
<argument name="page" value="$$createCMSPage.identifier$$"/>
<argument name="product_1" value="$$product1$$"/>
<argument name="product_2" value="$$product2$$"/>
</actionGroup>
<actionGroup ref="navigateToCreatedCMSPage" stepKey="navigateToCreatedCMSPage2">
<argument name="CMSPage" value="$$createCMSPage$$"/>
</actionGroup>
<conditionalClick selector="{{CmsNewPagePageContentSection.header}}"
dependentSelector="{{CmsNewPagePageContentSection.header}}._show" visible="false"
stepKey="clickContentTab2"/>
<waitForPageLoad stepKey="waitForContentSectionLoad2"/>
<waitForElementNotVisible selector="{{CmsWYSIWYGSection.CheckIfTabExpand}}" stepKey="waitForTabExpand2"/>
<executeJS function="jQuery('[id=\'cms_page_form_content_ifr\']').attr('name', 'preview-iframe')"
stepKey="setPreviewFrameName"/>
<switchToIFrame selector="preview-iframe" stepKey="switchToIframe"/>
<doubleClick selector="{{TinyMCESection.WidgetButton}}" stepKey="clickToEditWidget"/>
<switchToIFrame stepKey="switchOutFromIframe"/>
<waitForPageLoad stepKey="waitForPageToLoadBeforeOpeningProductsList"/>
<click selector="{{WidgetSection.RuleParam1('4')}}" stepKey="openProductsList"/>
<waitForElementVisible selector="{{WidgetSection.Chooser}}" stepKey="waitForElement2"/>
<click selector="{{WidgetSection.Chooser}}" stepKey="clickChooser2"/>
<waitForPageLoad stepKey="waitForPageToLoadBeforeFillingProduct1Name"/>
<fillField selector="{{WidgetSection.ChooserName}}" userInput="$$product1.name$$" stepKey="fillProduct1Name_2"/>
<waitForPageLoad stepKey="waitForPageToLoadBeforeClickingOnSearchFilter2"/>
<click selector="{{AdminNewWidgetSection.searchBlock}}" stepKey="searchFilter2"/>
<waitForPageLoad stepKey="waitForPageToLoadBeforeSelectingProduct1"/>
<click selector="{{WidgetSection.PreCreateProduct('$$product1.name$$')}}" stepKey="selectProduct1_1"/>
<click selector="{{WidgetSection.PreCreateProduct('$$product1.name$$')}}" stepKey="selectProduct2_2"/>
<click selector="{{AdminNewWidgetSection.applyParameter}}" stepKey="applyProducts1"/>
<click selector="{{WidgetSection.InsertWidget}}" stepKey="clickOnInsertWidgetButton1"/>
<waitForPageLoad stepKey="waitForPageToLoadBeforeClickingOnSaveWidget2"/>
<click selector="{{InsertWidgetSection.save}}" stepKey="saveWidget1"/>
<waitForPageLoad stepKey="waitForSaveComplete1"/>

<actionGroup ref="CompareTwoProductsOrder" stepKey="compareProductOrders2">
<argument name="page" value="$$createCMSPage.identifier$$"/>
<argument name="product_1" value="$$product2$$"/>
<argument name="product_2" value="$$product1$$"/>
</actionGroup>
</test>
</tests>
23 changes: 10 additions & 13 deletions app/code/Magento/Rule/Model/Condition/Sql/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -270,25 +270,22 @@ private function buildConditions(AbstractCollection $collection, Combine $combin
$conditions = '';
$attributeField = '';
foreach ($combine->getConditions() as $condition) {
if ($condition->getData('attribute') === \Magento\Catalog\Api\Data\ProductInterface::SKU) {
if ($condition->getData('attribute') === \Magento\Catalog\Api\Data\ProductInterface::SKU
&& $condition->getData('operator') === '()'
) {
$conditions = $condition->getData('value');
$attributeField = $condition->getMappedSqlField();
$attributeField = $this->_connection->quoteIdentifier($condition->getMappedSqlField());
}
}

if (!empty($conditions) && !empty($attributeField)) {
$conditions = explode(',', $conditions);
foreach ($conditions as &$condition) {
$condition = trim($condition);
}
$conditions = implode(', ', $conditions);
$conditions = $this->_connection->quote(
array_map('trim', explode(',', $conditions))
);
$collection->getSelect()->reset(Select::ORDER);
$collection->getSelect()->order(
$this->_connection->quoteInto(
"FIELD(?, ?)",
[
$attributeField,
$conditions
]
$this->_expressionFactory->create(
['expression' => "FIELD($attributeField, $conditions)"]
)
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,20 @@ public function testAttachConditionToCollection(): void
'operator' => '==',
'value' => '2017-09-15',
],
'1--3' => [
'type' => ProductCondition::class,
'attribute' => 'sku',
'operator' => '()',
'value' => ' :( , :) ',
]
],
];

$rule->loadPost($ruleConditionArray);
$this->model->attachConditionToCollection($collection, $rule->getConditions());

$whereString = "/\(category_id IN \('3'\).+\(IFNULL\(`e`\.`entity_id`,.+\) = '2017-09-15'\)/";
$this->assertNotFalse(preg_match($whereString, $collection->getSelectSql(true)));
$whereString = "/\(category_id IN \('3'\).+\(IFNULL\(`e`\.`entity_id`,.+\) = '2017-09-15'\)"
. ".+ORDER BY \(FIELD\(`e`.`sku`, ':\(', ':\)'\)\)/";
$this->assertEquals(1, preg_match($whereString, $collection->getSelectSql(true)));
}
}

0 comments on commit 3dcdba7

Please sign in to comment.