Skip to content

Commit e2f69da

Browse files
committed
Merge branch 'ACP2E-1264' of https://github.com/magento-l3/magento2ce into PR-01-10-2023
2 parents c130c2d + 6d2aa01 commit e2f69da

File tree

5 files changed

+126
-54
lines changed

5 files changed

+126
-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()
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\GraphQl\Bundle;
9+
10+
use Magento\Bundle\Test\Fixture\Link as BundleSelectionFixture;
11+
use Magento\Bundle\Test\Fixture\Option as BundleOptionFixture;
12+
use Magento\Bundle\Test\Fixture\Product as BundleProductFixture;
13+
use Magento\Catalog\Test\Fixture\Category as CategoryFixture;
14+
use Magento\Catalog\Test\Fixture\Product as ProductFixture;
15+
use Magento\CatalogInventory\Model\Configuration as CatalogInventoryConfiguration;
16+
use Magento\TestFramework\Fixture\Config as ConfigFixture;
17+
use Magento\TestFramework\Fixture\DataFixture;
18+
use Magento\TestFramework\TestCase\GraphQlAbstract;
19+
20+
class CategoryListTest extends GraphQlAbstract
21+
{
22+
#[
23+
ConfigFixture(CatalogInventoryConfiguration::XML_PATH_SHOW_OUT_OF_STOCK, '1', 'store', 'default'),
24+
DataFixture(CategoryFixture::class, ['url_path' => 'cat1'], 'cat1'),
25+
DataFixture(ProductFixture::class, ['sku' => 's1', 'stock_item' => ['is_in_stock' => false]], 's1'),
26+
DataFixture(ProductFixture::class, ['sku' => 's2'], 's2'),
27+
DataFixture(BundleSelectionFixture::class, ['sku' => '$s1.sku$', 'price' => 10, 'price_type' => 0], 'link1'),
28+
DataFixture(BundleSelectionFixture::class, ['sku' => '$s2.sku$', 'price' => 20, 'price_type' => 0], 'link2'),
29+
DataFixture(BundleOptionFixture::class, ['product_links' => ['$link1$', '$link2$']], 'opt1'),
30+
DataFixture(
31+
BundleProductFixture::class,
32+
['sku' => 'bundle1', 'category_ids' => ['$cat1.id$'], '_options' => ['$opt1$']],
33+
'bundle1'
34+
),
35+
]
36+
public function testOutOfStockBundleSelectionWithEnabledShowOutOfStock(): void
37+
{
38+
$query = $this->getQuery('cat1');
39+
$response = $this->graphQlQuery($query);
40+
self::assertNotEmpty($response['categoryList']);
41+
$categoryList = $response['categoryList'][0];
42+
self::assertNotEmpty($categoryList['products']['items']);
43+
$bundle = $categoryList['products']['items'][0];
44+
self::assertEquals('bundle1', $bundle['sku']);
45+
self::assertCount(2, $bundle['items'][0]['options']);
46+
self::assertEquals('s1', $bundle['items'][0]['options'][0]['product']['sku']);
47+
self::assertEquals('s2', $bundle['items'][0]['options'][1]['product']['sku']);
48+
}
49+
50+
/**
51+
* @param string $urlPath
52+
* @return string
53+
*/
54+
private function getQuery(string $urlPath): string
55+
{
56+
$query = <<<QUERY
57+
{
58+
categoryList(filters: {url_path: {eq: "$urlPath"}}) {
59+
id
60+
name
61+
products {
62+
total_count
63+
items {
64+
sku
65+
... on BundleProduct {
66+
items {
67+
options {
68+
product {
69+
sku
70+
}
71+
}
72+
}
73+
}
74+
}
75+
}
76+
}
77+
}
78+
QUERY;
79+
80+
return $query;
81+
}
82+
}

0 commit comments

Comments
 (0)