Skip to content

Commit c190e84

Browse files
34991-Added new WebAPI graphql test case for the PR scenario
1 parent 05c5ff0 commit c190e84

File tree

3 files changed

+232
-0
lines changed

3 files changed

+232
-0
lines changed

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

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -485,4 +485,56 @@ public function testBundleProductWithDisabledProductOption()
485485
$response = $this->graphQlQuery($query);
486486
$this->assertEmpty($response['products']['items']);
487487
}
488+
489+
/**
490+
* @magentoApiDataFixture Magento/Bundle/_files/bundle_product_with_sku_as_next_entity_id.php
491+
*/
492+
public function testBundleProductHavingSKUAsNextBundleProductId()
493+
{
494+
495+
$productSku = '4bundle-product';
496+
$query
497+
= <<<QUERY
498+
{
499+
products(filter: {sku: {eq: "{$productSku}"}})
500+
{
501+
items{
502+
id
503+
type_id
504+
name
505+
sku
506+
... on BundleProduct {
507+
items {
508+
option_id
509+
title
510+
required
511+
type
512+
position
513+
sku
514+
options {
515+
id
516+
quantity
517+
position
518+
is_default
519+
price
520+
price_type
521+
can_change_quantity
522+
label
523+
product {
524+
id
525+
name
526+
sku
527+
type_id
528+
}
529+
}
530+
}
531+
}
532+
}
533+
}
534+
}
535+
QUERY;
536+
537+
$response = $this->graphQlQuery($query);
538+
$this->assertNotEmpty($response['products']['items']);
539+
}
488540
}
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)