Skip to content

Commit b772470

Browse files
committed
MAGETWO-64547: Bundle Products - The options you selected are not available.
Static fixes
1 parent 27b121a commit b772470

File tree

7 files changed

+272
-256
lines changed

7 files changed

+272
-256
lines changed

app/code/Magento/Bundle/Controller/Adminhtml/Product/Initialization/Helper/Plugin/Bundle.php

Lines changed: 33 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -147,25 +147,7 @@ protected function processBundleOptionsData(\Magento\Catalog\Model\Product $prod
147147
if (!empty($linkData['selection_id'])) {
148148
$linkData['id'] = $linkData['selection_id'];
149149
}
150-
$link = $this->linkFactory->create(['data' => $linkData]);
151-
152-
if ((int)$product->getPriceType() !== \Magento\Bundle\Model\Product\Price::PRICE_TYPE_DYNAMIC) {
153-
if (array_key_exists('selection_price_value', $linkData)) {
154-
$link->setPrice($linkData['selection_price_value']);
155-
}
156-
if (array_key_exists('selection_price_type', $linkData)) {
157-
$link->setPriceType($linkData['selection_price_type']);
158-
}
159-
}
160-
161-
$linkProduct = $this->productRepository->getById($linkData['product_id']);
162-
$link->setSku($linkProduct->getSku());
163-
$link->setQty($linkData['selection_qty']);
164-
165-
if (array_key_exists('selection_can_change_qty', $linkData)) {
166-
$link->setCanChangeQuantity($linkData['selection_can_change_qty']);
167-
}
168-
$links[] = $link;
150+
$links[] = $this->buildLink($product, $linkData);;
169151
}
170152
$option->setProductLinks($links);
171153
$options[] = $option;
@@ -209,4 +191,36 @@ protected function processDynamicOptionsData(\Magento\Catalog\Model\Product $pro
209191
}
210192
$product->setOptions($newOptions);
211193
}
194+
195+
/**
196+
* @param \Magento\Catalog\Model\Product $product
197+
* @param $linkData
198+
*
199+
* @return \Magento\Bundle\Api\Data\LinkInterface
200+
*/
201+
private function buildLink(
202+
\Magento\Catalog\Model\Product $product,
203+
$linkData
204+
) {
205+
$link = $this->linkFactory->create(['data' => $linkData]);
206+
207+
if ((int)$product->getPriceType() !== \Magento\Bundle\Model\Product\Price::PRICE_TYPE_DYNAMIC) {
208+
if (array_key_exists('selection_price_value', $linkData)) {
209+
$link->setPrice($linkData['selection_price_value']);
210+
}
211+
if (array_key_exists('selection_price_type', $linkData)) {
212+
$link->setPriceType($linkData['selection_price_type']);
213+
}
214+
}
215+
216+
$linkProduct = $this->productRepository->getById($linkData['product_id']);
217+
$link->setSku($linkProduct->getSku());
218+
$link->setQty($linkData['selection_qty']);
219+
220+
if (array_key_exists('selection_can_change_qty', $linkData)) {
221+
$link->setCanChangeQuantity($linkData['selection_can_change_qty']);
222+
}
223+
224+
return $link;
225+
}
212226
}

app/code/Magento/Bundle/Model/LinkManagement.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ public function saveChild(
169169
* @param string $parentProductId
170170
* @return \Magento\Bundle\Model\Selection
171171
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
172+
* @SuppressWarnings(PHPMD.NPathComplexity)
172173
*/
173174
protected function mapProductLinkToSelectionModel(
174175
\Magento\Bundle\Model\Selection $selectionModel,
Lines changed: 47 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,47 @@
1-
<?php
2-
/**
3-
* Copyright © Magento, Inc. All rights reserved.
4-
* See COPYING.txt for license details.
5-
*/
6-
namespace Magento\Bundle\Model\ResourceModel\Selection\Collection;
7-
8-
use Magento\Bundle\Model\ResourceModel\Selection\Collection;
9-
10-
/**
11-
* An applier of additional filters to a selection collection.
12-
*
13-
* The class is introduced to extend filtering abilities of the collection
14-
* without backward incompatible changes in a corresponding collection class.
15-
*/
16-
class FilterApplier
17-
{
18-
/**
19-
* @var array
20-
*/
21-
private $conditionTypesMap = [
22-
'eq' => ' = ?',
23-
'in' => 'IN (?)'
24-
];
25-
26-
/**
27-
* Applies filter to the given collection in accordance with the given condition.
28-
*
29-
* @param Collection $collection
30-
* @param string $field
31-
* @param string|array $value
32-
* @param string $conditionType
33-
*
34-
* @return void
35-
*/
36-
public function apply(Collection $collection, $field, $value, $conditionType = 'eq')
37-
{
38-
foreach ($collection->getSelect()->getPart('from') as $tableAlias => $data) {
39-
if ($data['tableName'] == $collection->getTable('catalog_product_bundle_selection')) {
40-
$field = $tableAlias . '.' . $field;
41-
}
42-
}
43-
44-
$collection->getSelect()
45-
->where($field . $this->conditionTypesMap[$conditionType], $value);
46-
}
47-
}
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Bundle\Model\ResourceModel\Selection\Collection;
7+
8+
use Magento\Bundle\Model\ResourceModel\Selection\Collection;
9+
10+
/**
11+
* An applier of additional filters to a selection collection.
12+
*
13+
* The class is introduced to extend filtering abilities of the collection
14+
* without backward incompatible changes in a corresponding collection class.
15+
*/
16+
class FilterApplier
17+
{
18+
/**
19+
* @var array
20+
*/
21+
private $conditionTypesMap = [
22+
'eq' => ' = ?',
23+
'in' => 'IN (?)'
24+
];
25+
26+
/**
27+
* Applies filter to the given collection in accordance with the given condition.
28+
*
29+
* @param Collection $collection
30+
* @param string $field
31+
* @param string|array $value
32+
* @param string $conditionType
33+
*
34+
* @return void
35+
*/
36+
public function apply(Collection $collection, $field, $value, $conditionType = 'eq')
37+
{
38+
foreach ($collection->getSelect()->getPart('from') as $tableAlias => $data) {
39+
if ($data['tableName'] == $collection->getTable('catalog_product_bundle_selection')) {
40+
$field = $tableAlias . '.' . $field;
41+
}
42+
}
43+
44+
$collection->getSelect()
45+
->where($field . $this->conditionTypesMap[$conditionType], $value);
46+
}
47+
}

app/code/Magento/Bundle/Setup/UpgradeSchema.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ class UpgradeSchema implements UpgradeSchemaInterface
1818
/**
1919
* {@inheritdoc}
2020
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
21+
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
2122
*/
2223
public function upgrade(SchemaSetupInterface $setup, ModuleContextInterface $context)
2324
{
Lines changed: 95 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -1,95 +1,95 @@
1-
<?php
2-
/**
3-
* Copyright © Magento, Inc. All rights reserved.
4-
* See COPYING.txt for license details.
5-
*/
6-
namespace Magento\BundleImportExport\Model\Import\Product\Type\Bundle;
7-
8-
/**
9-
* A bundle product relations (options, selections, etc.) data saver.
10-
*
11-
* Performs saving of a bundle product relations data during import operations.
12-
*/
13-
class RelationsDataSaver
14-
{
15-
/**
16-
* @var \Magento\Framework\App\ResourceConnection
17-
*/
18-
private $resource;
19-
20-
/**
21-
* @param \Magento\Framework\App\ResourceConnection $resource
22-
*/
23-
public function __construct(
24-
\Magento\Framework\App\ResourceConnection $resource
25-
) {
26-
$this->resource = $resource;
27-
}
28-
29-
/**
30-
* Saves given options.
31-
*
32-
* @param array $options
33-
*
34-
* @return void
35-
*/
36-
public function saveOptions(array $options)
37-
{
38-
if (!empty($options)) {
39-
$this->resource->getConnection()->insertOnDuplicate(
40-
$this->resource->getTableName('catalog_product_bundle_option'),
41-
$options,
42-
[
43-
'required',
44-
'position',
45-
'type'
46-
]
47-
);
48-
}
49-
}
50-
51-
/**
52-
* Saves given option values.
53-
*
54-
* @param array $optionValues
55-
*
56-
* @return void
57-
*/
58-
public function saveOptionValues(array $optionValues)
59-
{
60-
if (!empty($optionValues)) {
61-
$this->resource->getConnection()->insertOnDuplicate(
62-
$this->resource->getTableName('catalog_product_bundle_option_value'),
63-
$optionValues,
64-
['title']
65-
);
66-
}
67-
}
68-
69-
/**
70-
* Saves given selections.
71-
*
72-
* @param array $selections
73-
*
74-
* @return void
75-
*/
76-
public function saveSelections(array $selections)
77-
{
78-
if (!empty($selections)) {
79-
$this->resource->getConnection()->insertOnDuplicate(
80-
$this->resource->getTableName('catalog_product_bundle_selection'),
81-
$selections,
82-
[
83-
'selection_id',
84-
'product_id',
85-
'position',
86-
'is_default',
87-
'selection_price_type',
88-
'selection_price_value',
89-
'selection_qty',
90-
'selection_can_change_qty'
91-
]
92-
);
93-
}
94-
}
95-
}
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\BundleImportExport\Model\Import\Product\Type\Bundle;
7+
8+
/**
9+
* A bundle product relations (options, selections, etc.) data saver.
10+
*
11+
* Performs saving of a bundle product relations data during import operations.
12+
*/
13+
class RelationsDataSaver
14+
{
15+
/**
16+
* @var \Magento\Framework\App\ResourceConnection
17+
*/
18+
private $resource;
19+
20+
/**
21+
* @param \Magento\Framework\App\ResourceConnection $resource
22+
*/
23+
public function __construct(
24+
\Magento\Framework\App\ResourceConnection $resource
25+
) {
26+
$this->resource = $resource;
27+
}
28+
29+
/**
30+
* Saves given options.
31+
*
32+
* @param array $options
33+
*
34+
* @return void
35+
*/
36+
public function saveOptions(array $options)
37+
{
38+
if (!empty($options)) {
39+
$this->resource->getConnection()->insertOnDuplicate(
40+
$this->resource->getTableName('catalog_product_bundle_option'),
41+
$options,
42+
[
43+
'required',
44+
'position',
45+
'type'
46+
]
47+
);
48+
}
49+
}
50+
51+
/**
52+
* Saves given option values.
53+
*
54+
* @param array $optionValues
55+
*
56+
* @return void
57+
*/
58+
public function saveOptionValues(array $optionValues)
59+
{
60+
if (!empty($optionValues)) {
61+
$this->resource->getConnection()->insertOnDuplicate(
62+
$this->resource->getTableName('catalog_product_bundle_option_value'),
63+
$optionValues,
64+
['title']
65+
);
66+
}
67+
}
68+
69+
/**
70+
* Saves given selections.
71+
*
72+
* @param array $selections
73+
*
74+
* @return void
75+
*/
76+
public function saveSelections(array $selections)
77+
{
78+
if (!empty($selections)) {
79+
$this->resource->getConnection()->insertOnDuplicate(
80+
$this->resource->getTableName('catalog_product_bundle_selection'),
81+
$selections,
82+
[
83+
'selection_id',
84+
'product_id',
85+
'position',
86+
'is_default',
87+
'selection_price_type',
88+
'selection_price_value',
89+
'selection_qty',
90+
'selection_can_change_qty'
91+
]
92+
);
93+
}
94+
}
95+
}

dev/tests/functional/tests/app/Magento/Bundle/Test/TestCase/UpdateBundleOptionsShoppingCartTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ class UpdateBundleOptionsShoppingCartTest extends Injectable
4646
*/
4747
private $catalogProductEdit;
4848

49-
5049
/**
5150
* Factory for Test Steps.
5251
*
@@ -70,6 +69,7 @@ public function __inject(
7069
$this->catalogProductEdit = $catalogProductEditPage;
7170
$this->testStepFactory = $testStepFactory;
7271
}
72+
7373
/**
7474
* Test update bundle product option title after adding to the shopping cart
7575
*

0 commit comments

Comments
 (0)