Skip to content

Commit b65b37e

Browse files
committed
ACP2E-1264: Bundle options missed in Graphql response when display out of stock products = Yes
1 parent 528ed74 commit b65b37e

File tree

4 files changed

+44
-54
lines changed

4 files changed

+44
-54
lines changed

app/code/Magento/BundleGraphQl/Model/Resolver/Links/Collection.php

Lines changed: 19 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
use Magento\Framework\Exception\RuntimeException;
1616
use Magento\Framework\GraphQl\Query\EnumLookup;
1717
use Magento\Framework\GraphQl\Query\Uid;
18-
use Magento\Catalog\Api\ProductRepositoryInterface;
1918
use Zend_Db_Select_Exception;
2019

2120
/**
@@ -51,29 +50,20 @@ class Collection
5150
/** @var Uid */
5251
private $uidEncoder;
5352

54-
/**
55-
* @var ProductRepositoryInterface
56-
*/
57-
private $productRepository;
58-
5953
/**
6054
* @param CollectionFactory $linkCollectionFactory
6155
* @param EnumLookup $enumLookup
6256
* @param Uid|null $uidEncoder
63-
* @param ProductRepositoryInterface|null $productRepository
6457
*/
6558
public function __construct(
6659
CollectionFactory $linkCollectionFactory,
6760
EnumLookup $enumLookup,
68-
Uid $uidEncoder = null,
69-
?ProductRepositoryInterface $productRepository = null
61+
Uid $uidEncoder = null
7062
) {
7163
$this->linkCollectionFactory = $linkCollectionFactory;
7264
$this->enumLookup = $enumLookup;
7365
$this->uidEncoder = $uidEncoder ?: ObjectManager::getInstance()
7466
->get(Uid::class);
75-
$this->productRepository = $productRepository ?: ObjectManager::getInstance()
76-
->get(ProductRepositoryInterface::class);
7767
}
7868

7969
/**
@@ -117,7 +107,6 @@ public function getLinksForOptionId(int $optionId) : array
117107
* Fetch link data and return in array format. Keys for links will be their option Ids.
118108
*
119109
* @return array
120-
* @throws NoSuchEntityException
121110
* @throws RuntimeException
122111
* @throws Zend_Db_Select_Exception
123112
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
@@ -143,33 +132,26 @@ private function fetch() : array
143132

144133
/** @var Selection $link */
145134
foreach ($linkCollection as $link) {
146-
$productDetails = [];
147135
$data = $link->getData();
148-
if (isset($data['product_id'])) {
149-
$productDetails = $this->productRepository->getById($data['product_id']);
150-
}
151-
152-
if ($productDetails && $productDetails->getIsSalable()) {
153-
$formattedLink = [
154-
'price' => $link->getSelectionPriceValue(),
155-
'position' => $link->getPosition(),
156-
'id' => $link->getSelectionId(),
157-
'uid' => $this->uidEncoder->encode((string)$link->getSelectionId()),
158-
'qty' => (float)$link->getSelectionQty(),
159-
'quantity' => (float)$link->getSelectionQty(),
160-
'is_default' => (bool)$link->getIsDefault(),
161-
'price_type' => $this->enumLookup->getEnumValueFromField(
162-
'PriceTypeEnum',
163-
(string)$link->getSelectionPriceType()
164-
) ?: 'DYNAMIC',
165-
'can_change_quantity' => $link->getSelectionCanChangeQty(),
166-
];
167-
$data = array_replace($data, $formattedLink);
168-
if (!isset($this->links[$link->getOptionId()])) {
169-
$this->links[$link->getOptionId()] = [];
170-
}
171-
$this->links[$link->getOptionId()][] = $data;
136+
$formattedLink = [
137+
'price' => $link->getSelectionPriceValue(),
138+
'position' => $link->getPosition(),
139+
'id' => $link->getSelectionId(),
140+
'uid' => $this->uidEncoder->encode((string)$link->getSelectionId()),
141+
'qty' => (float)$link->getSelectionQty(),
142+
'quantity' => (float)$link->getSelectionQty(),
143+
'is_default' => (bool)$link->getIsDefault(),
144+
'price_type' => $this->enumLookup->getEnumValueFromField(
145+
'PriceTypeEnum',
146+
(string)$link->getSelectionPriceType()
147+
) ?: 'DYNAMIC',
148+
'can_change_quantity' => $link->getSelectionCanChangeQty(),
149+
];
150+
$data = array_replace($data, $formattedLink);
151+
if (!isset($this->links[$link->getOptionId()])) {
152+
$this->links[$link->getOptionId()] = [];
172153
}
154+
$this->links[$link->getOptionId()][] = $data;
173155
}
174156

175157
return $this->links;
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?xml version="1.0"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
9+
<type name="Magento\Catalog\Model\ResourceModel\Product\Collection">
10+
<plugin name="add_stock_information" type="Magento\CatalogInventory\Model\AddStockStatusToCollection" />
11+
</type>
12+
</config>

app/code/Magento/QuoteGraphQl/Model/Cart/GetCartProducts.php

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77

88
namespace Magento\QuoteGraphQl\Model\Cart;
99

10-
use Magento\Catalog\Api\ProductRepositoryInterface;
11-
use Magento\Framework\Api\SearchCriteriaBuilder;
10+
use Magento\Catalog\Api\Data\ProductInterface;
11+
use Magento\Catalog\Model\ResourceModel\Product\CollectionFactory as ProductCollectionFactory;
1212
use Magento\Quote\Model\Quote;
1313

1414
/**
@@ -17,25 +17,17 @@
1717
class GetCartProducts
1818
{
1919
/**
20-
* @var ProductRepositoryInterface
20+
* @var ProductCollectionFactory
2121
*/
22-
private $productRepository;
22+
private $productCollectionFactory;
2323

2424
/**
25-
* @var SearchCriteriaBuilder
26-
*/
27-
private $searchCriteriaBuilder;
28-
29-
/**
30-
* @param ProductRepositoryInterface $productRepository
31-
* @param SearchCriteriaBuilder $searchCriteriaBuilder
25+
* @param ProductCollectionFactory $productCollectionFactory
3226
*/
3327
public function __construct(
34-
ProductRepositoryInterface $productRepository,
35-
SearchCriteriaBuilder $searchCriteriaBuilder
28+
ProductCollectionFactory $productCollectionFactory
3629
) {
37-
$this->productRepository = $productRepository;
38-
$this->searchCriteriaBuilder = $searchCriteriaBuilder;
30+
$this->productCollectionFactory = $productCollectionFactory;
3931
}
4032

4133
/**
@@ -57,8 +49,11 @@ function ($item) {
5749
$cartItems
5850
);
5951

60-
$searchCriteria = $this->searchCriteriaBuilder->addFilter('entity_id', $cartItemIds, 'in')->create();
61-
$products = $this->productRepository->getList($searchCriteria)->getItems();
52+
$productCollection = $this->productCollectionFactory->create()
53+
->addAttributeToSelect('*')
54+
->addIdFilter($cartItemIds)
55+
->setFlag('has_stock_status_filter', true);
56+
$products = $productCollection->getItems();
6257

6358
return $products;
6459
}

app/code/Magento/Sales/Model/Reorder/Reorder.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,7 @@ private function getOrderProducts(string $storeId, array $orderItemProductIds):
231231
{
232232
/** @var Collection $collection */
233233
$collection = $this->productCollectionFactory->create();
234+
$collection->setFlag('has_stock_status_filter', true);
234235
$collection->setStore($storeId)
235236
->addIdFilter($orderItemProductIds)
236237
->addStoreFilter()

0 commit comments

Comments
 (0)