Skip to content

Commit 850e38c

Browse files
⏫ Forwardport of #12107 to 2.3-develop branch
Applied pull request patch https://github.com/magento/magento2/pull/12107.patch (created by @p-bystritsky) based on commit(s): 1. ca071c0 Fixed GitHub Issues in 2.3-develop branch: - #11880: Magento 2.1.9 Configurable::getUsedProducts returns a different array after product collections is cached (reported by @apedicdev)
1 parent 8e77e2f commit 850e38c

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

app/code/Magento/ConfigurableProduct/Model/Product/Type/Configurable.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1296,7 +1296,7 @@ private function loadUsedProducts(\Magento\Catalog\Model\Product $product, $cach
12961296
if ($salableOnly) {
12971297
$collection = $this->salableProcessor->process($collection);
12981298
}
1299-
$usedProducts = $collection->getItems();
1299+
$usedProducts = array_values($collection->getItems());
13001300
$this->saveUsedProductsCacheData($product, $usedProducts, $cacheKey);
13011301
}
13021302
$product->setData($dataFieldName, $usedProducts);

dev/tests/integration/testsuite/Magento/ConfigurableProduct/Model/Product/Type/ConfigurableTest.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,26 @@ public function testGetUsedProducts()
235235
}
236236
}
237237

238+
/**
239+
* Test getUsedProducts returns array with same indexes regardless collections was cache or not.
240+
*
241+
* @magentoAppIsolation enabled
242+
* @magentoDataFixture Magento/ConfigurableProduct/_files/product_configurable.php
243+
*/
244+
public function testGetUsedProductsCached()
245+
{
246+
/** @var \Magento\Framework\App\Cache\StateInterface $cacheState */
247+
$cacheState = Bootstrap::getObjectManager()->get(\Magento\Framework\App\Cache\StateInterface::class);
248+
$cacheState->setEnabled(\Magento\Framework\App\Cache\Type\Collection::TYPE_IDENTIFIER, true);
249+
250+
$products = $this->getUsedProducts();
251+
$productsCached = $this->getUsedProducts();
252+
self::assertEquals(
253+
array_keys($products),
254+
array_keys($productsCached)
255+
);
256+
}
257+
238258
public function testGetUsedProductCollection()
239259
{
240260
$this->assertInstanceOf(
@@ -570,4 +590,14 @@ protected function _prepareForCart()
570590

571591
return $product;
572592
}
593+
594+
/**
595+
* @return ProductInterface[]
596+
*/
597+
protected function getUsedProducts()
598+
{
599+
$product = Bootstrap::getObjectManager()->create(Product::class);
600+
$product->load(1);
601+
return $this->model->getUsedProducts($product);
602+
}
573603
}

0 commit comments

Comments
 (0)