Skip to content

Commit eb75cf7

Browse files
committed
Merge branch 'ACP2E-3038' of https://github.com/adobe-commerce-tier-4/magento2ce into Tier4-09-12-2024
2 parents 1503c06 + 11555ef commit eb75cf7

File tree

14 files changed

+672
-87
lines changed

14 files changed

+672
-87
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/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);

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,

app/code/Magento/Paypal/Model/Ipn.php

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@
77
namespace Magento\Paypal\Model;
88

99
use Exception;
10+
use Magento\Framework\App\ObjectManager;
1011
use Magento\Framework\Exception\LocalizedException;
1112
use Magento\Sales\Model\Order;
1213
use Magento\Sales\Model\Order\Email\Sender\CreditmemoSender;
1314
use Magento\Sales\Model\Order\Email\Sender\OrderSender;
15+
use Magento\Sales\Model\OrderMutexInterface;
1416

1517
/**
1618
* PayPal Instant Payment Notification processor model
@@ -46,13 +48,19 @@ class Ipn extends \Magento\Paypal\Model\AbstractIpn implements IpnInterface
4648
protected $creditmemoSender;
4749

4850
/**
49-
* @param \Magento\Paypal\Model\ConfigFactory $configFactory
51+
* @var OrderMutexInterface|null
52+
*/
53+
private ?OrderMutexInterface $orderMutex;
54+
55+
/**
56+
* @param ConfigFactory $configFactory
5057
* @param \Psr\Log\LoggerInterface $logger
5158
* @param \Magento\Framework\HTTP\Adapter\CurlFactory $curlFactory
5259
* @param \Magento\Sales\Model\OrderFactory $orderFactory
5360
* @param Info $paypalInfo
5461
* @param OrderSender $orderSender
5562
* @param CreditmemoSender $creditmemoSender
63+
* @param OrderMutexInterface|null $orderMutex
5664
* @param array $data
5765
*/
5866
public function __construct(
@@ -63,13 +71,15 @@ public function __construct(
6371
Info $paypalInfo,
6472
OrderSender $orderSender,
6573
CreditmemoSender $creditmemoSender,
74+
?OrderMutexInterface $orderMutex = null,
6675
array $data = []
6776
) {
6877
parent::__construct($configFactory, $logger, $curlFactory, $data);
6978
$this->_orderFactory = $orderFactory;
7079
$this->_paypalInfo = $paypalInfo;
7180
$this->orderSender = $orderSender;
7281
$this->creditmemoSender = $creditmemoSender;
82+
$this->orderMutex = $orderMutex ?: ObjectManager::getInstance()->get(OrderMutexInterface::class);
7383
}
7484

7585
/**
@@ -466,6 +476,21 @@ protected function _registerPaymentReversal()
466476
* @return void
467477
*/
468478
protected function _registerPaymentRefund()
479+
{
480+
return $this->orderMutex->execute(
481+
(int) $this->_order->getEntityId(),
482+
\Closure::fromCallable([$this, 'processRefund'])
483+
);
484+
}
485+
486+
/**
487+
* Process a refund
488+
*
489+
* @return void
490+
* @throws Exception
491+
* @SuppressWarnings(PHPMD.UnusedPrivateMethod) This method is used in closure callback
492+
*/
493+
private function processRefund()
469494
{
470495
$this->_importPaymentInformation();
471496
$reason = $this->getRequestData('reason_code');

app/code/Magento/Rss/Controller/Feed/Index.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,10 @@
66
*/
77
namespace Magento\Rss\Controller\Feed;
88

9+
use Magento\Framework\DataObject\IdentityInterface;
910
use Magento\Framework\Exception\NotFoundException;
1011

11-
/**
12-
* Class Index
13-
* @package Magento\Rss\Controller\Feed
14-
*/
15-
class Index extends \Magento\Rss\Controller\Feed
12+
class Index extends \Magento\Rss\Controller\Feed implements \Magento\Framework\App\Action\HttpGetActionInterface
1613
{
1714
/**
1815
* Index action
@@ -46,6 +43,11 @@ public function execute()
4643
$rss->setDataProvider($provider);
4744

4845
$this->getResponse()->setHeader('Content-type', 'text/xml; charset=UTF-8');
46+
$tags = ['rss'];
47+
if ($provider instanceof IdentityInterface) {
48+
$tags = array_merge($tags, $provider->getIdentities());
49+
}
50+
$this->getResponse()->setHeader('X-Magento-Tags', implode(',', $tags));
4951
$this->getResponse()->setBody($rss->createRssXml());
5052
}
5153
}

app/code/Magento/Rss/Model/Rss.php

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use Magento\Framework\App\FeedFactoryInterface;
1313
use Magento\Framework\App\ObjectManager;
1414
use Magento\Framework\App\Rss\DataProviderInterface;
15+
use Magento\Framework\DataObject\IdentityInterface;
1516
use Magento\Framework\Exception\InputException;
1617
use Magento\Framework\Exception\RuntimeException;
1718
use Magento\Framework\Serialize\SerializerInterface;
@@ -83,12 +84,26 @@ public function getFeeds()
8384
$serializedData = $this->serializer->serialize($this->dataProvider->getRssData());
8485

8586
if ($cacheKey && $cacheLifeTime) {
86-
$this->cache->save($serializedData, $cacheKey, ['rss'], $cacheLifeTime);
87+
$this->cache->save($serializedData, $cacheKey, $this->getCacheTags(), $cacheLifeTime);
8788
}
8889

8990
return $this->serializer->unserialize($serializedData);
9091
}
9192

93+
/**
94+
* Returns cache tags
95+
*
96+
* @return array|string[]
97+
*/
98+
private function getCacheTags()
99+
{
100+
$tags = ['rss'];
101+
if ($this->dataProvider instanceof IdentityInterface) {
102+
$tags = array_merge($tags, $this->dataProvider->getIdentities());
103+
}
104+
return $tags;
105+
}
106+
92107
/**
93108
* Sets data provider
94109
*

0 commit comments

Comments
 (0)