Skip to content

Commit 158707b

Browse files
author
Sergey Shvets
committed
Merge branch '2.2-develop' of github.com:magento/magento2ce into MAGETWO-73456
2 parents 971426c + 160dc85 commit 158707b

File tree

129 files changed

+2419
-425
lines changed

Some content is hidden

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

129 files changed

+2419
-425
lines changed

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/Block/Product/ListProduct.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ public function getIdentities()
356356
* Get post parameters
357357
*
358358
* @param Product $product
359-
* @return string
359+
* @return array
360360
*/
361361
public function getAddToCartPostParams(Product $product)
362362
{

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/Attribute/SetRepository.php

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
*/
77
namespace Magento\Catalog\Model\Product\Attribute;
88

9-
use Magento\Framework\Exception\InputException;
10-
119
class SetRepository implements \Magento\Catalog\Api\AttributeSetRepositoryInterface
1210
{
1311
/**
@@ -53,7 +51,7 @@ public function __construct(
5351
*/
5452
public function save(\Magento\Eav\Api\Data\AttributeSetInterface $attributeSet)
5553
{
56-
$this->validate($attributeSet);
54+
$this->validateBeforeSave($attributeSet);
5755
return $this->attributeSetRepository->save($attributeSet);
5856
}
5957

@@ -127,4 +125,29 @@ protected function validate(\Magento\Eav\Api\Data\AttributeSetInterface $attribu
127125
);
128126
}
129127
}
128+
129+
/**
130+
* Validate attribute set entity type id.
131+
*
132+
* @param \Magento\Eav\Api\Data\AttributeSetInterface $attributeSet
133+
* @return void
134+
* @throws \Magento\Framework\Exception\StateException
135+
* @throws \Magento\Framework\Exception\NoSuchEntityException
136+
* @throws \Magento\Framework\Exception\LocalizedException
137+
*/
138+
private function validateBeforeSave(\Magento\Eav\Api\Data\AttributeSetInterface $attributeSet)
139+
{
140+
$productEntityId = $this->eavConfig->getEntityType(\Magento\Catalog\Model\Product::ENTITY)->getId();
141+
$result = $attributeSet->getEntityTypeId() === $productEntityId;
142+
if (!$result && $attributeSet->getAttributeSetId()) {
143+
$existingAttributeSet = $this->attributeSetRepository->get($attributeSet->getAttributeSetId());
144+
$attributeSet->setEntityTypeId($existingAttributeSet->getEntityTypeId());
145+
$result = $existingAttributeSet->getEntityTypeId() === $productEntityId;
146+
}
147+
if (!$result) {
148+
throw new \Magento\Framework\Exception\StateException(
149+
__('Provided Attribute set non product Attribute set.')
150+
);
151+
}
152+
}
130153
}

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
}

0 commit comments

Comments
 (0)