Skip to content

Commit 0f83ee1

Browse files
Merge branch 2.2-develop into ENGCOM-4187-magento-magento2-20845
2 parents eb8deb1 + 199eff2 commit 0f83ee1

File tree

63 files changed

+617
-121
lines changed

Some content is hidden

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

63 files changed

+617
-121
lines changed

app/code/Magento/Catalog/Model/Category/Attribute/Source/Layout.php

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@ class Layout extends \Magento\Eav\Model\Entity\Attribute\Source\AbstractSource
1717
*/
1818
protected $pageLayoutBuilder;
1919

20+
/**
21+
* @inheritdoc
22+
* @deprecated since the cache is now handled by \Magento\Theme\Model\PageLayout\Config\Builder::$configFiles
23+
*/
24+
protected $_options = null;
25+
2026
/**
2127
* @param \Magento\Framework\View\Model\PageLayout\Config\BuilderInterface $pageLayoutBuilder
2228
*/
@@ -26,14 +32,14 @@ public function __construct(\Magento\Framework\View\Model\PageLayout\Config\Buil
2632
}
2733

2834
/**
29-
* {@inheritdoc}
35+
* @inheritdoc
3036
*/
3137
public function getAllOptions()
3238
{
33-
if (!$this->_options) {
34-
$this->_options = $this->pageLayoutBuilder->getPageLayoutsConfig()->toOptionArray();
35-
array_unshift($this->_options, ['value' => '', 'label' => __('No layout updates')]);
36-
}
37-
return $this->_options;
39+
$options = $this->pageLayoutBuilder->getPageLayoutsConfig()->toOptionArray();
40+
array_unshift($options, ['value' => '', 'label' => __('No layout updates')]);
41+
$this->_options = $options;
42+
43+
return $options;
3844
}
3945
}

app/code/Magento/Catalog/Model/Product/Attribute/Source/Layout.php

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@ class Layout extends \Magento\Eav\Model\Entity\Attribute\Source\AbstractSource
1717
*/
1818
protected $pageLayoutBuilder;
1919

20+
/**
21+
* @inheritdoc
22+
* @deprecated since the cache is now handled by \Magento\Theme\Model\PageLayout\Config\Builder::$configFiles
23+
*/
24+
protected $_options = null;
25+
2026
/**
2127
* @param \Magento\Framework\View\Model\PageLayout\Config\BuilderInterface $pageLayoutBuilder
2228
*/
@@ -26,14 +32,14 @@ public function __construct(\Magento\Framework\View\Model\PageLayout\Config\Buil
2632
}
2733

2834
/**
29-
* @return array
35+
* @inheritdoc
3036
*/
3137
public function getAllOptions()
3238
{
33-
if (!$this->_options) {
34-
$this->_options = $this->pageLayoutBuilder->getPageLayoutsConfig()->toOptionArray();
35-
array_unshift($this->_options, ['value' => '', 'label' => __('No layout updates')]);
36-
}
37-
return $this->_options;
39+
$options = $this->pageLayoutBuilder->getPageLayoutsConfig()->toOptionArray();
40+
array_unshift($options, ['value' => '', 'label' => __('No layout updates')]);
41+
$this->_options = $options;
42+
43+
return $options;
3844
}
3945
}

app/code/Magento/Catalog/Test/Mftf/Test/StorefrontPurchaseProductCustomOptionsDifferentStoreViewsTest.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
<severity value="CRITICAL"/>
1717
<testCaseId value="MAGETWO-77831"/>
1818
<group value="product"/>
19+
<skip>
20+
<issueId value="MAGETWO-98182"/>
21+
</skip>
1922
</annotations>
2023

2124
<before>

app/code/Magento/CatalogInventory/Model/StockManagement.php

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ public function __construct(
8383

8484
/**
8585
* Subtract product qtys from stock.
86+
*
8687
* Return array of items that require full save.
8788
*
8889
* @param string[] $items
@@ -139,17 +140,25 @@ public function registerProductsSale($items, $websiteId = null)
139140
}
140141

141142
/**
142-
* @param string[] $items
143-
* @param int $websiteId
144-
* @return bool
143+
* @inheritdoc
145144
*/
146145
public function revertProductsSale($items, $websiteId = null)
147146
{
148147
//if (!$websiteId) {
149148
$websiteId = $this->stockConfiguration->getDefaultScopeId();
150149
//}
151-
$this->qtyCounter->correctItemsQty($items, $websiteId, '+');
152-
return true;
150+
$revertItems = [];
151+
foreach ($items as $productId => $qty) {
152+
$stockItem = $this->stockRegistryProvider->getStockItem($productId, $websiteId);
153+
$canSubtractQty = $stockItem->getItemId() && $this->canSubtractQty($stockItem);
154+
if (!$canSubtractQty || !$this->stockConfiguration->isQty($stockItem->getTypeId())) {
155+
continue;
156+
}
157+
$revertItems[$productId] = $qty;
158+
}
159+
$this->qtyCounter->correctItemsQty($revertItems, $websiteId, '+');
160+
161+
return $revertItems;
153162
}
154163

155164
/**
@@ -193,6 +202,8 @@ protected function getProductType($productId)
193202
}
194203

195204
/**
205+
* Get stock resource.
206+
*
196207
* @return ResourceStock
197208
*/
198209
protected function getResource()

app/code/Magento/CatalogInventory/Observer/RevertQuoteInventoryObserver.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ public function execute(EventObserver $observer)
6464
{
6565
$quote = $observer->getEvent()->getQuote();
6666
$items = $this->productQty->getProductQty($quote->getAllItems());
67-
$this->stockManagement->revertProductsSale($items, $quote->getStore()->getWebsiteId());
68-
$productIds = array_keys($items);
67+
$revertedItems = $this->stockManagement->revertProductsSale($items, $quote->getStore()->getWebsiteId());
68+
$productIds = array_keys($revertedItems);
6969
if (!empty($productIds)) {
7070
$this->stockIndexerProcessor->reindexList($productIds);
7171
$this->priceIndexer->reindexList($productIds);

app/code/Magento/Cms/Model/Page/Source/PageLayout.php

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ class PageLayout implements OptionSourceInterface
2020

2121
/**
2222
* @var array
23+
* @deprecated since the cache is now handled by \Magento\Theme\Model\PageLayout\Config\Builder::$configFiles
2324
*/
2425
protected $options;
2526

@@ -34,16 +35,10 @@ public function __construct(BuilderInterface $pageLayoutBuilder)
3435
}
3536

3637
/**
37-
* Get options
38-
*
39-
* @return array
38+
* @inheritdoc
4039
*/
4140
public function toOptionArray()
4241
{
43-
if ($this->options !== null) {
44-
return $this->options;
45-
}
46-
4742
$configOptions = $this->pageLayoutBuilder->getPageLayoutsConfig()->getOptions();
4843
$options = [];
4944
foreach ($configOptions as $key => $value) {
@@ -54,6 +49,6 @@ public function toOptionArray()
5449
}
5550
$this->options = $options;
5651

57-
return $this->options;
52+
return $options;
5853
}
5954
}

app/code/Magento/Cms/view/adminhtml/templates/browser/content/files.phtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ $_height = $block->getImagesHeight();
1515
<?php if ($block->getFilesCount() > 0): ?>
1616
<?php foreach ($block->getFiles() as $file): ?>
1717
<div data-row="file" class="filecnt" id="<?= $block->escapeHtmlAttr($block->getFileId($file)) ?>">
18-
<p class="nm" style="height:<?= $block->escapeHtmlAttr($_height) ?>px;width:<?= $block->escapeHtmlAttr($_width) ?>px;">
18+
<p class="nm" style="height:<?= $block->escapeHtmlAttr($_height) ?>px;">
1919
<?php if ($block->getFileThumbUrl($file)):?>
2020
<img src="<?= $block->escapeHtmlAttr($block->getFileThumbUrl($file)) ?>" alt="<?= $block->escapeHtmlAttr($block->getFileName($file)) ?>"/>
2121
<?php endif; ?>

app/code/Magento/Customer/Model/Metadata/AttributeMetadataCache.php

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use Magento\Framework\App\Cache\StateInterface;
1313
use Magento\Framework\App\CacheInterface;
1414
use Magento\Framework\Serialize\SerializerInterface;
15+
use Magento\Store\Model\StoreManagerInterface;
1516

1617
/**
1718
* Cache for attribute metadata
@@ -53,24 +54,33 @@ class AttributeMetadataCache
5354
*/
5455
private $serializer;
5556

57+
/**
58+
* @var StoreManagerInterface
59+
*/
60+
private $storeManager;
61+
5662
/**
5763
* Constructor
5864
*
5965
* @param CacheInterface $cache
6066
* @param StateInterface $state
6167
* @param SerializerInterface $serializer
6268
* @param AttributeMetadataHydrator $attributeMetadataHydrator
69+
* @param StoreManagerInterface|null $storeManager
6370
*/
6471
public function __construct(
6572
CacheInterface $cache,
6673
StateInterface $state,
6774
SerializerInterface $serializer,
68-
AttributeMetadataHydrator $attributeMetadataHydrator
75+
AttributeMetadataHydrator $attributeMetadataHydrator,
76+
StoreManagerInterface $storeManager = null
6977
) {
7078
$this->cache = $cache;
7179
$this->state = $state;
7280
$this->serializer = $serializer;
7381
$this->attributeMetadataHydrator = $attributeMetadataHydrator;
82+
$this->storeManager = $storeManager ?: \Magento\Framework\App\ObjectManager::getInstance()
83+
->get(StoreManagerInterface::class);
7484
}
7585

7686
/**
@@ -82,19 +92,20 @@ public function __construct(
8292
*/
8393
public function load($entityType, $suffix = '')
8494
{
85-
if (isset($this->attributes[$entityType . $suffix])) {
86-
return $this->attributes[$entityType . $suffix];
95+
$storeId = $this->storeManager->getStore()->getId();
96+
if (isset($this->attributes[$entityType . $suffix . $storeId])) {
97+
return $this->attributes[$entityType . $suffix . $storeId];
8798
}
8899
if ($this->isEnabled()) {
89-
$cacheKey = self::ATTRIBUTE_METADATA_CACHE_PREFIX . $entityType . $suffix;
100+
$cacheKey = self::ATTRIBUTE_METADATA_CACHE_PREFIX . $entityType . $suffix . $storeId;
90101
$serializedData = $this->cache->load($cacheKey);
91102
if ($serializedData) {
92103
$attributesData = $this->serializer->unserialize($serializedData);
93104
$attributes = [];
94105
foreach ($attributesData as $key => $attributeData) {
95106
$attributes[$key] = $this->attributeMetadataHydrator->hydrate($attributeData);
96107
}
97-
$this->attributes[$entityType . $suffix] = $attributes;
108+
$this->attributes[$entityType . $suffix . $storeId] = $attributes;
98109
return $attributes;
99110
}
100111
}
@@ -111,9 +122,10 @@ public function load($entityType, $suffix = '')
111122
*/
112123
public function save($entityType, array $attributes, $suffix = '')
113124
{
114-
$this->attributes[$entityType . $suffix] = $attributes;
125+
$storeId = $this->storeManager->getStore()->getId();
126+
$this->attributes[$entityType . $suffix . $storeId] = $attributes;
115127
if ($this->isEnabled()) {
116-
$cacheKey = self::ATTRIBUTE_METADATA_CACHE_PREFIX . $entityType . $suffix;
128+
$cacheKey = self::ATTRIBUTE_METADATA_CACHE_PREFIX . $entityType . $suffix . $storeId;
117129
$attributesData = [];
118130
foreach ($attributes as $key => $attribute) {
119131
$attributesData[$key] = $this->attributeMetadataHydrator->extract($attribute);

app/code/Magento/Customer/Test/Unit/Model/Metadata/AttributeMetadataCacheTest.php

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,14 @@
1515
use Magento\Framework\App\CacheInterface;
1616
use Magento\Framework\Serialize\SerializerInterface;
1717
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
18+
use Magento\Store\Api\Data\StoreInterface;
19+
use Magento\Store\Model\StoreManagerInterface;
1820

21+
/**
22+
* Class AttributeMetadataCache Test
23+
*
24+
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
25+
*/
1926
class AttributeMetadataCacheTest extends \PHPUnit\Framework\TestCase
2027
{
2128
/**
@@ -43,20 +50,35 @@ class AttributeMetadataCacheTest extends \PHPUnit\Framework\TestCase
4350
*/
4451
private $attributeMetadataCache;
4552

53+
/**
54+
* @var StoreInterface|\PHPUnit_Framework_MockObject_MockObject
55+
*/
56+
private $storeMock;
57+
58+
/**
59+
* @var StoreManagerInterface|\PHPUnit_Framework_MockObject_MockObject
60+
*/
61+
private $storeManagerMock;
62+
4663
protected function setUp()
4764
{
4865
$objectManager = new ObjectManager($this);
4966
$this->cacheMock = $this->createMock(CacheInterface::class);
5067
$this->stateMock = $this->createMock(StateInterface::class);
5168
$this->serializerMock = $this->createMock(SerializerInterface::class);
5269
$this->attributeMetadataHydratorMock = $this->createMock(AttributeMetadataHydrator::class);
70+
$this->storeMock = $this->createMock(StoreInterface::class);
71+
$this->storeManagerMock = $this->createMock(StoreManagerInterface::class);
72+
$this->storeManagerMock->method('getStore')->willReturn($this->storeMock);
73+
$this->storeMock->method('getId')->willReturn(1);
5374
$this->attributeMetadataCache = $objectManager->getObject(
5475
AttributeMetadataCache::class,
5576
[
5677
'cache' => $this->cacheMock,
5778
'state' => $this->stateMock,
5879
'serializer' => $this->serializerMock,
59-
'attributeMetadataHydrator' => $this->attributeMetadataHydratorMock
80+
'attributeMetadataHydrator' => $this->attributeMetadataHydratorMock,
81+
'storeManager' => $this->storeManagerMock
6082
]
6183
);
6284
}
@@ -80,7 +102,8 @@ public function testLoadNoCache()
80102
{
81103
$entityType = 'EntityType';
82104
$suffix = 'none';
83-
$cacheKey = AttributeMetadataCache::ATTRIBUTE_METADATA_CACHE_PREFIX . $entityType . $suffix;
105+
$storeId = 1;
106+
$cacheKey = AttributeMetadataCache::ATTRIBUTE_METADATA_CACHE_PREFIX . $entityType . $suffix . $storeId;
84107
$this->stateMock->expects($this->once())
85108
->method('isEnabled')
86109
->with(Type::TYPE_IDENTIFIER)
@@ -96,7 +119,8 @@ public function testLoad()
96119
{
97120
$entityType = 'EntityType';
98121
$suffix = 'none';
99-
$cacheKey = AttributeMetadataCache::ATTRIBUTE_METADATA_CACHE_PREFIX . $entityType . $suffix;
122+
$storeId = 1;
123+
$cacheKey = AttributeMetadataCache::ATTRIBUTE_METADATA_CACHE_PREFIX . $entityType . $suffix . $storeId;
100124
$serializedString = 'serialized string';
101125
$attributeMetadataOneData = [
102126
'attribute_code' => 'attribute_code',
@@ -156,7 +180,8 @@ public function testSave()
156180
{
157181
$entityType = 'EntityType';
158182
$suffix = 'none';
159-
$cacheKey = AttributeMetadataCache::ATTRIBUTE_METADATA_CACHE_PREFIX . $entityType . $suffix;
183+
$storeId = 1;
184+
$cacheKey = AttributeMetadataCache::ATTRIBUTE_METADATA_CACHE_PREFIX . $entityType . $suffix . $storeId;
160185
$serializedString = 'serialized string';
161186
$attributeMetadataOneData = [
162187
'attribute_code' => 'attribute_code',

app/code/Magento/Multishipping/Model/Checkout/Type/Multishipping.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1168,7 +1168,7 @@ private function removePlacedItemsFromQuote(array $shippingAddresses, array $pla
11681168
{
11691169
foreach ($shippingAddresses as $address) {
11701170
foreach ($address->getAllItems() as $addressItem) {
1171-
if (in_array($addressItem->getId(), $placedAddressItems)) {
1171+
if (in_array($addressItem->getQuoteItemId(), $placedAddressItems)) {
11721172
if ($addressItem->getProduct()->getIsVirtual()) {
11731173
$addressItem->isDeleted(true);
11741174
} else {
@@ -1218,7 +1218,7 @@ private function searchQuoteAddressId(OrderInterface $order, array $addresses):
12181218
$item = array_pop($items);
12191219
foreach ($addresses as $address) {
12201220
foreach ($address->getAllItems() as $addressItem) {
1221-
if ($addressItem->getId() == $item->getQuoteItemId()) {
1221+
if ($addressItem->getQuoteItemId() == $item->getQuoteItemId()) {
12221222
return (int)$address->getId();
12231223
}
12241224
}

0 commit comments

Comments
 (0)