Skip to content

Commit 7377de5

Browse files
authored
Merge pull request magento#9268 from adobe-commerce-tier-4/Tier4-09-12-2024
Tier 4 PR Delivery 09-12-2024
2 parents d01ee51 + c13a3ca commit 7377de5

File tree

23 files changed

+964
-155
lines changed

23 files changed

+964
-155
lines changed

app/code/Magento/Authorization/Test/Fixture/Role.php

Lines changed: 57 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use Magento\Authorization\Model\RulesFactory;
1414
use Magento\Authorization\Model\UserContextInterface;
1515
use Magento\Framework\DataObject;
16+
use Magento\TestFramework\Fixture\Api\DataMerger;
1617
use Magento\TestFramework\Fixture\Data\ProcessorInterface;
1718
use Magento\TestFramework\Fixture\RevertibleDataFixtureInterface;
1819

@@ -25,13 +26,16 @@ class Role implements RevertibleDataFixtureInterface
2526
'role_name' => 'Role Name %uniqid%',
2627
'role_type' => Group::ROLE_TYPE,
2728
'user_id' => 0,
28-
'user_type' => UserContextInterface::USER_TYPE_ADMIN
29+
'user_type' => UserContextInterface::USER_TYPE_ADMIN,
30+
'pid' => 0,
31+
'gws_is_all' => 1,
32+
'gws_websites' => null,
33+
'gws_store_groups' => null,
34+
'resources' => self::RESOURCES
2935
];
3036

31-
private const DEFAULT_DATA_RULES = [
32-
'id' => null,
33-
'role_id' => null,
34-
'resources' => ['Magento_Backend::all']
37+
private const RESOURCES = [
38+
'Magento_Backend::all'
3539
];
3640

3741
/**
@@ -54,39 +58,59 @@ class Role implements RevertibleDataFixtureInterface
5458
*/
5559
private $rulesFactory;
5660

61+
/**
62+
* @var DataMerger
63+
*/
64+
private $dataMerger;
65+
5766
/**
5867
* @param RoleFactory $roleFactory
5968
* @param RoleResource $roleResourceModel
6069
* @param RulesFactory $rulesFactory
6170
* @param ProcessorInterface $dataProcessor
71+
* @param DataMerger $dataMerger
6272
*/
6373
public function __construct(
6474
RoleFactory $roleFactory,
6575
RoleResource $roleResourceModel,
6676
RulesFactory $rulesFactory,
67-
ProcessorInterface $dataProcessor
77+
ProcessorInterface $dataProcessor,
78+
DataMerger $dataMerger
6879
) {
6980
$this->roleFactory = $roleFactory;
7081
$this->roleResourceModel = $roleResourceModel;
7182
$this->rulesFactory = $rulesFactory;
7283
$this->dataProcessor = $dataProcessor;
84+
$this->dataMerger = $dataMerger;
7385
}
7486

7587
/**
7688
* @inheritdoc
7789
*/
7890
public function apply(array $data = []): ?DataObject
7991
{
92+
$data = $this->prepareData($data);
93+
94+
$websites = $this->convertGwsWebsiteStoreGroups($data['gws_websites']);
95+
$storeGroups = $this->convertGwsWebsiteStoreGroups($data['gws_store_groups']);
96+
8097
$role = $this->roleFactory->create();
81-
$role->setData($this->prepareData(array_diff_key($data, self::DEFAULT_DATA_RULES)));
82-
$this->roleResourceModel->save($role);
98+
$role->setRoleName($data['role_name'])
99+
->setRoleType($data['role_type'])
100+
->setPid($data['pid'])
101+
->setUserType($data['user_type'])
102+
->setGwsIsAll($data['gws_is_all'])
103+
->setGwsWebsites($websites)
104+
->setGwsStoreGroups($storeGroups);
105+
106+
$result = $role->save();
83107

84-
$rules = $this->rulesFactory->create();
85-
$rules->setRoleId($role->getId() ?? null);
86-
$rules->setResources($data['resources'] ?? self::DEFAULT_DATA_RULES['resources']);
87-
$rules->saveRel();
108+
$this->rulesFactory->create()
109+
->setRoleId($result['role_id'])
110+
->setResources($data['resources'] ?? self::RESOURCES)
111+
->saveRel();
88112

89-
return $role;
113+
return $result;
90114
}
91115

92116
/**
@@ -110,7 +134,26 @@ public function revert(DataObject $data): void
110134
*/
111135
private function prepareData(array $data): array
112136
{
113-
$data = array_merge(self::DEFAULT_DATA, $data);
137+
$data = $this->dataMerger->merge(self::DEFAULT_DATA, $data);
114138
return $this->dataProcessor->process($this, $data);
115139
}
140+
141+
/**
142+
* Convert GWS websites and store groups to string
143+
*
144+
* @param $data
145+
* @return string|null
146+
*/
147+
private function convertGwsWebsiteStoreGroups($data): ?string
148+
{
149+
if (isset($data)) {
150+
if (is_array($data)) {
151+
return implode(',', $data);
152+
}
153+
if (is_string($data)) {
154+
return $data;
155+
}
156+
}
157+
return null;
158+
}
116159
}

app/code/Magento/Catalog/Block/Adminhtml/Category/Widget/Chooser.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ protected function _getNodeJson($node, $level = 0)
152152
if (in_array($node->getId(), $this->getSelectedCategories())) {
153153
$item['checked'] = true;
154154
}
155-
$item['is_anchor'] = (int)$node->getIsAnchor();
155+
$item['is_anchor'] = $node->getIsAnchor() !== null ? (int) $node->getIsAnchor() : 1;
156156
$item['url_key'] = $node->getData('url_key');
157157
return $item;
158158
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
<?php
2+
/************************************************************************
3+
*
4+
* Copyright 2024 Adobe
5+
* All Rights Reserved.
6+
*
7+
* NOTICE: All information contained herein is, and remains
8+
* the property of Adobe and its suppliers, if any. The intellectual
9+
* and technical concepts contained herein are proprietary to Adobe
10+
* and its suppliers and are protected by all applicable intellectual
11+
* property laws, including trade secret and copyright laws.
12+
* Dissemination of this information or reproduction of this material
13+
* is strictly forbidden unless prior written permission is obtained
14+
* from Adobe.
15+
* ************************************************************************
16+
*/
17+
declare(strict_types=1);
18+
19+
namespace Magento\Catalog\Model\ResourceModel\Product;
20+
21+
use Magento\Catalog\Model\Indexer\Category\Product\TableMaintainer as CategoryProductTableMaintainer;
22+
use Magento\Framework\App\ResourceConnection;
23+
use Magento\Store\Model\StoreManagerInterface;
24+
25+
class GetCategories
26+
{
27+
/**
28+
* @param ResourceConnection $resource
29+
* @param CategoryProductTableMaintainer $categoryProductTableMaintainer
30+
* @param StoreManagerInterface $storeManager
31+
*/
32+
public function __construct(
33+
private readonly ResourceConnection $resource,
34+
private readonly CategoryProductTableMaintainer $categoryProductTableMaintainer,
35+
private readonly StoreManagerInterface $storeManager
36+
) {
37+
}
38+
39+
/**
40+
* Returns list of categories ids for provided products
41+
*
42+
* @param int[] $productList
43+
* @return int[]
44+
*/
45+
public function execute(array $productList): array
46+
{
47+
$connection = $this->resource->getConnection();
48+
$categories = [];
49+
foreach ($this->storeManager->getStores() as $store) {
50+
$select = $connection->select()->from(
51+
['category_product_index' => $this->categoryProductTableMaintainer->getMainTable((int)$store->getId())],
52+
['category_product_index.category_id']
53+
);
54+
$select->where('category_product_index.product_id IN (?)', $productList, \Zend_Db::INT_TYPE);
55+
$select->distinct(true);
56+
57+
$categories += array_fill_keys($connection->fetchCol($select), true);
58+
}
59+
60+
return array_keys($categories);
61+
}
62+
}

0 commit comments

Comments
 (0)