Skip to content

Commit 130412f

Browse files
authored
Merge branch 'magento-commerce:2.4-develop' into 2.4.8-graphql-api-enhancements
2 parents 9db836a + 7377de5 commit 130412f

File tree

36 files changed

+1579
-228
lines changed

36 files changed

+1579
-228
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
}

app/code/Magento/Catalog/Block/Rss/Product/NewProducts.php

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,13 @@
55
*/
66
namespace Magento\Catalog\Block\Rss\Product;
77

8-
use Magento\Framework\App\Rss\DataProviderInterface;
8+
use Magento\Framework\App\Rss\DataProviderInterface as DProviderInterface;
9+
use Magento\Framework\DataObject\IdentityInterface as IdInterface;
910

10-
/**
11-
* Class NewProducts
12-
* @package Magento\Catalog\Block\Rss\Product
13-
*/
14-
class NewProducts extends \Magento\Framework\View\Element\AbstractBlock implements DataProviderInterface
11+
class NewProducts extends \Magento\Framework\View\Element\AbstractBlock implements DProviderInterface, IdInterface
1512
{
13+
public const CACHE_TAG = 'rss_p_new';
14+
1615
/**
1716
* @var \Magento\Catalog\Helper\Image
1817
*/
@@ -55,6 +54,8 @@ public function __construct(
5554
}
5655

5756
/**
57+
* Configure class
58+
*
5859
* @return void
5960
*/
6061
protected function _construct()
@@ -64,15 +65,15 @@ protected function _construct()
6465
}
6566

6667
/**
67-
* {@inheritdoc}
68+
* @inheritdoc
6869
*/
6970
public function isAllowed()
7071
{
7172
return $this->_scopeConfig->isSetFlag('rss/catalog/new', \Magento\Store\Model\ScopeInterface::SCOPE_STORE);
7273
}
7374

7475
/**
75-
* {@inheritdoc}
76+
* @inheritdoc
7677
*/
7778
public function getRssData()
7879
{
@@ -132,6 +133,8 @@ public function getRssData()
132133
}
133134

134135
/**
136+
* Get current store id
137+
*
135138
* @return int
136139
*/
137140
protected function getStoreId()
@@ -177,14 +180,16 @@ protected function renderPriceHtml(\Magento\Catalog\Model\Product $product)
177180
}
178181

179182
/**
180-
* {@inheritdoc}
183+
* @inheritdoc
181184
*/
182185
public function getCacheLifetime()
183186
{
184187
return 600;
185188
}
186189

187190
/**
191+
* Generate rss feed
192+
*
188193
* @return array
189194
*/
190195
public function getFeeds()
@@ -199,10 +204,18 @@ public function getFeeds()
199204
}
200205

201206
/**
202-
* {@inheritdoc}
207+
* @inheritdoc
203208
*/
204209
public function isAuthRequired()
205210
{
206211
return false;
207212
}
213+
214+
/**
215+
* @inheritdoc
216+
*/
217+
public function getIdentities()
218+
{
219+
return [self::CACHE_TAG];
220+
}
208221
}

app/code/Magento/Catalog/Model/Product.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2413,6 +2413,7 @@ public function getIdentities()
24132413
|| $this->isObjectNew();
24142414
if ($isProductNew && ($isStatusChanged || $this->getStatus() == Status::STATUS_ENABLED)) {
24152415
$identities[] = \Magento\Catalog\Block\Product\NewProduct::CACHE_TAG;
2416+
$identities[] = \Magento\Catalog\Block\Rss\Product\NewProducts::CACHE_TAG;
24162417
}
24172418

24182419
return array_unique($identities);
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+
}

app/code/Magento/Catalog/Test/Unit/Model/ProductTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -983,7 +983,7 @@ private function getNoStockStatusChangesData(MockObject $extensionAttributesMock
983983
private function getNewProductProviderData(): array
984984
{
985985
return [
986-
['cat_p_1', 'cat_c_p_1', 'cat_p_new'],
986+
['cat_p_1', 'cat_c_p_1', 'cat_p_new', 'rss_p_new'],
987987
null,
988988
[
989989
'id' => 1,

0 commit comments

Comments
 (0)