Skip to content

Commit 4f1d406

Browse files
committed
Merge remote-tracking branch 'origin/MC-23554' into 2.4-develop-pr111
2 parents 57f5832 + 4f8aab6 commit 4f1d406

File tree

44 files changed

+1636
-219
lines changed

Some content is hidden

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

44 files changed

+1636
-219
lines changed
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
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\Model\Sales\Order\Shipment;
9+
10+
use Magento\Catalog\Model\Product\Type;
11+
use Magento\Sales\Model\ValidatorInterface;
12+
13+
/**
14+
* Validate if requested order items can be shipped according to bundle product shipment type
15+
*/
16+
class BundleShipmentTypeValidator implements ValidatorInterface
17+
{
18+
/**
19+
* @inheritdoc
20+
*/
21+
public function validate($item)
22+
{
23+
$result = [];
24+
if (!$item->isDummy(true)) {
25+
return $result;
26+
}
27+
28+
$message = 'Cannot create shipment as bundle product "%1" has shipment type "%2". ' .
29+
'%3 should be shipped instead.';
30+
31+
if ($item->getHasChildren() && $item->getProductType() === Type::TYPE_BUNDLE) {
32+
$result[] = __(
33+
$message,
34+
$item->getSku(),
35+
__('Separately'),
36+
__('Bundle product options'),
37+
);
38+
}
39+
40+
if ($item->getParentItem() && $item->getParentItem()->getProductType() === Type::TYPE_BUNDLE) {
41+
$result[] = __(
42+
$message,
43+
$item->getParentItem()->getSku(),
44+
__('Together'),
45+
__('Bundle product itself'),
46+
);
47+
}
48+
49+
return $result;
50+
}
51+
}

app/code/Magento/Bundle/etc/di.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,4 +234,11 @@
234234
</argument>
235235
</arguments>
236236
</type>
237+
<type name="Magento\Sales\Model\Order\Shipment\ShipmentItemsValidator">
238+
<arguments>
239+
<argument name="validators" xsi:type="array">
240+
<item name="shipment_type" xsi:type="object">Magento\Bundle\Model\Sales\Order\Shipment\BundleShipmentTypeValidator</item>
241+
</argument>
242+
</arguments>
243+
</type>
237244
</config>

app/code/Magento/Bundle/i18n/en_US.csv

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,3 +105,6 @@ Select...,Select...
105105
Status,Status
106106
Thumbnail,Thumbnail
107107
Type,Type
108+
"Cannot create shipment as bundle product ""%1"" has shipment type ""%2"". %3 should be shipped instead.","Cannot create shipment as bundle product ""%1"" has shipment type ""%2"". %3 should be shipped instead."
109+
"Bundle product itself","Bundle product itself"
110+
"Bundle product options","Bundle product options"

app/code/Magento/CatalogImportExport/Test/Unit/Model/Export/ProductTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,8 @@ protected function setUp(): void
172172

173173
$this->productFactory = $this->getMockBuilder(
174174
\Magento\Catalog\Model\ResourceModel\ProductFactory::class
175-
)->addMethods(['getTypeId'])
175+
)->disableOriginalConstructor()
176+
->addMethods(['getTypeId'])
176177
->onlyMethods(['create'])
177178
->getMock();
178179

app/code/Magento/Checkout/Test/Unit/Model/ShippingInformationManagementTest.php

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
use Magento\Quote\Model\ShippingAssignmentFactory;
3333
use Magento\Quote\Model\ShippingFactory;
3434
use PHPUnit\Framework\MockObject\MockObject;
35+
use PHPUnit\Framework\MockObject\RuntimeException;
3536
use PHPUnit\Framework\TestCase;
3637

3738
/**
@@ -148,7 +149,7 @@ protected function setUp(): void
148149
'importCustomerAddressData',
149150
'save',
150151
'getShippingRateByCode',
151-
'getShippingMethod'
152+
'getShippingMethod',
152153
]
153154
)
154155
->disableOriginalConstructor()
@@ -167,7 +168,7 @@ protected function setUp(): void
167168
'collectTotals',
168169
'getExtensionAttributes',
169170
'setExtensionAttributes',
170-
'setBillingAddress'
171+
'setBillingAddress',
171172
]
172173
)
173174
->disableOriginalConstructor()
@@ -238,9 +239,7 @@ private function setShippingAssignmentsMocks($shippingMethod): void
238239
->willReturn(null);
239240
$this->shippingAddressMock->expects($this->once())
240241
->method('setLimitCarrier');
241-
$this->cartExtensionMock = $this->getMockBuilder(CartExtension::class)
242-
->addMethods(['getShippingAssignments', 'setShippingAssignments'])
243-
->getMock();
242+
$this->cartExtensionMock = $this->getCartExtensionMock();
244243
$this->cartExtensionFactoryMock->expects($this->once())
245244
->method('create')
246245
->willReturn($this->cartExtensionMock);
@@ -622,4 +621,21 @@ public function testSaveAddressInformation(): void
622621
$this->model->saveAddressInformation($cartId, $addressInformationMock)
623622
);
624623
}
624+
625+
/**
626+
* Build cart extension mock.
627+
*
628+
* @return MockObject
629+
*/
630+
private function getCartExtensionMock(): MockObject
631+
{
632+
$mockBuilder = $this->getMockBuilder(CartExtension::class);
633+
try {
634+
$mockBuilder->addMethods(['getShippingAssignments', 'setShippingAssignments']);
635+
} catch (RuntimeException $e) {
636+
// CartExtension already generated.
637+
}
638+
639+
return $mockBuilder->getMock();
640+
}
625641
}

app/code/Magento/CheckoutAgreements/Test/Unit/Model/Checkout/Plugin/GuestValidationTest.php

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
use Magento\Quote\Api\Data\PaymentInterface;
2121
use Magento\Store\Model\ScopeInterface;
2222
use PHPUnit\Framework\MockObject\MockObject;
23+
use PHPUnit\Framework\MockObject\RuntimeException;
2324
use PHPUnit\Framework\TestCase;
2425

2526
/**
@@ -78,9 +79,7 @@ protected function setUp(): void
7879
$this->subjectMock = $this->getMockForAbstractClass(GuestPaymentInformationManagementInterface::class);
7980
$this->paymentMock = $this->getMockForAbstractClass(PaymentInterface::class);
8081
$this->addressMock = $this->getMockForAbstractClass(AddressInterface::class);
81-
$this->extensionAttributesMock = $this->getMockBuilder(PaymentExtension::class)
82-
->addMethods(['getAgreementIds'])
83-
->getMock();
82+
$this->extensionAttributesMock = $this->getPaymentExtension();
8483
$this->scopeConfigMock = $this->getMockForAbstractClass(ScopeConfigInterface::class);
8584
$this->checkoutAgreementsListMock = $this->createMock(
8685
CheckoutAgreementsListInterface::class
@@ -165,4 +164,21 @@ public function testBeforeSavePaymentInformationAndPlaceOrderIfAgreementsNotVali
165164
"The order wasn't placed. First, agree to the terms and conditions, then try placing your order again."
166165
);
167166
}
167+
168+
/**
169+
* Build payment extension mock.
170+
*
171+
* @return MockObject
172+
*/
173+
private function getPaymentExtension(): MockObject
174+
{
175+
$mockBuilder = $this->getMockBuilder(PaymentExtension::class);
176+
try {
177+
$mockBuilder->addMethods(['getAgreementIds']);
178+
} catch (RuntimeException $e) {
179+
// Payment extension already generated.
180+
}
181+
182+
return $mockBuilder->getMock();
183+
}
168184
}

app/code/Magento/CheckoutAgreements/Test/Unit/Model/Checkout/Plugin/ValidationTest.php

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
use Magento\Quote\Model\Quote;
2323
use Magento\Store\Model\ScopeInterface;
2424
use PHPUnit\Framework\MockObject\MockObject;
25+
use PHPUnit\Framework\MockObject\RuntimeException;
2526
use PHPUnit\Framework\TestCase;
2627

2728
/**
@@ -96,9 +97,7 @@ protected function setUp(): void
9697
->disableOriginalConstructor()
9798
->getMock();
9899
$this->quoteRepositoryMock = $this->getMockForAbstractClass(CartRepositoryInterface::class);
99-
$this->extensionAttributesMock = $this->getMockBuilder(PaymentExtension::class)
100-
->addMethods(['getAgreementIds'])
101-
->getMock();
100+
$this->extensionAttributesMock = $this->getPaymentExtension();
102101
$this->scopeConfigMock = $this->getMockForAbstractClass(ScopeConfigInterface::class);
103102
$this->checkoutAgreementsListMock = $this->createMock(
104103
CheckoutAgreementsListInterface::class
@@ -232,4 +231,21 @@ public function testBeforeSavePaymentInformation()
232231
->willReturn($this->extensionAttributesMock);
233232
$this->model->beforeSavePaymentInformation($this->subjectMock, $cartId, $this->paymentMock, $this->addressMock);
234233
}
234+
235+
/**
236+
* Build payment extension mock.
237+
*
238+
* @return MockObject
239+
*/
240+
private function getPaymentExtension(): MockObject
241+
{
242+
$mockBuilder = $this->getMockBuilder(PaymentExtension::class);
243+
try {
244+
$mockBuilder->addMethods(['getAgreementIds']);
245+
} catch (RuntimeException $e) {
246+
// Payment extension already generated.
247+
}
248+
249+
return $mockBuilder->getMock();
250+
}
235251
}

app/code/Magento/Customer/Model/Customer/DataProviderWithDefaultAddresses.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use Magento\Framework\Session\SessionManagerInterface;
1818
use Magento\Customer\Model\FileUploaderDataResolver;
1919
use Magento\Customer\Model\AttributeMetadataResolver;
20+
use Magento\Ui\Component\Form\Element\Multiline;
2021
use Magento\Ui\DataProvider\AbstractDataProvider;
2122

2223
/**
@@ -130,6 +131,7 @@ public function getData(): array
130131
$result['customer'],
131132
array_flip(self::$forbiddenCustomerFields)
132133
);
134+
$this->prepareCustomAttributeValue($result['customer']);
133135
unset($result['address']);
134136

135137
$result['default_billing_address'] = $this->prepareDefaultAddress(
@@ -179,6 +181,24 @@ private function prepareDefaultAddress($address): array
179181
return $addressData;
180182
}
181183

184+
/***
185+
* Prepare values for Custom Attributes.
186+
*
187+
* @param array $data
188+
* @return void
189+
*/
190+
private function prepareCustomAttributeValue(array &$data): void
191+
{
192+
foreach ($this->meta['customer']['children'] as $attributeName => $attributeMeta) {
193+
if ($attributeMeta['arguments']['data']['config']['dataType'] === Multiline::NAME
194+
&& isset($data[$attributeName])
195+
&& !is_array($data[$attributeName])
196+
) {
197+
$data[$attributeName] = explode("\n", $data[$attributeName]);
198+
}
199+
}
200+
}
201+
182202
/**
183203
* Get attributes meta
184204
*

app/code/Magento/Customer/Model/Metadata/Form/Multiline.php

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
class Multiline extends Text
1111
{
1212
/**
13-
* {@inheritdoc}
13+
* @inheritDoc
1414
*/
1515
public function extractValue(\Magento\Framework\App\RequestInterface $request)
1616
{
@@ -24,7 +24,8 @@ public function extractValue(\Magento\Framework\App\RequestInterface $request)
2424
}
2525

2626
/**
27-
* {@inheritdoc}
27+
* @inheritDoc
28+
*
2829
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
2930
*/
3031
public function validateValue($value)
@@ -43,7 +44,8 @@ public function validateValue($value)
4344
if (!is_array($value)) {
4445
$value = [$value];
4546
}
46-
for ($i = 0; $i < $attribute->getMultilineCount(); $i++) {
47+
$multilineCount = $attribute->getMultilineCount();
48+
for ($i = 0; $i < $multilineCount; $i++) {
4749
if (!isset($value[$i])) {
4850
$value[$i] = null;
4951
}
@@ -57,6 +59,7 @@ public function validateValue($value)
5759
if (!empty($value[$i])) {
5860
$result = parent::validateValue($value[$i]);
5961
if ($result !== true) {
62+
// phpcs:ignore Magento2.Performance.ForeachArrayMerge
6063
$errors = array_merge($errors, $result);
6164
}
6265
}
@@ -70,26 +73,28 @@ public function validateValue($value)
7073
}
7174

7275
/**
73-
* {@inheritdoc}
76+
* @inheritDoc
7477
*/
7578
public function compactValue($value)
7679
{
77-
if (!is_array($value)) {
78-
$value = [$value];
80+
if (is_array($value)) {
81+
$value = trim(implode("\n", $value));
7982
}
83+
$value = [$value];
84+
8085
return parent::compactValue($value);
8186
}
8287

8388
/**
84-
* {@inheritdoc}
89+
* @inheritDoc
8590
*/
8691
public function restoreValue($value)
8792
{
8893
return $this->compactValue($value);
8994
}
9095

9196
/**
92-
* {@inheritdoc}
97+
* @inheritDoc
9398
*/
9499
public function outputValue($format = \Magento\Customer\Model\Metadata\ElementFactory::OUTPUT_FORMAT_TEXT)
95100
{

app/code/Magento/Customer/Test/Unit/Model/Renderer/RegionTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@ function (array $attributes) use ($elementMock): string {
6666
}
6767
);
6868
$countryMock = $this->getMockBuilder(AbstractElement::class)
69-
->addMethods(['getValue', 'serialize'])
69+
->onlyMethods(['serialize'])
70+
->addMethods(['getValue'])
7071
->disableOriginalConstructor()
7172
->getMockForAbstractClass();
7273
$countryMock->method('serialize')->willReturnCallback(

0 commit comments

Comments
 (0)