Skip to content

Commit 75403ff

Browse files
committed
Merge remote-tracking branch 'origin/2.2-develop' into 2.2-develop-pr40
2 parents e0060a1 + b62b78b commit 75403ff

File tree

16 files changed

+254
-58
lines changed

16 files changed

+254
-58
lines changed
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
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\Braintree\Test\Unit\Model\InstantPurchase\PayPal;
9+
10+
use Magento\Braintree\Model\InstantPurchase\CreditCard\TokenFormatter as PaypalTokenFormatter;
11+
use Magento\Vault\Api\Data\PaymentTokenInterface;
12+
13+
class TokenFormatterTest extends \PHPUnit\Framework\TestCase
14+
{
15+
/**
16+
* @var PaymentTokenInterface|\PHPUnit_Framework_MockObject_MockObject
17+
*/
18+
private $paymentTokenMock;
19+
20+
/**
21+
* @var PaypalTokenFormatter
22+
*/
23+
private $paypalTokenFormatter;
24+
25+
/**
26+
* @var array
27+
*/
28+
private $tokenDetails = [
29+
'type' => 'visa',
30+
'maskedCC' => '4444************9999',
31+
'expirationDate' => '07-07-2025'
32+
];
33+
34+
protected function setUp()
35+
{
36+
$this->paymentTokenMock = $this->getMockBuilder(PaymentTokenInterface::class)
37+
->getMockForAbstractClass();
38+
39+
$this->paypalTokenFormatter = new PaypalTokenFormatter();
40+
}
41+
42+
public function testFormatPaymentTokenWithKnownCardType()
43+
{
44+
$this->tokenDetails['type'] = key(PaypalTokenFormatter::$baseCardTypes);
45+
$this->paymentTokenMock->expects($this->once())
46+
->method('getTokenDetails')
47+
->willReturn(json_encode($this->tokenDetails));
48+
49+
$formattedString = sprintf(
50+
'%s: %s, %s: %s (%s: %s)',
51+
__('Credit Card'),
52+
reset(PaypalTokenFormatter::$baseCardTypes),
53+
__('ending'),
54+
$this->tokenDetails['maskedCC'],
55+
__('expires'),
56+
$this->tokenDetails['expirationDate']
57+
);
58+
59+
self::assertEquals($formattedString, $this->paypalTokenFormatter->formatPaymentToken($this->paymentTokenMock));
60+
}
61+
62+
public function testFormatPaymentTokenWithUnknownCardType()
63+
{
64+
$this->paymentTokenMock->expects($this->once())
65+
->method('getTokenDetails')
66+
->willReturn(json_encode($this->tokenDetails));
67+
68+
$formattedString = sprintf(
69+
'%s: %s, %s: %s (%s: %s)',
70+
__('Credit Card'),
71+
$this->tokenDetails['type'],
72+
__('ending'),
73+
$this->tokenDetails['maskedCC'],
74+
__('expires'),
75+
$this->tokenDetails['expirationDate']
76+
);
77+
78+
self::assertEquals($formattedString, $this->paypalTokenFormatter->formatPaymentToken($this->paymentTokenMock));
79+
}
80+
81+
public function testFormatPaymentTokenWithWrongData()
82+
{
83+
unset($this->tokenDetails['type']);
84+
85+
$this->paymentTokenMock->expects($this->once())
86+
->method('getTokenDetails')
87+
->willReturn(json_encode($this->tokenDetails));
88+
self::expectException('\InvalidArgumentException');
89+
90+
$this->paypalTokenFormatter->formatPaymentToken($this->paymentTokenMock);
91+
}
92+
}

app/code/Magento/Catalog/Controller/Adminhtml/Product/Save.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,13 +148,13 @@ public function execute()
148148
} catch (\Magento\Framework\Exception\LocalizedException $e) {
149149
$this->_objectManager->get(\Psr\Log\LoggerInterface::class)->critical($e);
150150
$this->messageManager->addExceptionMessage($e);
151-
$data = $this->persistMediaData($product, $data);
151+
$data = isset($product) ? $this->persistMediaData($product, $data) : $data;
152152
$this->getDataPersistor()->set('catalog_product', $data);
153153
$redirectBack = $productId ? true : 'new';
154154
} catch (\Exception $e) {
155155
$this->_objectManager->get(\Psr\Log\LoggerInterface::class)->critical($e);
156156
$this->messageManager->addErrorMessage($e->getMessage());
157-
$data = $this->persistMediaData($product, $data);
157+
$data = isset($product) ? $this->persistMediaData($product, $data) : $data;
158158
$this->getDataPersistor()->set('catalog_product', $data);
159159
$redirectBack = $productId ? true : 'new';
160160
}

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

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,16 @@ public function process(\DOMElement $mediaNode, $mediaParentTag)
3232
continue;
3333
}
3434
$attributeTagName = $attribute->tagName;
35-
if ($attributeTagName === 'background') {
36-
$nodeValue = $this->processImageBackground($attribute->nodeValue);
37-
} elseif ($attributeTagName === 'width' || $attributeTagName === 'height') {
38-
$nodeValue = intval($attribute->nodeValue);
35+
if ((bool)$attribute->getAttribute('xsi:nil') !== true) {
36+
if ($attributeTagName === 'background') {
37+
$nodeValue = $this->processImageBackground($attribute->nodeValue);
38+
} elseif ($attributeTagName === 'width' || $attributeTagName === 'height') {
39+
$nodeValue = intval($attribute->nodeValue);
40+
} else {
41+
$nodeValue = $attribute->nodeValue;
42+
}
3943
} else {
40-
$nodeValue = $attribute->nodeValue;
44+
$nodeValue = null;
4145
}
4246
$result[$mediaParentTag][$moduleNameImage][Image::MEDIA_TYPE_CONFIG_NODE][$imageId][$attribute->tagName]
4347
= $nodeValue;

app/code/Magento/Catalog/Model/ProductRepository/MediaGalleryProcessor.php

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,13 @@ public function processMediaGallery(ProductInterface $product, array $mediaGalle
100100
$newEntries = $mediaGalleryEntries;
101101
}
102102

103-
$this->processor->clearMediaAttribute($product, array_keys($product->getMediaAttributes()));
104103
$images = $product->getMediaGallery('images');
104+
105+
if ($images) {
106+
$images = $this->determineImageRoles($product, $images);
107+
}
108+
109+
$this->processor->clearMediaAttribute($product, array_keys($product->getMediaAttributes()));
105110
if ($images) {
106111
foreach ($images as $image) {
107112
if (!isset($image['removed']) && !empty($image['types'])) {
@@ -112,6 +117,32 @@ public function processMediaGallery(ProductInterface $product, array $mediaGalle
112117
$this->processEntries($product, $newEntries, $entriesById);
113118
}
114119

120+
/**
121+
* Ascertain image roles, if they are not set against the gallery entries
122+
*
123+
* @param ProductInterface $product
124+
* @param array $images
125+
* @return array
126+
*/
127+
private function determineImageRoles(ProductInterface $product, array $images)
128+
{
129+
$imagesWithRoles = [];
130+
foreach ($images as $image) {
131+
if (!isset($image['types'])) {
132+
$image['types'] = [];
133+
if (isset($image['file'])) {
134+
foreach (array_keys($product->getMediaAttributes()) as $attribute) {
135+
if ($image['file'] == $product->getData($attribute)) {
136+
$image['types'][] = $attribute;
137+
}
138+
}
139+
}
140+
}
141+
$imagesWithRoles[] = $image;
142+
}
143+
return $imagesWithRoles;
144+
}
145+
115146
/**
116147
* Convert entries into product media gallery data and set to product.
117148
*

app/code/Magento/Checkout/view/frontend/web/js/region-updater.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,8 @@ define([
188188

189189
if (!this.options.optionalRegionAllowed) { //eslint-disable-line max-depth
190190
regionList.attr('disabled', 'disabled');
191+
} else {
192+
regionList.removeAttr('disabled');
191193
}
192194
}
193195

app/code/Magento/ConfigurableProduct/Model/Quote/Item/CartItemProcessor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public function convertToBuyRequest(CartItemInterface $cartItem)
6969
if (is_array($options)) {
7070
$requestData = [];
7171
foreach ($options as $option) {
72-
$requestData['super_attribute'][$option->getOptionId()] = $option->getOptionValue();
72+
$requestData['super_attribute'][$option->getOptionId()] = (string) $option->getOptionValue();
7373
}
7474
return $this->objectFactory->create($requestData);
7575
}

app/code/Magento/ConfigurableProduct/view/adminhtml/web/js/variations/variations.js

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -407,15 +407,17 @@ define([
407407
* - associated_product_ids_serialized.
408408
*/
409409
serializeData: function () {
410-
this.source.data['configurable-matrix-serialized'] =
411-
JSON.stringify(this.source.data['configurable-matrix']);
412-
413-
delete this.source.data['configurable-matrix'];
414-
415-
this.source.data['associated_product_ids_serialized'] =
416-
JSON.stringify(this.source.data['associated_product_ids']);
410+
if (this.source.data['configurable-matrix']) {
411+
this.source.data['configurable-matrix-serialized'] =
412+
JSON.stringify(this.source.data['configurable-matrix']);
413+
delete this.source.data['configurable-matrix'];
414+
}
417415

418-
delete this.source.data['associated_product_ids'];
416+
if (this.source.data['associated_product_ids']) {
417+
this.source.data['associated_product_ids_serialized'] =
418+
JSON.stringify(this.source.data['associated_product_ids']);
419+
delete this.source.data['associated_product_ids'];
420+
}
419421
},
420422

421423
/**

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,9 @@
7878
<item name="production" xsi:type="array">
7979
<item name="dev/debug/debug_logging" xsi:type="string">0</item>
8080
</item>
81+
<item name="developer" xsi:type="array">
82+
<item name="dev/debug/debug_logging" xsi:type="null" />
83+
</item>
8184
</item>
8285
</argument>
8386
</arguments>

app/code/Magento/Eav/Api/Data/AttributeInterface.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
11
<?php
22
/**
3-
*
43
* Copyright © Magento, Inc. All rights reserved.
54
* See COPYING.txt for license details.
65
*/
76
namespace Magento\Eav\Api\Data;
87

8+
use Magento\Framework\Api\CustomAttributesDataInterface;
9+
use Magento\Framework\Api\MetadataObjectInterface;
10+
911
/**
1012
* Interface AttributeInterface
1113
* @api
1214
* @since 100.0.2
1315
*/
14-
interface AttributeInterface extends \Magento\Framework\Api\CustomAttributesDataInterface
16+
interface AttributeInterface extends CustomAttributesDataInterface, MetadataObjectInterface
1517
{
1618
const ATTRIBUTE_ID = 'attribute_id';
1719

0 commit comments

Comments
 (0)