Skip to content

Commit e1ec129

Browse files
Indrani sonawaneIndrani sonawane
authored andcommitted
Merge remote-tracking branch 'novakivskiy/bugfix/34991' into comm_78764_34992
2 parents fa3d6ec + 279ef41 commit e1ec129

File tree

4 files changed

+235
-1
lines changed

4 files changed

+235
-1
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,13 +112,15 @@ private function fetch() : array
112112

113113
$productTable = $optionsCollection->getTable('catalog_product_entity');
114114
$linkField = $optionsCollection->getConnection()->getAutoIncrementField($productTable);
115+
$entityIds = array_column($this->skuMap, 'entity_id');
116+
115117
$optionsCollection->getSelect()->join(
116118
['cpe' => $productTable],
117119
'cpe.' . $linkField . ' = main_table.parent_id',
118120
[]
119121
)->where(
120122
"cpe.entity_id IN (?)",
121-
$this->skuMap
123+
$entityIds
122124
);
123125
$optionsCollection->setPositionOrder();
124126

dev/tests/api-functional/testsuite/Magento/GraphQl/Bundle/BundleProductViewTest.php

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -502,4 +502,56 @@ public function testBundleProductWithDisabledProductOption()
502502
$response = $this->graphQlQuery($query);
503503
$this->assertEmpty($response['products']['items']);
504504
}
505+
506+
/**
507+
* @magentoApiDataFixture Magento/Bundle/_files/bundle_product_with_sku_as_next_entity_id.php
508+
*/
509+
public function testBundleProductHavingSKUAsNextBundleProductId()
510+
{
511+
512+
$productSku = '4bundle-product';
513+
$query
514+
= <<<QUERY
515+
{
516+
products(filter: {sku: {eq: "{$productSku}"}})
517+
{
518+
items{
519+
id
520+
type_id
521+
name
522+
sku
523+
... on BundleProduct {
524+
items {
525+
option_id
526+
title
527+
required
528+
type
529+
position
530+
sku
531+
options {
532+
id
533+
quantity
534+
position
535+
is_default
536+
price
537+
price_type
538+
can_change_quantity
539+
label
540+
product {
541+
id
542+
name
543+
sku
544+
type_id
545+
}
546+
}
547+
}
548+
}
549+
}
550+
}
551+
}
552+
QUERY;
553+
554+
$response = $this->graphQlQuery($query);
555+
$this->assertNotEmpty($response['products']['items']);
556+
}
505557
}
Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
8+
9+
/*
10+
* Since the bundle product creation GUI doesn't allow to choose values for bundled products' custom options,
11+
* bundled items should not contain products with required custom options.
12+
* However, if to create such a bundle product, it will be always out of stock.
13+
*/
14+
Resolver::getInstance()->requireDataFixture('Magento/Catalog/_files/products.php');
15+
16+
/** @var $objectManager \Magento\TestFramework\ObjectManager */
17+
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
18+
/** @var \Magento\Catalog\Api\ProductRepositoryInterface $productRepository */
19+
$productRepository = $objectManager->create(\Magento\Catalog\Api\ProductRepositoryInterface::class);
20+
$sampleProduct = $productRepository->get('simple');
21+
22+
/** @var $product \Magento\Catalog\Model\Product */
23+
$bundleProduct = $objectManager->create(\Magento\Catalog\Model\Product::class);
24+
$bundleProduct->setTypeId('bundle')
25+
->setId(3)
26+
->setAttributeSetId(4)
27+
->setWeight(2)
28+
->setWebsiteIds([1])
29+
->setName('Bundle Product')
30+
->setSku('4bundle-product')
31+
->setVisibility(\Magento\Catalog\Model\Product\Visibility::VISIBILITY_BOTH)
32+
->setStatus(\Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED)
33+
->setStockData(['use_config_manage_stock' => 1, 'qty' => 100, 'is_qty_decimal' => 0, 'is_in_stock' => 1])
34+
->setPriceView(1)
35+
->setSkuType(1)
36+
->setWeightType(1)
37+
->setPriceType(1)
38+
->setShipmentType(0)
39+
->setPrice(10.0)
40+
->setBundleOptionsData(
41+
[
42+
[
43+
'title' => 'Bundle Product Items',
44+
'default_title' => 'Bundle Product Items',
45+
'type' => 'select', 'required' => 1,
46+
'delete' => '',
47+
],
48+
]
49+
)
50+
->setBundleSelectionsData(
51+
[
52+
[
53+
[
54+
'product_id' => $sampleProduct->getId(),
55+
'selection_price_value' => 2.75,
56+
'selection_qty' => 1,
57+
'selection_can_change_qty' => 1,
58+
'delete' => '',
59+
60+
],
61+
],
62+
]
63+
);
64+
65+
/** @var $product \Magento\Catalog\Model\Product */
66+
$bundleProduct2 = $objectManager->create(\Magento\Catalog\Model\Product::class);
67+
$bundleProduct2->setTypeId('bundle')
68+
->setId(4)
69+
->setAttributeSetId(4)
70+
->setWeight(2)
71+
->setWebsiteIds([1])
72+
->setName('Bundle Product 4')
73+
->setSku('5bundle-product')
74+
->setVisibility(\Magento\Catalog\Model\Product\Visibility::VISIBILITY_BOTH)
75+
->setStatus(\Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED)
76+
->setStockData(['use_config_manage_stock' => 1, 'qty' => 100, 'is_qty_decimal' => 0, 'is_in_stock' => 1])
77+
->setPriceView(1)
78+
->setSkuType(1)
79+
->setWeightType(1)
80+
->setPriceType(1)
81+
->setShipmentType(0)
82+
->setPrice(10.0)
83+
->setBundleOptionsData(
84+
[
85+
[
86+
'title' => 'Bundle Product Items',
87+
'default_title' => 'Bundle Product Items',
88+
'type' => 'select', 'required' => 1,
89+
'delete' => '',
90+
],
91+
]
92+
)
93+
->setBundleSelectionsData(
94+
[
95+
[
96+
[
97+
'product_id' => $sampleProduct->getId(),
98+
'selection_price_value' => 2.75,
99+
'selection_qty' => 1,
100+
'selection_can_change_qty' => 1,
101+
'delete' => '',
102+
103+
],
104+
],
105+
]
106+
);
107+
108+
foreach ([$bundleProduct, $bundleProduct2] as $product) {
109+
if ($product->getBundleOptionsData()) {
110+
$options = [];
111+
foreach ($product->getBundleOptionsData() as $key => $optionData) {
112+
if (!(bool)$optionData['delete']) {
113+
$option = $objectManager->create(\Magento\Bundle\Api\Data\OptionInterfaceFactory::class)
114+
->create(['data' => $optionData]);
115+
$option->setSku($product->getSku());
116+
$option->setOptionId(null);
117+
118+
$links = [];
119+
$bundleLinks = $product->getBundleSelectionsData();
120+
if (!empty($bundleLinks[$key])) {
121+
foreach ($bundleLinks[$key] as $linkData) {
122+
if (!(bool)$linkData['delete']) {
123+
/** @var \Magento\Bundle\Api\Data\LinkInterface$link */
124+
$link = $objectManager->create(\Magento\Bundle\Api\Data\LinkInterfaceFactory::class)
125+
->create(['data' => $linkData]);
126+
$linkProduct = $productRepository->getById($linkData['product_id']);
127+
$link->setSku($linkProduct->getSku());
128+
$link->setQty($linkData['selection_qty']);
129+
$link->setPrice($linkData['selection_price_value']);
130+
if (isset($linkData['selection_can_change_qty'])) {
131+
$link->setCanChangeQuantity($linkData['selection_can_change_qty']);
132+
}
133+
$links[] = $link;
134+
}
135+
}
136+
$option->setProductLinks($links);
137+
$options[] = $option;
138+
}
139+
}
140+
}
141+
$extension = $product->getExtensionAttributes();
142+
$extension->setBundleProductOptions($options);
143+
$product->setExtensionAttributes($extension);
144+
}
145+
146+
$productRepository->save($product, true);
147+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
8+
9+
/*
10+
* Since the bundle product creation GUI doesn't allow to choose values for bundled products' custom options,
11+
* bundled items should not contain products with required custom options.
12+
* However, if to create such a bundle product, it will be always out of stock.
13+
*/
14+
Resolver::getInstance()->requireDataFixture('Magento/Catalog/_files/products_rollback.php');
15+
16+
/** @var \Magento\Framework\Registry $registry */
17+
$registry = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(\Magento\Framework\Registry::class);
18+
$registry->unregister('isSecureArea');
19+
$registry->register('isSecureArea', true);
20+
21+
$productRepository = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()
22+
->get(\Magento\Catalog\Api\ProductRepositoryInterface::class);
23+
try {
24+
$product = $productRepository->get('4bundle-product', false, null, true);
25+
$productRepository->delete($product);
26+
$product = $productRepository->get('5bundle-product', false, null, true);
27+
$productRepository->delete($product);
28+
} catch (\Magento\Framework\Exception\NoSuchEntityException $e) {
29+
//Product already removed
30+
}
31+
32+
$registry->unregister('isSecureArea');
33+
$registry->register('isSecureArea', false);

0 commit comments

Comments
 (0)