Skip to content

Commit b76e703

Browse files
Merge remote-tracking branch 'origin/2.3-develop' into MC-19701
2 parents 03ed173 + 70d2287 commit b76e703

File tree

15 files changed

+232
-123
lines changed

15 files changed

+232
-123
lines changed

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -832,12 +832,14 @@ public function getStoreIds()
832832
if (!$this->hasStoreIds()) {
833833
$storeIds = [];
834834
if ($websiteIds = $this->getWebsiteIds()) {
835-
if ($this->_storeManager->isSingleStoreMode()) {
835+
if (!$this->isObjectNew() && $this->_storeManager->isSingleStoreMode()) {
836836
$websiteIds = array_keys($websiteIds);
837837
}
838838
foreach ($websiteIds as $websiteId) {
839839
$websiteStores = $this->_storeManager->getWebsite($websiteId)->getStoreIds();
840-
$storeIds = array_merge($storeIds, $websiteStores);
840+
foreach ($websiteStores as $websiteStore) {
841+
$storeIds []= $websiteStore;
842+
}
841843
}
842844
}
843845
$this->setStoreIds($storeIds);
@@ -920,9 +922,9 @@ public function beforeSave()
920922
//Validate changing of design.
921923
$userType = $this->getUserContext()->getUserType();
922924
if ((
923-
$userType === UserContextInterface::USER_TYPE_ADMIN
925+
$userType === UserContextInterface::USER_TYPE_ADMIN
924926
|| $userType === UserContextInterface::USER_TYPE_INTEGRATION
925-
)
927+
)
926928
&& !$this->getAuthorization()->isAllowed('Magento_Catalog::edit_product_design')
927929
) {
928930
$this->setData('custom_design', $this->getOrigData('custom_design'));

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

Lines changed: 53 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use Magento\Framework\Api\ExtensibleDataInterface;
1414
use Magento\Framework\Api\ExtensionAttributesFactory;
1515
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;
16+
use Magento\Store\Model\StoreManagerInterface;
1617

1718
/**
1819
* Product Test
@@ -207,6 +208,11 @@ class ProductTest extends \PHPUnit\Framework\TestCase
207208
*/
208209
private $eavConfig;
209210

211+
/**
212+
* @var StoreManagerInterface|\PHPUnit_Framework_MockObject_MockObject
213+
*/
214+
private $storeManager;
215+
210216
/**
211217
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
212218
*/
@@ -303,13 +309,13 @@ protected function setUp()
303309
->disableOriginalConstructor()
304310
->getMock();
305311

306-
$storeManager = $this->getMockBuilder(\Magento\Store\Model\StoreManagerInterface::class)
312+
$this->storeManager = $this->getMockBuilder(\Magento\Store\Model\StoreManagerInterface::class)
307313
->disableOriginalConstructor()
308314
->getMockForAbstractClass();
309-
$storeManager->expects($this->any())
315+
$this->storeManager->expects($this->any())
310316
->method('getStore')
311317
->will($this->returnValue($this->store));
312-
$storeManager->expects($this->any())
318+
$this->storeManager->expects($this->any())
313319
->method('getWebsite')
314320
->will($this->returnValue($this->website));
315321
$this->indexerRegistryMock = $this->createPartialMock(
@@ -394,7 +400,7 @@ protected function setUp()
394400
'extensionFactory' => $this->extensionAttributesFactory,
395401
'productPriceIndexerProcessor' => $this->productPriceProcessor,
396402
'catalogProductOptionFactory' => $optionFactory,
397-
'storeManager' => $storeManager,
403+
'storeManager' => $this->storeManager,
398404
'resource' => $this->resource,
399405
'registry' => $this->registry,
400406
'moduleManager' => $this->moduleManager,
@@ -450,6 +456,48 @@ public function testGetStoreIds()
450456
$this->assertEquals($expectedStoreIds, $this->model->getStoreIds());
451457
}
452458

459+
/**
460+
* @dataProvider getSingleStoreIds
461+
* @param bool $isObjectNew
462+
*/
463+
public function testGetStoreSingleSiteModelIds(
464+
bool $isObjectNew
465+
) {
466+
$websiteIDs = [0 => 2];
467+
$this->model->setWebsiteIds(
468+
!$isObjectNew ? $websiteIDs : array_flip($websiteIDs)
469+
);
470+
471+
$this->model->isObjectNew($isObjectNew);
472+
473+
$this->storeManager->expects(
474+
$this->exactly(
475+
(int) !$isObjectNew
476+
)
477+
)
478+
->method('isSingleStoreMode')
479+
->will($this->returnValue(true));
480+
481+
$this->website->expects(
482+
$this->once()
483+
)->method('getStoreIds')
484+
->will($this->returnValue($websiteIDs));
485+
486+
$this->assertEquals($websiteIDs, $this->model->getStoreIds());
487+
}
488+
489+
public function getSingleStoreIds()
490+
{
491+
return [
492+
[
493+
false
494+
],
495+
[
496+
true
497+
],
498+
];
499+
}
500+
453501
public function testGetStoreId()
454502
{
455503
$this->model->setStoreId(3);
@@ -1221,8 +1269,7 @@ public function testGetMediaGalleryImagesMerging()
12211269
{
12221270
$mediaEntries =
12231271
[
1224-
'images' =>
1225-
[
1272+
'images' => [
12261273
[
12271274
'value_id' => 1,
12281275
'file' => 'imageFile.jpg',

app/code/Magento/OfflinePayments/Observer/BeforeOrderPaymentSaveObserver.php

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,38 +3,38 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
declare(strict_types=1);
67

7-
/**
8-
* OfflinePayments Observer
9-
*/
108
namespace Magento\OfflinePayments\Observer;
119

1210
use Magento\Framework\Event\ObserverInterface;
1311
use Magento\OfflinePayments\Model\Banktransfer;
1412
use Magento\OfflinePayments\Model\Cashondelivery;
1513
use Magento\OfflinePayments\Model\Checkmo;
14+
use Magento\Sales\Model\Order\Payment;
1615

16+
/**
17+
* Sets payment additional information.
18+
*/
1719
class BeforeOrderPaymentSaveObserver implements ObserverInterface
1820
{
1921
/**
20-
* Sets current instructions for bank transfer account
22+
* Sets current instructions for bank transfer account.
2123
*
2224
* @param \Magento\Framework\Event\Observer $observer
2325
* @return void
26+
* @throws \Magento\Framework\Exception\LocalizedException
2427
*/
25-
public function execute(\Magento\Framework\Event\Observer $observer)
28+
public function execute(\Magento\Framework\Event\Observer $observer): void
2629
{
27-
/** @var \Magento\Sales\Model\Order\Payment $payment */
30+
/** @var Payment $payment */
2831
$payment = $observer->getEvent()->getPayment();
2932
$instructionMethods = [
3033
Banktransfer::PAYMENT_METHOD_BANKTRANSFER_CODE,
3134
Cashondelivery::PAYMENT_METHOD_CASHONDELIVERY_CODE
3235
];
3336
if (in_array($payment->getMethod(), $instructionMethods)) {
34-
$payment->setAdditionalInformation(
35-
'instructions',
36-
$payment->getMethodInstance()->getInstructions()
37-
);
37+
$payment->setAdditionalInformation('instructions', $this->getInstructions($payment));
3838
} elseif ($payment->getMethod() === Checkmo::PAYMENT_METHOD_CHECKMO_CODE) {
3939
$methodInstance = $payment->getMethodInstance();
4040
if (!empty($methodInstance->getPayableTo())) {
@@ -45,4 +45,17 @@ public function execute(\Magento\Framework\Event\Observer $observer)
4545
}
4646
}
4747
}
48+
49+
/**
50+
* Retrieve store-specific payment method instructions, or already saved if exists.
51+
*
52+
* @param Payment $payment
53+
* @return string|null
54+
* @throws \Magento\Framework\Exception\LocalizedException
55+
*/
56+
private function getInstructions(Payment $payment): ?string
57+
{
58+
return $payment->getAdditionalInformation('instructions')
59+
?: $payment->getMethodInstance()->getConfigData('instructions', $payment->getOrder()->getStoreId());
60+
}
4861
}

app/code/Magento/OfflinePayments/Test/Unit/Observer/BeforeOrderPaymentSaveObserverTest.php

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use Magento\OfflinePayments\Model\Banktransfer;
1212
use Magento\OfflinePayments\Model\Cashondelivery;
1313
use Magento\OfflinePayments\Observer\BeforeOrderPaymentSaveObserver;
14+
use Magento\Sales\Model\Order;
1415
use Magento\Sales\Model\Order\Payment;
1516
use PHPUnit_Framework_MockObject_MockObject as MockObject;
1617
use Magento\OfflinePayments\Model\Checkmo;
@@ -76,19 +77,12 @@ public function testBeforeOrderPaymentSaveWithInstructions($methodCode)
7677
$this->payment->expects(self::once())
7778
->method('getMethod')
7879
->willReturn($methodCode);
80+
$this->payment->method('getAdditionalInformation')
81+
->with('instructions')
82+
->willReturn('payment configuration');
7983
$this->payment->expects(self::once())
8084
->method('setAdditionalInformation')
8185
->with('instructions', 'payment configuration');
82-
$method = $this->getMockBuilder(Banktransfer::class)
83-
->disableOriginalConstructor()
84-
->getMock();
85-
86-
$method->expects(self::once())
87-
->method('getInstructions')
88-
->willReturn('payment configuration');
89-
$this->payment->expects(self::once())
90-
->method('getMethodInstance')
91-
->willReturn($method);
9286

9387
$this->_model->execute($this->observer);
9488
}

app/code/Magento/OfflinePayments/composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
"php": "~7.1.3||~7.2.0||~7.3.0",
99
"magento/framework": "*",
1010
"magento/module-checkout": "*",
11-
"magento/module-payment": "*"
11+
"magento/module-payment": "*",
12+
"magento/module-sales": "*"
1213
},
1314
"suggest": {
1415
"magento/module-config": "*"

app/code/Magento/Payment/Block/Info/Instructions.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,18 @@ class Instructions extends \Magento\Payment\Block\Info
2525
*/
2626
protected $_template = 'Magento_Payment::info/instructions.phtml';
2727

28+
/**
29+
* Gets payment method title for appropriate store.
30+
*
31+
* @return string
32+
* @throws \Magento\Framework\Exception\LocalizedException
33+
*/
34+
public function getTitle()
35+
{
36+
return $this->getInfo()->getAdditionalInformation('method_title')
37+
?: $this->getMethod()->getConfigData('title', $this->getInfo()->getOrder()->getStoreId());
38+
}
39+
2840
/**
2941
* Get instructions text from order payment
3042
* (or from config, if instructions are missed in payment)

app/code/Magento/Payment/Test/Unit/Block/Info/InstructionsTest.php

Lines changed: 81 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@
44
* See COPYING.txt for license details.
55
*/
66

7-
/**
8-
* Test class for \Magento\Payment\Block\Info\Instructions
9-
*/
107
namespace Magento\Payment\Test\Unit\Block\Info;
118

9+
use Magento\Payment\Model\MethodInterface;
10+
use Magento\Sales\Model\Order;
11+
use PHPUnit\Framework\MockObject\MockObject;
12+
1213
class InstructionsTest extends \PHPUnit\Framework\TestCase
1314
{
1415
/**
@@ -25,10 +26,59 @@ protected function setUp()
2526
{
2627
$context = $this->createMock(\Magento\Framework\View\Element\Template\Context::class);
2728
$this->_instructions = new \Magento\Payment\Block\Info\Instructions($context);
28-
$this->_info = $this->createMock(\Magento\Payment\Model\Info::class);
29+
$this->_info = $this->getMockBuilder(\Magento\Payment\Model\Info::class)
30+
->setMethods(
31+
[
32+
'getOrder',
33+
'getAdditionalInformation',
34+
'getMethodInstance'
35+
]
36+
)
37+
->disableOriginalConstructor()
38+
->getMock();
2939
$this->_instructions->setData('info', $this->_info);
3040
}
3141

42+
/**
43+
* @return void
44+
* @throws \Magento\Framework\Exception\LocalizedException
45+
*/
46+
public function testGetTitleFromPaymentAdditionalData()
47+
{
48+
$this->_info->method('getAdditionalInformation')
49+
->with('method_title')
50+
->willReturn('payment_method_title');
51+
52+
$this->getMethod()->expects($this->never())
53+
->method('getConfigData');
54+
55+
$this->assertEquals($this->_instructions->getTitle(), 'payment_method_title');
56+
}
57+
58+
/**
59+
* @return void
60+
* @throws \Magento\Framework\Exception\LocalizedException
61+
*/
62+
public function testGetTitleFromPaymentMethodConfig()
63+
{
64+
$this->_info->method('getAdditionalInformation')
65+
->with('method_title')
66+
->willReturn(null);
67+
68+
$this->getMethod()->expects($this->once())
69+
->method('getConfigData')
70+
->with('title', null)
71+
->willReturn('payment_method_title');
72+
73+
$order = $this->getOrder();
74+
$this->_info->method('getOrder')->willReturn($order);
75+
76+
$this->assertEquals($this->_instructions->getTitle(), 'payment_method_title');
77+
}
78+
79+
/**
80+
* @return void
81+
*/
3282
public function testGetInstructionAdditionalInformation()
3383
{
3484
$this->_info->expects($this->once())
@@ -41,10 +91,13 @@ public function testGetInstructionAdditionalInformation()
4191
$this->assertEquals('get the instruction here', $this->_instructions->getInstructions());
4292
}
4393

94+
/**
95+
* @return void
96+
*/
4497
public function testGetInstruction()
4598
{
4699
$methodInstance = $this->getMockBuilder(
47-
\Magento\Payment\Model\MethodInterface::class
100+
MethodInterface::class
48101
)->getMockForAbstractClass();
49102
$methodInstance->expects($this->once())
50103
->method('getConfigData')
@@ -59,4 +112,27 @@ public function testGetInstruction()
59112
->willReturn($methodInstance);
60113
$this->assertEquals('get the instruction here', $this->_instructions->getInstructions());
61114
}
115+
116+
/**
117+
* @return MethodInterface|MockObject
118+
*/
119+
private function getMethod()
120+
{
121+
$method = $this->getMockBuilder(MethodInterface::class)
122+
->getMockForAbstractClass();
123+
$this->_info->method('getMethodInstance')
124+
->willReturn($method);
125+
126+
return $method;
127+
}
128+
129+
/**
130+
* @return Order|MockObject
131+
*/
132+
private function getOrder()
133+
{
134+
return $this->getMockBuilder(Order::class)
135+
->disableOriginalConstructor()
136+
->getMock();
137+
}
62138
}

app/code/Magento/Payment/view/adminhtml/templates/info/instructions.phtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* @see \Magento\Payment\Block\Info
1010
*/
1111
?>
12-
<p><?= $block->escapeHtml($block->getMethod()->getTitle()) ?></p>
12+
<p><?= $block->escapeHtml($block->getTitle()) ?></p>
1313
<?php if ($block->getInstructions()) : ?>
1414
<table>
1515
<tbody>

app/code/Magento/Payment/view/frontend/templates/info/instructions.phtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
*/
1111
?>
1212
<dl class="payment-method">
13-
<dt class="title"><?= $block->escapeHtml($block->getMethod()->getTitle()) ?></dt>
13+
<dt class="title"><?= $block->escapeHtml($block->getTitle()) ?></dt>
1414
<?php if ($block->getInstructions()) : ?>
1515
<dd class="content"><?= /* @noEscape */ nl2br($block->escapeHtml($block->getInstructions())) ?></dd>
1616
<?php endif; ?>

0 commit comments

Comments
 (0)