Skip to content

Commit b0e3726

Browse files
author
Roman Lytvynenko
committed
Merge branch 'MC-30260' of https://github.com/magento-tango/magento2ce into Tango-PR-01-24-2020-24
2 parents f99bf7a + 9accf14 commit b0e3726

File tree

4 files changed

+114
-4
lines changed

4 files changed

+114
-4
lines changed

app/code/Magento/CatalogWidget/Block/Product/ProductsList.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -373,9 +373,9 @@ private function updateAnchorCategoryConditions(array $condition): array
373373
return $condition;
374374
}
375375

376-
if ($category->getIsAnchor() && $category->getChildren()) {
377-
$children = explode(',', $category->getChildren());
378-
376+
$children = $category->getIsAnchor() ? $category->getChildren(true) : [];
377+
if ($children) {
378+
$children = explode(',', $children);
379379
$condition['operator'] = "()";
380380
$condition['value'] = array_merge([$categoryId], $children);
381381
}
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
$categories = [
9+
[
10+
'id' => 444,
11+
'parentId' => 2,
12+
'level' => 2,
13+
'path' => '1/2/3'
14+
],
15+
[
16+
'id' => 445,
17+
'parentId' => 444,
18+
'level' => 3,
19+
'path' => '1/2/3/4'
20+
],
21+
[
22+
'id' => 446,
23+
'parentId' => 445,
24+
'level' => 4,
25+
'path' => '1/2/3/4/5'
26+
],
27+
];
28+
29+
$products = [
30+
[
31+
'id' => 444,
32+
'categoryIDs' => [446]
33+
],
34+
[
35+
'id' => 445,
36+
'categoryIDs' => [446]
37+
]
38+
];
39+
40+
foreach ($categories as $category) {
41+
$categoryModel = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()
42+
->create(\Magento\Catalog\Model\Category::class);
43+
$categoryModel->isObjectNew(true);
44+
$categoryModel->setId($category['id'])
45+
->setName('Category ' . $category['id'])
46+
->setParentId($category['parentId'])
47+
->setPath($category['path'])
48+
->setLevel($category['level'])
49+
->setAvailableSortBy('name')
50+
->setDefaultSortBy('name')
51+
->setIsActive(true)
52+
->setPosition(1)
53+
->setAvailableSortBy(['position'])
54+
->save();
55+
}
56+
57+
foreach ($products as $product) {
58+
/** @var $product \Magento\Catalog\Model\Product */
59+
$productModel = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()
60+
->create(\Magento\Catalog\Model\Product::class);
61+
$productModel->setTypeId(\Magento\Catalog\Model\Product\Type::TYPE_SIMPLE)
62+
->setId($product['id'])
63+
->setAttributeSetId(4)
64+
->setStoreId(1)
65+
->setWebsiteIds([1])
66+
->setName('Simple Product ' . $product['id'])
67+
->setSku('simple' . $product['id'])
68+
->setPrice(10)
69+
->setWeight(18)
70+
->setStockData(['use_config_manage_stock' => 0])
71+
->setCategoryIds($product['categoryIDs'])
72+
->setVisibility(\Magento\Catalog\Model\Product\Visibility::VISIBILITY_BOTH)
73+
->setStatus(\Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED)
74+
->save();
75+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
/** @var \Magento\Framework\Registry $registry */
9+
$registry = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()
10+
->get(\Magento\Framework\Registry::class);
11+
$registry->unregister('isSecureArea');
12+
$registry->register('isSecureArea', true);
13+
14+
$categoryIDs = [444, 445, 446];
15+
$productIDs = [444, 445];
16+
17+
foreach ($productIDs as $productID) {
18+
/** @var $product \Magento\Catalog\Model\Product */
19+
$product = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()
20+
->create(\Magento\Catalog\Model\Product::class);
21+
$product->load($productID);
22+
if ($product->getId()) {
23+
$product->delete();
24+
}
25+
}
26+
27+
foreach ($categoryIDs as $categoryID) {
28+
/** @var $category \Magento\Catalog\Model\Category */
29+
$category = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()
30+
->create(\Magento\Catalog\Model\Category::class);
31+
$category->load($categoryID);
32+
if ($category->getId()) {
33+
$category->delete();
34+
}
35+
}

dev/tests/integration/testsuite/Magento/CatalogWidget/Block/Product/ProductListTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ public function testProductListWithDateAttribute()
222222
* 4. Load collection for product list widget and make sure that number of loaded products is correct
223223
*
224224
* @magentoDbIsolation disabled
225-
* @magentoDataFixture Magento/Catalog/_files/product_in_multiple_categories.php
225+
* @magentoDataFixture Magento/Catalog/_files/product_in_nested_anchor_categories.php
226226
*/
227227
public function testCreateAnchorCollection()
228228
{

0 commit comments

Comments
 (0)