Skip to content

Commit 2cfcad4

Browse files
committed
Merge remote-tracking branch 'origin/MAGETWO-92509' into mpi-PR-1806
2 parents 4fbefd7 + 884acdd commit 2cfcad4

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

app/code/Magento/ConfigurableProductSales/Model/Order/Reorder/OrderedProductAvailabilityChecker.php

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@
55
*/
66
namespace Magento\ConfigurableProductSales\Model\Order\Reorder;
77

8-
use Magento\Sales\Model\Order\Reorder\OrderedProductAvailabilityCheckerInterface;
9-
use Magento\Sales\Model\Order\Item;
108
use Magento\Catalog\Api\Data\ProductInterface;
9+
use Magento\Catalog\Api\ProductRepositoryInterface;
1110
use Magento\Framework\App\ResourceConnection;
1211
use Magento\Framework\EntityManager\MetadataPool;
12+
use Magento\Sales\Model\Order\Item;
13+
use Magento\Sales\Model\Order\Reorder\OrderedProductAvailabilityCheckerInterface;
1314
use Magento\Store\Model\Store;
1415

1516
/**
@@ -27,16 +28,24 @@ class OrderedProductAvailabilityChecker implements OrderedProductAvailabilityChe
2728
*/
2829
private $metadataPool;
2930

31+
/**
32+
* @var ProductRepositoryInterface
33+
*/
34+
private $productRepository;
35+
3036
/**
3137
* @param ResourceConnection $resourceConnection
3238
* @param MetadataPool $metadataPool
39+
* @param ProductRepositoryInterface $productRepository
3340
*/
3441
public function __construct(
3542
ResourceConnection $resourceConnection,
36-
MetadataPool $metadataPool
43+
MetadataPool $metadataPool,
44+
ProductRepositoryInterface $productRepository
3745
) {
3846
$this->resourceConnection = $resourceConnection;
3947
$this->metadataPool = $metadataPool;
48+
$this->productRepository = $productRepository;
4049
}
4150

4251
/**
@@ -48,7 +57,9 @@ public function isAvailable(Item $item)
4857
$superAttribute = $buyRequest->getData()['super_attribute'] ?? [];
4958
$connection = $this->getConnection();
5059
$select = $connection->select();
51-
$orderItemParentId = $item->getParentItem()->getProductId();
60+
$linkField = $this->getMetadata()->getLinkField();
61+
$parentItem = $this->productRepository->getById($item->getParentItem()->getProductId());
62+
$orderItemParentId = $parentItem->getData($linkField);
5263
$select->from(
5364
['cpe' => $this->resourceConnection->getTableName('catalog_product_entity')],
5465
['cpe.entity_id']
@@ -67,7 +78,7 @@ public function isAvailable(Item $item)
6778
['cpid' . $attributeId => $this->resourceConnection->getTableName('catalog_product_entity_int')],
6879
sprintf(
6980
'cpe.%1$s = cpid%2$d.%1$s AND cpid%2$d.attribute_id = %2$d AND cpid%2$d.store_id = %3$d',
70-
$this->getMetadata()->getLinkField(),
81+
$linkField,
7182
$attributeId,
7283
Store::DEFAULT_STORE_ID
7384
),
@@ -77,7 +88,7 @@ public function isAvailable(Item $item)
7788
['cpis' . $attributeId => $this->resourceConnection->getTableName('catalog_product_entity_int')],
7889
sprintf(
7990
'cpe.%1$s = cpis%2$d.%1$s AND cpis%2$d.attribute_id = %2$d AND cpis%2$d.store_id = %3$d',
80-
$this->getMetadata()->getLinkField(),
91+
$linkField,
8192
$attributeId,
8293
$item->getStoreId()
8394
),

0 commit comments

Comments
 (0)