Skip to content

Commit db937f7

Browse files
committed
Merge remote-tracking branch 'mainline/2.2-develop' into DEVOPS-2174-2.2
2 parents 775fddb + e49ccf7 commit db937f7

File tree

59 files changed

+1092
-365
lines changed

Some content is hidden

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

59 files changed

+1092
-365
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ The members of this team have been recognized for their outstanding commitment t
3535
</a>
3636

3737
<h3>Top Contributors</h3>
38-
Magento team thanks for any contribution that can improve our code base, documentation or increase test coverage. We always recognize our most active members, your contributions are the foundation of the Magento open source platform.
38+
Magento is thankful for any contribution that can improve our code base, documentation or increase test coverage. We always recognize our most active members, as their contributions are the foundation of the Magento Open Source platform.
3939
<a href="https://magento.com/magento-contributors">
4040
<img src="https://raw.githubusercontent.com/wiki/magento/magento2/images/contributors.png"/>
4141
</a>

app/code/Magento/Braintree/Model/Adminhtml/System/Config/CountryCreditCard.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,13 @@ public function __construct(
6666
public function beforeSave()
6767
{
6868
$value = $this->getValue();
69+
if (!is_array($value)) {
70+
try {
71+
$value = $this->serializer->unserialize($value);
72+
} catch (\InvalidArgumentException $e) {
73+
$value = [];
74+
}
75+
}
6976
$result = [];
7077
foreach ($value as $data) {
7178
if (empty($data['country_id']) || empty($data['cc_types'])) {

app/code/Magento/Braintree/Model/AvsEmsCodeMapper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class AvsEmsCodeMapper implements PaymentVerificationInterface
2424
*
2525
* @var string
2626
*/
27-
private static $unavailableCode = 'U';
27+
private static $unavailableCode = '';
2828

2929
/**
3030
* List of mapping AVS codes

app/code/Magento/Braintree/Test/Unit/Model/AvsEmsCodeMapperTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,11 @@ public function testGetCodeWithException()
8484
public function getCodeDataProvider()
8585
{
8686
return [
87-
['avsZip' => null, 'avsStreet' => null, 'expected' => 'U'],
88-
['avsZip' => null, 'avsStreet' => 'M', 'expected' => 'U'],
89-
['avsZip' => 'M', 'avsStreet' => null, 'expected' => 'U'],
90-
['avsZip' => 'M', 'avsStreet' => 'Unknown', 'expected' => 'U'],
91-
['avsZip' => 'I', 'avsStreet' => 'A', 'expected' => 'U'],
87+
['avsZip' => null, 'avsStreet' => null, 'expected' => ''],
88+
['avsZip' => null, 'avsStreet' => 'M', 'expected' => ''],
89+
['avsZip' => 'M', 'avsStreet' => null, 'expected' => ''],
90+
['avsZip' => 'M', 'avsStreet' => 'Unknown', 'expected' => ''],
91+
['avsZip' => 'I', 'avsStreet' => 'A', 'expected' => ''],
9292
['avsZip' => 'M', 'avsStreet' => 'M', 'expected' => 'Y'],
9393
['avsZip' => 'N', 'avsStreet' => 'M', 'expected' => 'A'],
9494
['avsZip' => 'M', 'avsStreet' => 'N', 'expected' => 'Z'],

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

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use Magento\Catalog\Model\Product\Attribute\Backend\Media\EntryConverterPool;
1313
use Magento\Framework\Api\AttributeValueFactory;
1414
use Magento\Framework\App\Filesystem\DirectoryList;
15+
use Magento\Framework\App\ObjectManager;
1516
use Magento\Framework\DataObject\IdentityInterface;
1617
use Magento\Framework\Pricing\SaleableInterface;
1718

@@ -270,6 +271,7 @@ class Product extends \Magento\Catalog\Model\AbstractModel implements
270271

271272
/**
272273
* @var \Magento\Catalog\Api\ProductAttributeRepositoryInterface
274+
* @deprecated Not used anymore due to performance issue (loaded all product attributes)
273275
*/
274276
protected $metadataService;
275277

@@ -346,6 +348,11 @@ class Product extends \Magento\Catalog\Model\AbstractModel implements
346348
*/
347349
protected $linkTypeProvider;
348350

351+
/**
352+
* @var \Magento\Eav\Model\Config
353+
*/
354+
private $eavConfig;
355+
349356
/**
350357
* Product constructor.
351358
* @param \Magento\Framework\Model\Context $context
@@ -383,7 +390,7 @@ class Product extends \Magento\Catalog\Model\AbstractModel implements
383390
* @param \Magento\Framework\Api\DataObjectHelper $dataObjectHelper
384391
* @param \Magento\Framework\Api\ExtensionAttribute\JoinProcessorInterface $joinProcessor
385392
* @param array $data
386-
*
393+
* @param \Magento\Eav\Model\Config|null $config
387394
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
388395
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
389396
*/
@@ -422,7 +429,8 @@ public function __construct(
422429
EntryConverterPool $mediaGalleryEntryConverterPool,
423430
\Magento\Framework\Api\DataObjectHelper $dataObjectHelper,
424431
\Magento\Framework\Api\ExtensionAttribute\JoinProcessorInterface $joinProcessor,
425-
array $data = []
432+
array $data = [],
433+
\Magento\Eav\Model\Config $config = null
426434
) {
427435
$this->metadataService = $metadataService;
428436
$this->_itemOptionFactory = $itemOptionFactory;
@@ -461,6 +469,7 @@ public function __construct(
461469
$resourceCollection,
462470
$data
463471
);
472+
$this->eavConfig = $config ?? ObjectManager::getInstance()->get(\Magento\Eav\Model\Config::class);
464473
}
465474

466475
/**
@@ -474,12 +483,18 @@ protected function _construct()
474483
}
475484

476485
/**
477-
* {@inheritdoc}
486+
* Get a list of custom attribute codes that belongs to product attribute set. If attribute set not specified for
487+
* product will return all attribute codes
488+
*
489+
* @return string[]
478490
*/
479491
protected function getCustomAttributesCodes()
480492
{
481493
if ($this->customAttributesCodes === null) {
482-
$this->customAttributesCodes = $this->getEavAttributesCodes($this->metadataService);
494+
$this->customAttributesCodes = array_keys($this->eavConfig->getEntityAttributes(
495+
self::ENTITY,
496+
$this
497+
));
483498
$this->customAttributesCodes = array_diff($this->customAttributesCodes, $this->interfaceAttributes);
484499
}
485500
return $this->customAttributesCodes;

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

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -172,8 +172,10 @@ private function getExistingPrices(array $skus, $groupBySku = false)
172172
$rawPrices = $this->tierPricePersistence->get($ids);
173173
$prices = [];
174174

175+
$linkField = $this->tierPricePersistence->getEntityLinkField();
176+
$skuByIdLookup = $this->buildSkuByIdLookup($skus);
175177
foreach ($rawPrices as $rawPrice) {
176-
$sku = $this->retrieveSkuById($rawPrice[$this->tierPricePersistence->getEntityLinkField()], $skus);
178+
$sku = $skuByIdLookup[$rawPrice[$linkField]];
177179
$price = $this->tierPriceFactory->create($rawPrice, $sku);
178180
if ($groupBySku) {
179181
$prices[$sku][] = $price;
@@ -300,21 +302,21 @@ private function isCorrectPriceValue(array $existingPrice, array $price)
300302
}
301303

302304
/**
303-
* Retrieve SKU by product ID.
305+
* Generate lookup to retrieve SKU by product ID.
304306
*
305-
* @param int $id
306307
* @param array $skus
307-
* @return string|null
308+
* @return array
308309
*/
309-
private function retrieveSkuById($id, $skus)
310+
private function buildSkuByIdLookup($skus)
310311
{
312+
$lookup = [];
311313
foreach ($this->productIdLocator->retrieveProductIdsBySkus($skus) as $sku => $ids) {
312-
if (isset($ids[$id])) {
313-
return $sku;
314+
foreach (array_keys($ids) as $id) {
315+
$lookup[$id] = $sku;
314316
}
315317
}
316318

317-
return null;
319+
return $lookup;
318320
}
319321

320322
/**

app/code/Magento/Catalog/Plugin/Model/ResourceModel/ReadSnapshotPlugin.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,9 @@ public function afterExecute(ReadSnapshot $subject, array $entityData, $entityTy
5858
$globalAttributes = [];
5959
$attributesMap = [];
6060
$eavEntityType = $metadata->getEavEntityType();
61-
$attributes = (null === $eavEntityType) ? [] : $this->config->getEntityAttributes($eavEntityType);
61+
$attributes = null === $eavEntityType
62+
? []
63+
: $this->config->getEntityAttributes($eavEntityType, new \Magento\Framework\DataObject($entityData));
6264

6365
/** @var \Magento\Eav\Model\Entity\Attribute\AbstractAttribute $attribute */
6466
foreach ($attributes as $attribute) {

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

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,11 @@ class ProductTest extends \PHPUnit\Framework\TestCase
205205
*/
206206
private $cacheInterfaceMock;
207207

208+
/**
209+
* @var \Magento\Eav\Model\Config|\PHPUnit_Framework_MockObject_MockObject
210+
*/
211+
private $eavConfig;
212+
208213
/**
209214
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
210215
*/
@@ -364,6 +369,7 @@ protected function setUp()
364369
->setMethods(['create'])
365370
->getMock();
366371
$this->mediaConfig = $this->createMock(\Magento\Catalog\Model\Product\Media\Config::class);
372+
$this->eavConfig = $this->createMock(\Magento\Eav\Model\Config::class);
367373

368374
$this->extensionAttributes = $this->getMockBuilder(ProductExtensionInterface::class)
369375
->setMethods(['getStockItem'])
@@ -401,7 +407,8 @@ protected function setUp()
401407
'catalogProductMediaConfig' => $this->mediaConfig,
402408
'_filesystem' => $this->filesystemMock,
403409
'_collectionFactory' => $this->collectionFactoryMock,
404-
'data' => ['id' => 1]
410+
'data' => ['id' => 1],
411+
'eavConfig' => $this->eavConfig
405412
]
406413
);
407414
}
@@ -1269,39 +1276,32 @@ public function testGetCustomAttributes()
12691276
{
12701277
$priceCode = 'price';
12711278
$colorAttributeCode = 'color';
1272-
$interfaceAttribute = $this->createMock(\Magento\Framework\Api\MetadataObjectInterface::class);
1273-
$interfaceAttribute->expects($this->once())
1274-
->method('getAttributeCode')
1275-
->willReturn($priceCode);
1276-
$colorAttribute = $this->createMock(\Magento\Framework\Api\MetadataObjectInterface::class);
1277-
$colorAttribute->expects($this->once())
1278-
->method('getAttributeCode')
1279-
->willReturn($colorAttributeCode);
1280-
$customAttributesMetadata = [$interfaceAttribute, $colorAttribute];
1281-
1282-
$this->metadataServiceMock->expects($this->once())
1283-
->method('getCustomAttributesMetadata')
1279+
$customAttributesMetadata = [$priceCode => 'attribute1', $colorAttributeCode => 'attribute2'];
1280+
1281+
$this->metadataServiceMock->expects($this->never())->method('getCustomAttributesMetadata');
1282+
$this->eavConfig->expects($this->once())
1283+
->method('getEntityAttributes')
12841284
->willReturn($customAttributesMetadata);
12851285
$this->model->setData($priceCode, 10);
12861286

12871287
//The color attribute is not set, expect empty custom attribute array
12881288
$this->assertEquals([], $this->model->getCustomAttributes());
12891289

12901290
//Set the color attribute;
1291-
$this->model->setData($colorAttributeCode, "red");
1291+
$this->model->setData($colorAttributeCode, 'red');
12921292
$attributeValue = new \Magento\Framework\Api\AttributeValue();
12931293
$attributeValue2 = new \Magento\Framework\Api\AttributeValue();
12941294
$this->attributeValueFactory->expects($this->exactly(2))->method('create')
12951295
->willReturnOnConsecutiveCalls($attributeValue, $attributeValue2);
12961296
$this->assertEquals(1, count($this->model->getCustomAttributes()));
12971297
$this->assertNotNull($this->model->getCustomAttribute($colorAttributeCode));
1298-
$this->assertEquals("red", $this->model->getCustomAttribute($colorAttributeCode)->getValue());
1298+
$this->assertEquals('red', $this->model->getCustomAttribute($colorAttributeCode)->getValue());
12991299

13001300
//Change the attribute value, should reflect in getCustomAttribute
1301-
$this->model->setCustomAttribute($colorAttributeCode, "blue");
1301+
$this->model->setCustomAttribute($colorAttributeCode, 'blue');
13021302
$this->assertEquals(1, count($this->model->getCustomAttributes()));
13031303
$this->assertNotNull($this->model->getCustomAttribute($colorAttributeCode));
1304-
$this->assertEquals("blue", $this->model->getCustomAttribute($colorAttributeCode)->getValue());
1304+
$this->assertEquals('blue', $this->model->getCustomAttribute($colorAttributeCode)->getValue());
13051305
}
13061306

13071307
/**

app/code/Magento/Catalog/view/frontend/web/js/product/breadcrumbs.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ define([
1010
'use strict';
1111

1212
return function (widget) {
13+
1314
$.widget('mage.breadcrumbs', widget, {
1415
options: {
1516
categoryUrlSuffix: '',
@@ -26,9 +27,9 @@ define([
2627
menu = $(this.options.menuContainer).data('mageMenu');
2728

2829
if (typeof menu === 'undefined') {
29-
$(this.options.menuContainer).on('menucreate', function () {
30-
this._super();
31-
}.bind(this));
30+
this._on($(this.options.menuContainer), {
31+
'menucreate': this._super
32+
});
3233
} else {
3334
this._super();
3435
}

app/code/Magento/Checkout/Model/GuestPaymentInformationManagement.php

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use Magento\Framework\App\ResourceConnection;
1111
use Magento\Quote\Api\CartRepositoryInterface;
1212
use Magento\Framework\Exception\CouldNotSaveException;
13+
use Magento\Quote\Model\Quote;
1314

1415
/**
1516
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
@@ -135,13 +136,19 @@ public function savePaymentInformation(
135136
\Magento\Quote\Api\Data\PaymentInterface $paymentMethod,
136137
\Magento\Quote\Api\Data\AddressInterface $billingAddress = null
137138
) {
139+
$quoteIdMask = $this->quoteIdMaskFactory->create()->load($cartId, 'masked_id');
140+
/** @var Quote $quote */
141+
$quote = $this->cartRepository->getActive($quoteIdMask->getQuoteId());
142+
138143
if ($billingAddress) {
139144
$billingAddress->setEmail($email);
140-
$this->billingAddressManagement->assign($cartId, $billingAddress);
145+
$quote->removeAddress($quote->getBillingAddress()->getId());
146+
$quote->setBillingAddress($billingAddress);
147+
$quote->setDataChanges(true);
141148
} else {
142-
$quoteIdMask = $this->quoteIdMaskFactory->create()->load($cartId, 'masked_id');
143-
$this->cartRepository->getActive($quoteIdMask->getQuoteId())->getBillingAddress()->setEmail($email);
149+
$quote->getBillingAddress()->setEmail($email);
144150
}
151+
$this->limitShippingCarrier($quote);
145152

146153
$this->paymentMethodManagement->set($cartId, $paymentMethod);
147154
return true;
@@ -169,4 +176,22 @@ private function getLogger()
169176
}
170177
return $this->logger;
171178
}
179+
180+
/**
181+
* Limits shipping rates request by carrier from shipping address.
182+
*
183+
* @param Quote $quote
184+
*
185+
* @return void
186+
* @see \Magento\Shipping\Model\Shipping::collectRates
187+
*/
188+
private function limitShippingCarrier(Quote $quote)
189+
{
190+
$shippingAddress = $quote->getShippingAddress();
191+
if ($shippingAddress && $shippingAddress->getShippingMethod()) {
192+
$shippingDataArray = explode('_', $shippingAddress->getShippingMethod());
193+
$shippingCarrier = array_shift($shippingDataArray);
194+
$shippingAddress->setLimitCarrier($shippingCarrier);
195+
}
196+
}
172197
}

0 commit comments

Comments
 (0)