Skip to content

Commit 0a45ec2

Browse files
Merge branch '2.4-develop' into MC-29866
2 parents 3cd62c7 + fa00ff7 commit 0a45ec2

File tree

113 files changed

+6408
-1097
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

113 files changed

+6408
-1097
lines changed

app/code/Magento/AsynchronousOperations/Model/OperationProcessor.php

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,25 +8,24 @@
88

99
namespace Magento\AsynchronousOperations\Model;
1010

11-
use Magento\Framework\Serialize\Serializer\Json;
1211
use Magento\AsynchronousOperations\Api\Data\OperationInterface;
13-
use Magento\Framework\Bulk\OperationManagementInterface;
1412
use Magento\AsynchronousOperations\Model\ConfigInterface as AsyncConfig;
15-
use Magento\Framework\MessageQueue\MessageValidator;
16-
use Magento\Framework\MessageQueue\MessageEncoder;
17-
use Magento\Framework\Exception\NoSuchEntityException;
18-
use Magento\Framework\MessageQueue\ConsumerConfigurationInterface;
19-
use Psr\Log\LoggerInterface;
20-
use Magento\Framework\Exception\LocalizedException;
21-
use Magento\Framework\Exception\TemporaryStateExceptionInterface;
13+
use Magento\Framework\Bulk\OperationManagementInterface;
14+
use Magento\Framework\Communication\ConfigInterface as CommunicationConfig;
2215
use Magento\Framework\DB\Adapter\ConnectionException;
2316
use Magento\Framework\DB\Adapter\DeadlockException;
2417
use Magento\Framework\DB\Adapter\LockWaitException;
18+
use Magento\Framework\Exception\LocalizedException;
19+
use Magento\Framework\Exception\NoSuchEntityException;
20+
use Magento\Framework\MessageQueue\ConsumerConfigurationInterface;
21+
use Magento\Framework\MessageQueue\MessageEncoder;
22+
use Magento\Framework\MessageQueue\MessageValidator;
23+
use Magento\Framework\Serialize\Serializer\Json;
2524
use Magento\Framework\Webapi\ServiceOutputProcessor;
26-
use Magento\Framework\Communication\ConfigInterface as CommunicationConfig;
25+
use Psr\Log\LoggerInterface;
2726

2827
/**
29-
* Class OperationProcessor
28+
* Proccess operation
3029
*
3130
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
3231
*/
@@ -80,9 +79,9 @@ class OperationProcessor
8079
* @param ConsumerConfigurationInterface $configuration
8180
* @param Json $jsonHelper
8281
* @param OperationManagementInterface $operationManagement
83-
* @param LoggerInterface $logger
8482
* @param \Magento\Framework\Webapi\ServiceOutputProcessor $serviceOutputProcessor
8583
* @param \Magento\Framework\Communication\ConfigInterface $communicationConfig
84+
* @param LoggerInterface $logger
8685
*/
8786
public function __construct(
8887
MessageValidator $messageValidator,
@@ -137,7 +136,9 @@ public function process(string $encodedMessage)
137136
$result = $this->executeHandler($callback, $entityParams);
138137
$status = $result['status'];
139138
$errorCode = $result['error_code'];
139+
// phpcs:disable Magento2.Performance.ForeachArrayMerge
140140
$messages = array_merge($messages, $result['messages']);
141+
// phpcs:enable Magento2.Performance.ForeachArrayMerge
141142
$outputData = $result['output_data'];
142143
}
143144
}
@@ -174,8 +175,8 @@ public function process(string $encodedMessage)
174175
/**
175176
* Execute topic handler
176177
*
177-
* @param $callback
178-
* @param $entityParams
178+
* @param callable $callback
179+
* @param array $entityParams
179180
* @return array
180181
*/
181182
private function executeHandler($callback, $entityParams)
@@ -187,7 +188,9 @@ private function executeHandler($callback, $entityParams)
187188
'output_data' => null
188189
];
189190
try {
191+
// phpcs:disable Magento2.Functions.DiscouragedFunction
190192
$result['output_data'] = call_user_func_array($callback, $entityParams);
193+
// phpcs:enable Magento2.Functions.DiscouragedFunction
191194
$result['messages'][] = sprintf('Service execution success %s::%s', get_class($callback[0]), $callback[1]);
192195
} catch (\Zend_Db_Adapter_Exception $e) {
193196
$this->logger->critical($e->getMessage());
@@ -206,9 +209,7 @@ private function executeHandler($callback, $entityParams)
206209
}
207210
} catch (NoSuchEntityException $e) {
208211
$this->logger->error($e->getMessage());
209-
$result['status'] = ($e instanceof TemporaryStateExceptionInterface) ?
210-
OperationInterface::STATUS_TYPE_NOT_RETRIABLY_FAILED :
211-
OperationInterface::STATUS_TYPE_NOT_RETRIABLY_FAILED;
212+
$result['status'] = OperationInterface::STATUS_TYPE_NOT_RETRIABLY_FAILED;
212213
$result['error_code'] = $e->getCode();
213214
$result['messages'][] = $e->getMessage();
214215
} catch (LocalizedException $e) {
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
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+
namespace Magento\Bundle\Test\Unit\Observer;
9+
10+
use Magento\Bundle\Block\Adminhtml\Catalog\Product\Edit\Tab\Attributes;
11+
use Magento\Bundle\Observer\SetAttributeTabBlockObserver;
12+
use Magento\Catalog\Helper\Catalog;
13+
use Magento\Catalog\Model\Product;
14+
use Magento\Catalog\Model\Product\Type;
15+
use Magento\Framework\Event;
16+
use Magento\Framework\Event\Observer;
17+
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
18+
use PHPUnit\Framework\MockObject\MockObject;
19+
use PHPUnit\Framework\TestCase;
20+
21+
/**
22+
* Class SetAttributeTabBlockObserverTest
23+
*
24+
* Test setting attribute tab block for bundle products
25+
*/
26+
class SetAttributeTabBlockObserverTest extends TestCase
27+
{
28+
/**
29+
* @var SetAttributeTabBlockObserver
30+
*/
31+
private $observer;
32+
33+
/**
34+
* @var Catalog|MockObject
35+
*/
36+
private $helperCatalogMock;
37+
38+
/**
39+
* @var Observer|MockObject
40+
*/
41+
private $observerMock;
42+
43+
/**
44+
* @var Event|MockObject
45+
*/
46+
private $eventMock;
47+
48+
/**
49+
* @var Product|MockObject
50+
*/
51+
private $productMock;
52+
53+
/**
54+
* Set Up
55+
*/
56+
public function setUp()
57+
{
58+
$objectManager = new ObjectManager($this);
59+
$this->helperCatalogMock = $this->createMock(Catalog::class);
60+
$this->observerMock = $this->createMock(Observer::class);
61+
$this->eventMock = $this->getMockBuilder(Event::class)
62+
->disableOriginalConstructor()
63+
->setMethods(['getProduct'])
64+
->getMock();
65+
$this->productMock = $this->getMockBuilder(Product::class)
66+
->disableOriginalConstructor()
67+
->getMock();
68+
69+
$this->observer = $objectManager->getObject(
70+
SetAttributeTabBlockObserver::class,
71+
[
72+
'helperCatalog' => $this->helperCatalogMock
73+
]
74+
);
75+
}
76+
77+
/**
78+
* Test setting attribute tab block for bundle product
79+
*/
80+
public function testAddingAttributeTabForBundleProduct()
81+
{
82+
$this->productMock->expects($this->any())
83+
->method('getTypeId')
84+
->willReturn(Type::TYPE_BUNDLE);
85+
$this->eventMock->expects($this->any())
86+
->method('getProduct')
87+
->willReturn($this->productMock);
88+
$this->observerMock->expects($this->any())
89+
->method('getEvent')
90+
->willReturn($this->eventMock);
91+
$this->helperCatalogMock->expects($this->once())
92+
->method('setAttributeTabBlock')
93+
->with(Attributes::class);
94+
95+
$this->observer->execute($this->observerMock);
96+
}
97+
98+
/**
99+
* Test setting attribute tab block for a non bundle product
100+
*/
101+
public function testAddingAttributeTabForNonBundleProduct()
102+
{
103+
$this->productMock->expects($this->any())
104+
->method('getTypeId')
105+
->willReturn(Type::TYPE_VIRTUAL);
106+
$this->eventMock->expects($this->any())
107+
->method('getProduct')
108+
->willReturn($this->productMock);
109+
$this->observerMock->expects($this->any())
110+
->method('getEvent')
111+
->willReturn($this->eventMock);
112+
$this->helperCatalogMock->expects($this->never())
113+
->method('setAttributeTabBlock');
114+
115+
$this->observer->execute($this->observerMock);
116+
}
117+
}
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
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+
namespace Magento\CatalogInventory\Test\Unit\Observer;
9+
10+
use Magento\Catalog\Model\Indexer\Product\Price\Processor;
11+
use Magento\CatalogInventory\Model\Configuration;
12+
use Magento\CatalogInventory\Observer\InvalidatePriceIndexUponConfigChangeObserver;
13+
use Magento\Framework\Event;
14+
use Magento\Framework\Event\Observer;
15+
use Magento\Framework\Indexer\IndexerInterface;
16+
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
17+
use PHPUnit\Framework\MockObject\MockObject;
18+
use PHPUnit\Framework\TestCase;
19+
20+
/**
21+
* Class InvalidatePriceIndexUponConfigChangeObserverTest
22+
*
23+
* Testing invalidating product price index onn config changing
24+
*/
25+
class InvalidatePriceIndexUponConfigChangeObserverTest extends TestCase
26+
{
27+
/**
28+
* @var InvalidatePriceIndexUponConfigChangeObserver
29+
*/
30+
private $observer;
31+
32+
/**
33+
* @var Processor|MockObject
34+
*/
35+
private $priceIndexProcessorMock;
36+
37+
/**
38+
* @var Observer|MockObject
39+
*/
40+
private $observerMock;
41+
42+
/**
43+
* @var Event|MockObject
44+
*/
45+
private $eventMock;
46+
47+
/**
48+
* @var IndexerInterface|MockObject
49+
*/
50+
private $indexerMock;
51+
52+
/**
53+
* Set Up
54+
*/
55+
public function setUp()
56+
{
57+
$objectManager = new ObjectManager($this);
58+
$this->priceIndexProcessorMock = $this->createMock(Processor::class);
59+
$this->indexerMock = $this->getMockBuilder(IndexerInterface::class)
60+
->getMockForAbstractClass();
61+
$this->observerMock = $this->createMock(Observer::class);
62+
$this->eventMock = $this->getMockBuilder(Event::class)
63+
->disableOriginalConstructor()
64+
->setMethods(['getChangedPaths'])
65+
->getMock();
66+
67+
$this->observer = $objectManager->getObject(
68+
InvalidatePriceIndexUponConfigChangeObserver::class,
69+
[
70+
'priceIndexProcessor' => $this->priceIndexProcessorMock
71+
]
72+
);
73+
}
74+
75+
/**
76+
* Testing invalidating product price index on catalog inventory config changes
77+
*/
78+
public function testInvalidatingPriceOnChangingOutOfStockConfig()
79+
{
80+
$changedPaths = [Configuration::XML_PATH_SHOW_OUT_OF_STOCK];
81+
82+
$this->eventMock->expects($this->once())
83+
->method('getChangedPaths')
84+
->willReturn($changedPaths);
85+
$this->observerMock->expects($this->once())
86+
->method('getEvent')
87+
->willReturn($this->eventMock);
88+
$this->indexerMock->expects($this->once())
89+
->method('invalidate');
90+
$this->priceIndexProcessorMock->expects($this->once())
91+
->method('getIndexer')
92+
->willReturn($this->indexerMock);
93+
94+
$this->observer->execute($this->observerMock);
95+
}
96+
97+
/**
98+
* Testing invalidating product price index on changing any other config
99+
*/
100+
public function testInvalidatingPriceOnChangingAnyOtherConfig()
101+
{
102+
$changedPaths = [Configuration::XML_PATH_ITEM_AUTO_RETURN];
103+
104+
$this->eventMock->expects($this->once())
105+
->method('getChangedPaths')
106+
->willReturn($changedPaths);
107+
$this->observerMock->expects($this->once())
108+
->method('getEvent')
109+
->willReturn($this->eventMock);
110+
$this->indexerMock->expects($this->never())
111+
->method('invalidate');
112+
$this->priceIndexProcessorMock->expects($this->never())
113+
->method('getIndexer')
114+
->willReturn($this->indexerMock);
115+
116+
$this->observer->execute($this->observerMock);
117+
}
118+
}

app/code/Magento/CatalogRule/Observer/ProcessAdminFinalPriceObserver.php

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@
77

88
namespace Magento\CatalogRule\Observer;
99

10-
use Magento\Framework\Stdlib\DateTime\TimezoneInterface;
11-
use Magento\Framework\Registry;
1210
use Magento\Framework\Event\ObserverInterface;
11+
use Magento\Framework\Registry;
12+
use Magento\Framework\Stdlib\DateTime\TimezoneInterface;
13+
use Magento\Store\Model\StoreManagerInterface;
1314

1415
/**
1516
* Observer for applying catalog rules on product for admin area
@@ -23,6 +24,11 @@ class ProcessAdminFinalPriceObserver implements ObserverInterface
2324
*/
2425
protected $coreRegistry;
2526

27+
/**
28+
* @var StoreManagerInterface
29+
*/
30+
protected $storeManager;
31+
2632
/**
2733
* @var \Magento\Framework\Stdlib\DateTime\TimezoneInterface
2834
*/
@@ -41,17 +47,20 @@ class ProcessAdminFinalPriceObserver implements ObserverInterface
4147
/**
4248
* @param RulePricesStorage $rulePricesStorage
4349
* @param Registry $coreRegistry
50+
* @param StoreManagerInterface $storeManager
4451
* @param \Magento\CatalogRule\Model\ResourceModel\RuleFactory $resourceRuleFactory
4552
* @param TimezoneInterface $localeDate
4653
*/
4754
public function __construct(
4855
RulePricesStorage $rulePricesStorage,
4956
Registry $coreRegistry,
57+
StoreManagerInterface $storeManager,
5058
\Magento\CatalogRule\Model\ResourceModel\RuleFactory $resourceRuleFactory,
5159
TimezoneInterface $localeDate
5260
) {
5361
$this->rulePricesStorage = $rulePricesStorage;
5462
$this->coreRegistry = $coreRegistry;
63+
$this->storeManager = $storeManager;
5564
$this->resourceRuleFactory = $resourceRuleFactory;
5665
$this->localeDate = $localeDate;
5766
}
@@ -61,6 +70,7 @@ public function __construct(
6170
*
6271
* @param \Magento\Framework\Event\Observer $observer
6372
* @return $this
73+
* @throws \Magento\Framework\Exception\NoSuchEntityException
6474
*/
6575
public function execute(\Magento\Framework\Event\Observer $observer)
6676
{
@@ -74,13 +84,17 @@ public function execute(\Magento\Framework\Event\Observer $observer)
7484
$wId = $ruleData->getWebsiteId();
7585
$gId = $ruleData->getCustomerGroupId();
7686
$pId = $product->getId();
77-
7887
$key = "{$date->format('Y-m-d H:i:s')}|{$wId}|{$gId}|{$pId}";
7988
} elseif ($product->getWebsiteId() !== null && $product->getCustomerGroupId() !== null) {
8089
$wId = $product->getWebsiteId();
8190
$gId = $product->getCustomerGroupId();
8291
$pId = $product->getId();
8392
$key = "{$date->format('Y-m-d H:i:s')}|{$wId}|{$gId}|{$pId}";
93+
} elseif ($product->getWebsiteId() === null && $product->getCustomerGroupId() !== null) {
94+
$wId = $this->storeManager->getStore($storeId)->getWebsiteId();
95+
$gId = $product->getCustomerGroupId();
96+
$pId = $product->getId();
97+
$key = "{$date->format('Y-m-d H:i:s')}|{$wId}|{$gId}|{$pId}";
8498
}
8599

86100
if ($key) {

0 commit comments

Comments
 (0)