Skip to content

Commit 31a7fe0

Browse files
committed
Merge pull request #268 from magento-firedrakes/MAGETWO-47215
[Firedrakes] Fix L2 MAGETWO-47215
2 parents e65e0a1 + 11bd2b2 commit 31a7fe0

File tree

4 files changed

+80
-17
lines changed

4 files changed

+80
-17
lines changed

app/code/Magento/Catalog/Model/Product/Type/AbstractType.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -574,8 +574,12 @@ protected function _prepareOptions(\Magento\Framework\DataObject $buyRequest, $p
574574
{
575575
$transport = new \StdClass();
576576
$transport->options = [];
577+
$options = null;
577578
if ($product->getHasOptions()) {
578-
foreach ($product->getOptions() as $option) {
579+
$options = $product->getOptions();
580+
}
581+
if ($options !== null) {
582+
foreach ($options as $option) {
579583
/* @var $option \Magento\Catalog\Model\Product\Option */
580584
$group = $option->groupFactory($option->getType())
581585
->setOption($option)

dev/tests/integration/testsuite/Magento/CatalogImportExport/_files/product_export_data.php

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88
require dirname(dirname(__DIR__)) . '/Store/_files/second_store.php';
99
require dirname(dirname(__DIR__)) . '/Catalog/_files/products_with_multiselect_attribute.php';
1010

11-
$productModel = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create('Magento\Catalog\Model\Product');
11+
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
12+
13+
$productModel = $objectManager->create('Magento\Catalog\Model\Product');
1214

1315
$customOptions = [
1416
1 => [
@@ -57,4 +59,17 @@
5759
[$product->getId() => ['position' => 1]]
5860
);
5961

60-
$product->setOptions($customOptions)->save();
62+
$options = [];
63+
64+
/** @var \Magento\Catalog\Api\Data\ProductCustomOptionInterfaceFactory $customOptionFactory */
65+
$customOptionFactory = $objectManager->create('Magento\Catalog\Api\Data\ProductCustomOptionInterfaceFactory');
66+
67+
foreach ($customOptions as $option) {
68+
/** @var \Magento\Catalog\Api\Data\ProductCustomOptionInterface $option */
69+
$option = $customOptionFactory->create(['data' => $option]);
70+
$option->setProductSku($productModel->getSku());
71+
72+
$options[] = $option;
73+
}
74+
75+
$productModel->setOptions($options)->save();

dev/tests/integration/testsuite/Magento/Quote/Model/QuoteManagementTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ class QuoteManagementTest extends \PHPUnit_Framework_TestCase
1717
*/
1818
public function testSubmit()
1919
{
20-
$this->markTestSkipped('Skipped because of MAGETWO-47215');
2120
/**
2221
* Preconditions:
2322
* Load quote with Bundle product that has at least to child products

dev/tests/integration/testsuite/Magento/Sales/_files/quote_with_bundle.php

Lines changed: 58 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,10 @@
3333
->setCategoryIds([2])
3434
->setStockData(['use_config_manage_stock' => 1, 'qty' => 100, 'is_qty_decimal' => 0, 'is_in_stock' => 1])
3535
->save();
36-
36+
$productRepository = $objectManager->get(Magento\Catalog\Api\ProductRepositoryInterface::class);
37+
/**
38+
* @var \Magento\Catalog\Model\Product $product
39+
*/
3740
$product = $objectManager->create('Magento\Catalog\Model\Product');
3841
$product
3942
->setTypeId(\Magento\Catalog\Model\Product\Type::TYPE_BUNDLE)
@@ -96,24 +99,66 @@
9699
]
97100
],
98101
]
99-
)
102+
)->setCustomAttributes([
103+
"price_type" => [
104+
'attribute_code' => 'price_type',
105+
'value' => \Magento\Bundle\Model\Product\Price::PRICE_TYPE_DYNAMIC
106+
],
107+
"price_view" => [
108+
"attribute_code" => "price_view",
109+
"value" => "1",
110+
],
111+
])
100112
->setCanSaveBundleSelections(true)
101-
->setAffectBundleProductSelections(true)
102-
->save();
113+
->setHasOptions(false)
114+
->setAffectBundleProductSelections(true);
115+
if ($product->getBundleOptionsData()) {
116+
$options = [];
117+
foreach ($product->getBundleOptionsData() as $key => $optionData) {
118+
if (!(bool)$optionData['delete']) {
119+
$option = $objectManager->create('Magento\Bundle\Api\Data\OptionInterfaceFactory')
120+
->create(['data' => $optionData]);
121+
$option->setSku($product->getSku());
122+
$option->setOptionId(null);
103123

104-
//Load options
105-
$typeInstance = $product->getTypeInstance();
106-
$typeInstance->setStoreFilter($product->getStoreId(), $product);
107-
$optionCollection = $typeInstance->getOptionsCollection($product);
108-
$selectionCollection = $typeInstance->getSelectionsCollection($typeInstance->getOptionsIds($product), $product);
124+
$links = [];
125+
$bundleLinks = $product->getBundleSelectionsData();
126+
if (!empty($bundleLinks[$key])) {
127+
foreach ($bundleLinks[$key] as $linkData) {
128+
if (!(bool)$linkData['delete']) {
129+
/** @var \Magento\Bundle\Api\Data\LinkInterface$link */
130+
$link = $objectManager->create('Magento\Bundle\Api\Data\LinkInterfaceFactory')
131+
->create(['data' => $linkData]);
132+
$linkProduct = $productRepository->getById($linkData['product_id']);
133+
$link->setSku($linkProduct->getSku());
134+
$link->setQty($linkData['selection_qty']);
135+
if (isset($linkData['selection_can_change_qty'])) {
136+
$link->setCanChangeQuantity($linkData['selection_can_change_qty']);
137+
}
138+
$links[] = $link;
139+
}
140+
}
141+
$option->setProductLinks($links);
142+
$options[] = $option;
143+
}
144+
}
145+
}
146+
$extension = $product->getExtensionAttributes();
147+
$extension->setBundleProductOptions($options);
148+
$product->setExtensionAttributes($extension);
149+
}
150+
$productRepository->save($product);
109151

152+
$product = $productRepository->get($product->getSku());
110153
$bundleOptions = [];
111154
$bundleOptionsQty = [];
112155
/** @var $option \Magento\Bundle\Model\Option */
113-
foreach ($optionCollection as $option) {
114-
/** @var $selection \Magento\Bundle\Model\Selection */
115-
foreach ($selectionCollection as $selection) {
116-
$bundleOptions[$option->getId()][] = $selection->getSelectionId();
156+
foreach ($product->getExtensionAttributes()->getBundleProductOptions() as $option) {
157+
foreach ($option->getProductLinks() as $selection) {
158+
/**
159+
* @var \Magento\Bundle\Api\Data\LinkInterface $selection
160+
*/
161+
$bundleOptions[$option->getId()][] = $selection->getId();
117162
$bundleOptionsQty[$option->getId()][] = 1;
118163
}
119164
}

0 commit comments

Comments
 (0)