Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#34991 GraphQL Bundle Options generates wrong DB request and result: … #34992

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -112,13 +112,15 @@ private function fetch() : array

$productTable = $optionsCollection->getTable('catalog_product_entity');
$linkField = $optionsCollection->getConnection()->getAutoIncrementField($productTable);
$entityIds = array_column($this->skuMap, 'entity_id');

$optionsCollection->getSelect()->join(
['cpe' => $productTable],
'cpe.' . $linkField . ' = main_table.parent_id',
[]
)->where(
"cpe.entity_id IN (?)",
$this->skuMap
$entityIds
);
$optionsCollection->setPositionOrder();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -502,4 +502,56 @@ public function testBundleProductWithDisabledProductOption()
$response = $this->graphQlQuery($query);
$this->assertEmpty($response['products']['items']);
}

/**
* @magentoApiDataFixture Magento/Bundle/_files/bundle_product_with_sku_as_next_entity_id.php
*/
public function testBundleProductHavingSKUAsNextBundleProductId()
{

$productSku = '4bundle-product';
$query
= <<<QUERY
{
products(filter: {sku: {eq: "{$productSku}"}})
{
items{
id
type_id
name
sku
... on BundleProduct {
items {
option_id
title
required
type
position
sku
options {
id
quantity
position
is_default
price
price_type
can_change_quantity
label
product {
id
name
sku
type_id
}
}
}
}
}
}
}
QUERY;

$response = $this->graphQlQuery($query);
$this->assertNotEmpty($response['products']['items']);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

use Magento\TestFramework\Workaround\Override\Fixture\Resolver;

/*
* Since the bundle product creation GUI doesn't allow to choose values for bundled products' custom options,
* bundled items should not contain products with required custom options.
* However, if to create such a bundle product, it will be always out of stock.
*/
Resolver::getInstance()->requireDataFixture('Magento/Catalog/_files/products.php');

/** @var $objectManager \Magento\TestFramework\ObjectManager */
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
/** @var \Magento\Catalog\Api\ProductRepositoryInterface $productRepository */
$productRepository = $objectManager->create(\Magento\Catalog\Api\ProductRepositoryInterface::class);
$sampleProduct = $productRepository->get('simple');

/** @var $product \Magento\Catalog\Model\Product */
$bundleProduct = $objectManager->create(\Magento\Catalog\Model\Product::class);
$bundleProduct->setTypeId('bundle')
->setId(3)
->setAttributeSetId(4)
->setWeight(2)
->setWebsiteIds([1])
->setName('Bundle Product')
->setSku('4bundle-product')
->setVisibility(\Magento\Catalog\Model\Product\Visibility::VISIBILITY_BOTH)
->setStatus(\Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED)
->setStockData(['use_config_manage_stock' => 1, 'qty' => 100, 'is_qty_decimal' => 0, 'is_in_stock' => 1])
->setPriceView(1)
->setSkuType(1)
->setWeightType(1)
->setPriceType(1)
->setShipmentType(0)
->setPrice(10.0)
->setBundleOptionsData(
[
[
'title' => 'Bundle Product Items',
'default_title' => 'Bundle Product Items',
'type' => 'select', 'required' => 1,
'delete' => '',
],
]
)
->setBundleSelectionsData(
[
[
[
'product_id' => $sampleProduct->getId(),
'selection_price_value' => 2.75,
'selection_qty' => 1,
'selection_can_change_qty' => 1,
'delete' => '',

],
],
]
);

/** @var $product \Magento\Catalog\Model\Product */
$bundleProduct2 = $objectManager->create(\Magento\Catalog\Model\Product::class);
$bundleProduct2->setTypeId('bundle')
->setId(4)
->setAttributeSetId(4)
->setWeight(2)
->setWebsiteIds([1])
->setName('Bundle Product 4')
->setSku('5bundle-product')
->setVisibility(\Magento\Catalog\Model\Product\Visibility::VISIBILITY_BOTH)
->setStatus(\Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED)
->setStockData(['use_config_manage_stock' => 1, 'qty' => 100, 'is_qty_decimal' => 0, 'is_in_stock' => 1])
->setPriceView(1)
->setSkuType(1)
->setWeightType(1)
->setPriceType(1)
->setShipmentType(0)
->setPrice(10.0)
->setBundleOptionsData(
[
[
'title' => 'Bundle Product Items',
'default_title' => 'Bundle Product Items',
'type' => 'select', 'required' => 1,
'delete' => '',
],
]
)
->setBundleSelectionsData(
[
[
[
'product_id' => $sampleProduct->getId(),
'selection_price_value' => 2.75,
'selection_qty' => 1,
'selection_can_change_qty' => 1,
'delete' => '',

],
],
]
);

foreach ([$bundleProduct, $bundleProduct2] as $product) {
if ($product->getBundleOptionsData()) {
$options = [];
foreach ($product->getBundleOptionsData() as $key => $optionData) {
if (!(bool)$optionData['delete']) {
$option = $objectManager->create(\Magento\Bundle\Api\Data\OptionInterfaceFactory::class)
->create(['data' => $optionData]);
$option->setSku($product->getSku());
$option->setOptionId(null);

$links = [];
$bundleLinks = $product->getBundleSelectionsData();
if (!empty($bundleLinks[$key])) {
foreach ($bundleLinks[$key] as $linkData) {
if (!(bool)$linkData['delete']) {
/** @var \Magento\Bundle\Api\Data\LinkInterface$link */
$link = $objectManager->create(\Magento\Bundle\Api\Data\LinkInterfaceFactory::class)
->create(['data' => $linkData]);
$linkProduct = $productRepository->getById($linkData['product_id']);
$link->setSku($linkProduct->getSku());
$link->setQty($linkData['selection_qty']);
$link->setPrice($linkData['selection_price_value']);
if (isset($linkData['selection_can_change_qty'])) {
$link->setCanChangeQuantity($linkData['selection_can_change_qty']);
}
$links[] = $link;
}
}
$option->setProductLinks($links);
$options[] = $option;
}
}
}
$extension = $product->getExtensionAttributes();
$extension->setBundleProductOptions($options);
$product->setExtensionAttributes($extension);
}

$productRepository->save($product, true);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

use Magento\TestFramework\Workaround\Override\Fixture\Resolver;

/*
* Since the bundle product creation GUI doesn't allow to choose values for bundled products' custom options,
* bundled items should not contain products with required custom options.
* However, if to create such a bundle product, it will be always out of stock.
*/
Resolver::getInstance()->requireDataFixture('Magento/Catalog/_files/products_rollback.php');

/** @var \Magento\Framework\Registry $registry */
$registry = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(\Magento\Framework\Registry::class);
$registry->unregister('isSecureArea');
$registry->register('isSecureArea', true);

$productRepository = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()
->get(\Magento\Catalog\Api\ProductRepositoryInterface::class);
try {
$product = $productRepository->get('4bundle-product', false, null, true);
$productRepository->delete($product);
$product = $productRepository->get('5bundle-product', false, null, true);
$productRepository->delete($product);
} catch (\Magento\Framework\Exception\NoSuchEntityException $e) {
//Product already removed
}

$registry->unregister('isSecureArea');
$registry->register('isSecureArea', false);