Skip to content

Commit d521c40

Browse files
author
Oleksii Korshenko
authored
Merge pull request #1685 from magento-engcom/2.2-develop-prs
Public Pull Requests #12107 #11880: Configurable::getUsedProducts returns a different array after product collections is cached by @p-bystritsky #12091 Fix "Undefined variable: responseAjax" notice when trying to save a shipment package by @lazyguru Fixed Public Issues #11880 Magento 2.1.9 Configurable::getUsedProducts returns a different array after product collections is cached
2 parents 5a47b77 + b1e5801 commit d521c40

File tree

3 files changed

+33
-2
lines changed
  • app/code/Magento
  • dev/tests/integration/testsuite/Magento/ConfigurableProduct/Model/Product/Type

3 files changed

+33
-2
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);

app/code/Magento/Shipping/Controller/Adminhtml/Order/Shipment/Save.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,8 @@ public function execute()
109109

110110
$isNeedCreateLabel = isset($data['create_shipping_label']) && $data['create_shipping_label'];
111111

112+
$responseAjax = new \Magento\Framework\DataObject();
113+
112114
try {
113115
$this->shipmentLoader->setOrderId($this->getRequest()->getParam('order_id'));
114116
$this->shipmentLoader->setShipmentId($this->getRequest()->getParam('shipment_id'));
@@ -143,7 +145,6 @@ public function execute()
143145
$shipment->register();
144146

145147
$shipment->getOrder()->setCustomerNoteNotify(!empty($data['send_email']));
146-
$responseAjax = new \Magento\Framework\DataObject();
147148

148149
if ($isNeedCreateLabel) {
149150
$this->labelGenerator->create($shipment, $this->_request);

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
@@ -237,6 +237,26 @@ public function testGetUsedProducts()
237237
}
238238
}
239239

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

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

0 commit comments

Comments
 (0)