Skip to content

Commit 5c43245

Browse files
authored
Merge pull request #308 from magento-obsessive-owls/PB-69
[Owls] PB-69 Manually add products into ProductList by name/SKU and sort them by the order they added into the list
2 parents 0952b88 + cd249cc commit 5c43245

File tree

13 files changed

+467
-21
lines changed

13 files changed

+467
-21
lines changed

app/code/Magento/PageBuilder/Model/Catalog/Sorting/SimpleOption.php

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,14 @@ class SimpleOption implements OptionInterface
3737

3838
/**
3939
* @param string $label
40-
* @param string $sortDirection
41-
* @param string $attributeField
40+
* @param string|null $sortDirection
41+
* @param string|null $attributeField
4242
* @param string|null $secondarySortDirection
4343
*/
4444
public function __construct(
4545
string $label,
46-
string $sortDirection,
47-
string $attributeField,
46+
string $sortDirection = null,
47+
string $attributeField = null,
4848
string $secondarySortDirection = null
4949
) {
5050
$this->label = $label;
@@ -59,10 +59,11 @@ public function __construct(
5959
public function sort(
6060
\Magento\Catalog\Model\ResourceModel\Product\Collection $collection
6161
): \Magento\Catalog\Model\ResourceModel\Product\Collection {
62-
$collection->getSelect()->reset(Select::ORDER);
63-
$collection->addAttributeToSort($this->attributeField, $this->sortDirection);
64-
$collection->addAttributeToSort('entity_id', $this->secondarySortDirection);
65-
62+
if ($this->attributeField && $this->sortDirection) {
63+
$collection->getSelect()->reset(Select::ORDER);
64+
$collection->addAttributeToSort($this->attributeField, $this->sortDirection);
65+
$collection->addAttributeToSort('entity_id', $this->secondarySortDirection);
66+
}
6667
return $collection;
6768
}
6869

app/code/Magento/PageBuilder/Plugin/Catalog/Block/Product/ProductsListPlugin.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@ public function afterCreateCollection(
6060
\Magento\CatalogWidget\Block\Product\ProductsList $subject,
6161
\Magento\Catalog\Model\ResourceModel\Product\Collection $result
6262
) {
63-
$categoryId = $subject->getData('category_ids');
63+
$conditionOption = $subject->getData('condition_option');
64+
$categoryId = $conditionOption === 'category_ids' ? $subject->getData('condition_option_value') : null;
6465
$sortOption = $subject->getData('sort_order');
6566

6667
$this->stock->addIsInStockFilterToCollection($result);
@@ -93,6 +94,7 @@ public function afterCreateCollection(
9394
public function afterGetCacheKeyInfo(\Magento\CatalogWidget\Block\Product\ProductsList $subject, array $cacheKeys)
9495
{
9596
$cacheKeys[] = $subject->getData('sort_order');
97+
$cacheKeys[] = $subject->getData('condition_option');
9698
return $cacheKeys;
9799
}
98100

@@ -105,7 +107,8 @@ public function afterGetCacheKeyInfo(\Magento\CatalogWidget\Block\Product\Produc
105107
*/
106108
public function afterGetIdentities(\Magento\CatalogWidget\Block\Product\ProductsList $subject, array $result)
107109
{
108-
$categoryId = $subject->getData('category_ids');
110+
$conditionOption = $subject->getData('condition_option');
111+
$categoryId = $conditionOption === 'category_ids' ? $subject->getData('condition_option_value') : null;
109112
$sortOption = $subject->getData('sort_order');
110113

111114
if (!empty($categoryId) && $sortOption === 'position') {

app/code/Magento/PageBuilder/Test/Mftf/ActionGroup/ContentTypeProductsActionGroup.xml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
<argument name="property" defaultValue="PageBuilderProductsSelectCategoryDropDown"/>
6161
<argument name="category" type="string"/>
6262
</arguments>
63+
<waitForPageLoad stepKey="waitForPageLoad"/>
6364
<waitForElementVisible time="2" selector="{{EditPanelForm.panelMultiSelectFieldControl(property.section, property.fieldName)}}" stepKey="waitForMultiSelectFieldVisible"/>
6465
<click selector="{{EditPanelForm.panelMultiSelectFieldControl(property.section, property.fieldName)}}" stepKey="clickMultiSelectField"/>
6566
<waitForElementVisible selector="{{EditPanelForm.panelMultiSelectFieldControlInput(property.section, property.fieldName)}}" stepKey="waitForSearchField"/>
@@ -70,6 +71,17 @@
7071
<waitForElementNotVisible selector="{{EditPanelForm.panelMultiSelectFieldControlInput(property.section, property.fieldName)}}" stepKey="waitForSearchFieldNotVisible"/>
7172
<see selector="{{EditPanelForm.panelMultiSelectFieldControl(property.section, property.fieldName)}}" userInput="{{category}}" stepKey="seeResultInField"/>
7273
</actionGroup>
74+
<actionGroup name="addSKUsToSelectProductsBySKU">
75+
<arguments>
76+
<argument name="property" defaultValue="PageBuilderProductsEnterSKUsInput"/>
77+
<argument name="SKUs" type="string"/>
78+
</arguments>
79+
<waitForPageLoad stepKey="waitForPageLoad"/>
80+
<waitForElement time="2" selector="{{EditPanelForm.panelFieldControl(property.section, property.fieldName)}}" stepKey="waitForElementVisible"/>
81+
<see userInput="{{property.name}}" selector="{{EditPanelForm.panelFieldLabel(property.section, property.fieldName, property.section, property.name)}}" stepKey="seePropertyLabel"/>
82+
<fillField selector="{{EditPanelForm.panelFieldControl(property.section, property.fieldName)}}" userInput="{{SKUs}}" stepKey="fillPropertyField"/>
83+
<click selector="{{EditPanelForm.panelFieldLabel(property.section, property.fieldName, property.section, property.name)}}" stepKey="clickOnFieldLabel"/>
84+
</actionGroup>
7385
<actionGroup name="addConditionToProductConditions">
7486
<arguments>
7587
<argument name="conditionType" defaultValue="PageBuilderProductsConditionCategory"/>

app/code/Magento/PageBuilder/Test/Mftf/Data/ProductsData.xml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@
2424
<data key="fieldName">condition_option</data>
2525
<data key="value">category_ids</data>
2626
</entity>
27+
<entity name="PageBuilderProductsSelectProductsBySKU" type="pagebuilder_select_products_by_types">
28+
<data key="name">Select Products By</data>
29+
<data key="section">general</data>
30+
<data key="fieldName">condition_option</data>
31+
<data key="value">sku</data>
32+
</entity>
2733
<entity name="PageBuilderProductsSelectProductsByCondition" type="pagebuilder_select_products_by_types">
2834
<data key="name">Select Products By</data>
2935
<data key="section">general</data>
@@ -36,6 +42,12 @@
3642
<data key="section">general</data>
3743
<data key="fieldName">category_ids</data>
3844
</entity>
45+
<!-- SKU -->
46+
<entity name="PageBuilderProductsEnterSKUsInput" type="pagebuilder_products_sorting_types">
47+
<data key="name">Product SKUs</data>
48+
<data key="section">sku</data>
49+
<data key="fieldName">sku</data>
50+
</entity>
3951
<!-- Conditions -->
4052
<entity name="PageBuilderProductsConditionCombination" type="pagebuilder_products_condition_types">
4153
<data key="name">Conditions Combination</data>
@@ -72,6 +84,12 @@
7284
<data key="fieldName">sort_order</data>
7385
<data key="value">position</data>
7486
</entity>
87+
<entity name="PageBuilderProductsSortBySKUPosition" type="pagebuilder_products_sorting_types">
88+
<data key="name">Sort By</data>
89+
<data key="section">general</data>
90+
<data key="fieldName">sort_order</data>
91+
<data key="value">position_by_sku</data>
92+
</entity>
7593
<!-- Number of Products to Display -->
7694
<entity name="PageBuilderProductsCountPropertyOne" type="pagebuilder_content_type">
7795
<data key="name">Number of Products to Display</data>

0 commit comments

Comments
 (0)