Skip to content

Commit

Permalink
Merge pull request #1685 from magento-engcom/2.2-develop-prs
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Oleksii Korshenko authored Nov 9, 2017
2 parents 5a47b77 + b1e5801 commit d521c40
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1296,7 +1296,7 @@ private function loadUsedProducts(\Magento\Catalog\Model\Product $product, $cach
if ($salableOnly) {
$collection = $this->salableProcessor->process($collection);
}
$usedProducts = $collection->getItems();
$usedProducts = array_values($collection->getItems());
$this->saveUsedProductsCacheData($product, $usedProducts, $cacheKey);
}
$product->setData($dataFieldName, $usedProducts);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ public function execute()

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

$responseAjax = new \Magento\Framework\DataObject();

try {
$this->shipmentLoader->setOrderId($this->getRequest()->getParam('order_id'));
$this->shipmentLoader->setShipmentId($this->getRequest()->getParam('shipment_id'));
Expand Down Expand Up @@ -143,7 +145,6 @@ public function execute()
$shipment->register();

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

if ($isNeedCreateLabel) {
$this->labelGenerator->create($shipment, $this->_request);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,26 @@ public function testGetUsedProducts()
}
}

/**
* Test getUsedProducts returns array with same indexes regardless collections was cache or not.
*
* @magentoAppIsolation enabled
* @magentoDataFixture Magento/ConfigurableProduct/_files/product_configurable.php
*/
public function testGetUsedProductsCached()
{
/** @var \Magento\Framework\App\Cache\StateInterface $cacheState */
$cacheState = Bootstrap::getObjectManager()->get(\Magento\Framework\App\Cache\StateInterface::class);
$cacheState->setEnabled(\Magento\Framework\App\Cache\Type\Collection::TYPE_IDENTIFIER, true);

$products = $this->getUsedProducts();
$productsCached = $this->getUsedProducts();
self::assertEquals(
array_keys($products),
array_keys($productsCached)
);
}

public function testGetUsedProductCollection()
{
$this->assertInstanceOf(
Expand Down Expand Up @@ -571,4 +591,14 @@ protected function _prepareForCart()

return $product;
}

/**
* @return ProductInterface[]
*/
protected function getUsedProducts()
{
$product = Bootstrap::getObjectManager()->create(Product::class);
$product->load(1);
return $this->model->getUsedProducts($product);
}
}

0 comments on commit d521c40

Please sign in to comment.