Skip to content

Commit d01ee51

Browse files
authored
Merge pull request #9234 from adobe-commerce-tier-4/Tier4-PR-2024-08-05
[Support Tier-4 mrosmeteniuc] 08-05-2024 Regular delivery of bugfixes and improvements
2 parents ea32163 + 583e1a5 commit d01ee51

File tree

13 files changed

+615
-73
lines changed

13 files changed

+615
-73
lines changed

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

+23-10
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

+1
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

+1-1
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

+26-1
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

+7-5
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

+16-1
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
*

app/code/Magento/Rss/Test/Unit/Controller/Feed/IndexTest.php

+20-2
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,16 @@ public function testExecute()
9292
$rssModel->expects($this->once())->method('setDataProvider')->willReturnSelf();
9393
$rssModel->expects($this->once())->method('createRssXml')->willReturn('');
9494

95-
$this->response->expects($this->once())->method('setHeader')->willReturnSelf();
95+
$matcher = $this->exactly(2);
96+
$this->response->expects($matcher)
97+
->method('setHeader')
98+
->willReturnCallback(function (string $param) use ($matcher) {
99+
match ($matcher->numberOfInvocations()) {
100+
1 => $this->assertEquals($param, 'Content-type'),
101+
2 => $this->assertEquals($param, 'X-Magento-Tags'),
102+
};
103+
})
104+
->willReturnSelf();
96105
$this->response->expects($this->once())->method('setBody')->willReturnSelf();
97106

98107
$this->rssFactory->expects($this->once())->method('create')->willReturn($rssModel);
@@ -118,7 +127,16 @@ public function testExecuteWithException()
118127
$exceptionMock
119128
);
120129

121-
$this->response->expects($this->once())->method('setHeader')->willReturnSelf();
130+
$matcher = $this->exactly(2);
131+
$this->response->expects($matcher)
132+
->method('setHeader')
133+
->willReturnCallback(function (string $param) use ($matcher) {
134+
match ($matcher->numberOfInvocations()) {
135+
1 => $this->assertEquals($param, 'Content-type'),
136+
2 => $this->assertEquals($param, 'X-Magento-Tags'),
137+
};
138+
})
139+
->willReturnSelf();
122140
$this->rssFactory->expects($this->once())->method('create')->willReturn($rssModel);
123141
$this->rssManager->expects($this->once())->method('getProvider')->willReturn($dataProvider);
124142

app/code/Magento/Rss/Test/Unit/Model/RssTest.php

+42
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
namespace Magento\Rss\Test\Unit\Model;
99

10+
use Magento\Catalog\Block\Rss\Product\NewProducts;
1011
use Magento\Framework\App\CacheInterface;
1112
use Magento\Framework\App\FeedFactoryInterface;
1213
use Magento\Framework\App\FeedInterface;
@@ -148,6 +149,47 @@ public function testGetFeeds(): void
148149
$this->assertEquals($this->feedData, $this->rss->getFeeds());
149150
}
150151

152+
/**
153+
* Get new products feed test
154+
*
155+
* @return void
156+
*/
157+
public function testGetNewProductsFeed(): void
158+
{
159+
$dataProvider = $this->createMock(NewProducts::class);
160+
$dataProvider->expects($this->atLeastOnce())
161+
->method('getCacheKey')
162+
->willReturn('cache_key');
163+
$dataProvider->expects($this->atLeastOnce())
164+
->method('getCacheLifetime')
165+
->willReturn(100);
166+
$dataProvider->expects($this->once())
167+
->method('getRssData')
168+
->willReturn($this->feedData);
169+
$dataProvider->expects($this->once())->method('getIdentities')->willReturn(['identity']);
170+
171+
$this->rss->setDataProvider($dataProvider);
172+
173+
$this->cacheMock->expects($this->once())
174+
->method('load')
175+
->with('cache_key')
176+
->willReturn(false);
177+
$this->cacheMock->expects($this->once())
178+
->method('save')
179+
->with('serializedData')
180+
->willReturn(true);
181+
$this->serializerMock->expects($this->once())
182+
->method('serialize')
183+
->with($this->feedData)
184+
->willReturn(self::STUB_SERIALIZED_DATA);
185+
$this->serializerMock->expects($this->once())
186+
->method('unserialize')
187+
->with(self::STUB_SERIALIZED_DATA)
188+
->willReturn($this->feedData);
189+
190+
$this->assertEquals($this->feedData, $this->rss->getFeeds());
191+
}
192+
151193
public function testGetFeedsWithCache()
152194
{
153195
$dataProvider = $this->getMockForAbstractClass(DataProviderInterface::class);

app/code/Magento/SalesRule/Model/Quote/Discount.php

+15
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,21 @@ public function collect(
197197
if ($item->getNoDiscount() || !$this->calculator->canApplyDiscount($item) || $item->getParentItem()) {
198198
continue;
199199
}
200+
201+
switch ($rule->getSimpleAction()) {
202+
case Rule::BY_PERCENT_ACTION:
203+
case Rule::BY_FIXED_ACTION:
204+
if ($rule->getDiscountStep() > $item->getQty()) {
205+
continue 2;
206+
}
207+
break;
208+
case Rule::BUY_X_GET_Y_ACTION:
209+
if ($rule->getDiscountStep() >= $item->getQty()) {
210+
continue 2;
211+
}
212+
break;
213+
}
214+
200215
$eventArgs['item'] = $item;
201216
$this->eventManager->dispatch('sales_quote_address_discount_item', $eventArgs);
202217

0 commit comments

Comments
 (0)