Skip to content

Commit 36a3e0d

Browse files
author
Roman Lytvynenko
committed
MC-23252: Pagebuilder products list doesn't work with anchor category
1 parent 7a30f2b commit 36a3e0d

File tree

3 files changed

+54
-5
lines changed

3 files changed

+54
-5
lines changed

dev/tests/integration/testsuite/Magento/PageBuilder/Model/Catalog/ProductTotalsTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,21 @@ public function productDataProvider()
147147
]
148148
], [3, 1, 1, 0]
149149
],
150+
[ // #6 empty anchor category with subcategory containing 1 product
151+
['1' => [
152+
'aggregator' => 'all',
153+
'new_child' => '',
154+
'type' => \Magento\CatalogWidget\Model\Rule\Condition\Combine::class,
155+
'value' => '1',
156+
],
157+
'1--1' => [
158+
'operator' => '==',
159+
'type' => \Magento\CatalogWidget\Model\Rule\Condition\Product::class,
160+
'attribute' => 'category_ids',
161+
'value' => '5'
162+
]
163+
], [1, 0, 0, 0]
164+
],
150165
];
151166
}
152167
}

dev/tests/integration/testsuite/Magento/PageBuilder/_files/product_totals/products.php

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,37 @@
6969
->setDescription('Category 1.1 description.')
7070
->save();
7171

72+
$category = $objectManager->create(\Magento\Catalog\Model\Category::class);
73+
$category->isObjectNew(true);
74+
$category->setId(5)
75+
->setName('Category 2')
76+
->setParentId(2)
77+
->setPath('1/2/5')
78+
->setLevel(2)
79+
->setAvailableSortBy('name')
80+
->setDefaultSortBy('name')
81+
->setIsActive(true)
82+
->setIsAnchor(true)
83+
->setPosition(1)
84+
->setDescription('Category 2 - Empty Anchor')
85+
->save();
86+
87+
88+
$category = $objectManager->create(\Magento\Catalog\Model\Category::class);
89+
$category->isObjectNew(true);
90+
$category->setId(6)
91+
->setName('Category 2.1')
92+
->setParentId(5)
93+
->setPath('1/2/5/6')
94+
->setLevel(3)
95+
->setAvailableSortBy('name')
96+
->setDefaultSortBy('name')
97+
->setIsActive(true)
98+
->setIsAnchor(true)
99+
->setPosition(1)
100+
->setDescription('Category 2.1 - Anchor category child with 1 product')
101+
->save();
102+
72103
if (!function_exists('createTestProduct')) {
73104
/**
74105
* Create a test product
@@ -79,7 +110,8 @@
79110
* @param $objectManager
80111
* @param $defaultAttributeSet
81112
* @param $categoryLinkManagement
82-
* @throws Exception
113+
* @param $productRepository
114+
* @param array $assignToCategories
83115
*/
84116
function createTestProduct(
85117
$name,
@@ -88,7 +120,8 @@ function createTestProduct(
88120
$objectManager,
89121
$defaultAttributeSet,
90122
$categoryLinkManagement,
91-
$productRepository
123+
$productRepository,
124+
$assignToCategories = [2 ,3]
92125
) {
93126
/** @var $product \Magento\Catalog\Model\Product */
94127
$product = $objectManager->create(\Magento\Catalog\Model\Product::class);
@@ -113,7 +146,7 @@ function createTestProduct(
113146

114147
$categoryLinkManagement->assignProductToCategories(
115148
$product->getSku(),
116-
[2, 3]
149+
$assignToCategories
117150
);
118151
}
119152
}
@@ -126,7 +159,8 @@ function createTestProduct(
126159
$objectManager,
127160
$defaultAttributeSet,
128161
$categoryLinkManagement,
129-
$productRepository
162+
$productRepository,
163+
[2, 3, 6]
130164
);
131165

132166
// Create same product as above with SKU as numbers

dev/tests/integration/testsuite/Magento/PageBuilder/_files/product_totals/products_rollback.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
//Remove categories
3838
/** @var Magento\Catalog\Model\ResourceModel\Category\Collection $collection */
3939
$collection = $objectManager->create(\Magento\Catalog\Model\ResourceModel\Category\Collection::class);
40-
foreach ($collection->addAttributeToFilter('level', ['in' => [2, 3, 4, 5]]) as $category) {
40+
foreach ($collection->addAttributeToFilter('level', ['in' => [2, 3, 4, 5, 6]]) as $category) {
4141
/** @var \Magento\Catalog\Model\Category $category */
4242
$category->delete();
4343
}

0 commit comments

Comments
 (0)