Skip to content

Commit 23baebf

Browse files
ENGCOM-732: MAGETWO-70390 selection can change qty #100
- Merge Pull Request magento-engcom/import-export-improvements#100 from adam-paterson/import-export-improvements:MAGETWO-70390-selection-can-change-qty - Merged commits: 1. 77fefd8 2. fe9054e
2 parents b335359 + fe9054e commit 23baebf

File tree

5 files changed

+41
-5
lines changed

5 files changed

+41
-5
lines changed

app/code/Magento/BundleImportExport/Model/Export/RowCustomizer.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,8 @@ protected function getFormattedBundleSelections($optionValues, SelectionCollecti
242242
'price' => $selection->getSelectionPriceValue(),
243243
'default' => $selection->getIsDefault(),
244244
'default_qty' => $selection->getSelectionQty(),
245-
'price_type' => $this->getPriceTypeValue($selection->getSelectionPriceType())
245+
'price_type' => $this->getPriceTypeValue($selection->getSelectionPriceType()),
246+
'can_change_qty' => $selection->getSelectionCanChangeQty(),
246247
];
247248
$bundleData .= $optionValues
248249
. ImportModel::DEFAULT_GLOBAL_MULTI_VALUE_SEPARATOR

app/code/Magento/BundleImportExport/Model/Import/Product/Type/Bundle.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,7 @@ protected function populateSelectionTemplate($selection, $optionId, $parentId, $
299299
} else {
300300
$productId = $selection['product_id'];
301301
}
302+
302303
$populatedSelection = [
303304
'selection_id' => null,
304305
'option_id' => (int)$optionId,
@@ -310,7 +311,8 @@ protected function populateSelectionTemplate($selection, $optionId, $parentId, $
310311
? self::SELECTION_PRICE_TYPE_FIXED : self::SELECTION_PRICE_TYPE_PERCENT,
311312
'selection_price_value' => (isset($selection['price'])) ? (float)$selection['price'] : 0.0,
312313
'selection_qty' => (isset($selection['default_qty'])) ? (float)$selection['default_qty'] : 1.0,
313-
'selection_can_change_qty' => 1,
314+
'selection_can_change_qty' => isset($selection['can_change_qty'])
315+
? ($selection['can_change_qty'] ? 1 : 0) : 1,
314316
];
315317
if (isset($selection['selection_id'])) {
316318
$populatedSelection['selection_id'] = $selection['selection_id'];

app/code/Magento/BundleImportExport/Test/Unit/Model/Export/Product/RowCustomizerTest.php

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,12 +105,20 @@ protected function setUp()
105105
);
106106
$this->selection = $this->createPartialMock(
107107
\Magento\Catalog\Model\Product::class,
108-
['getSku', 'getSelectionPriceValue', 'getIsDefault', 'getSelectionQty', 'getSelectionPriceType']
108+
[
109+
'getSku',
110+
'getSelectionPriceValue',
111+
'getIsDefault',
112+
'getSelectionQty',
113+
'getSelectionPriceType',
114+
'getSelectionCanChangeQty'
115+
]
109116
);
110117
$this->selection->expects($this->any())->method('getSku')->willReturn(1);
111118
$this->selection->expects($this->any())->method('getSelectionPriceValue')->willReturn(1);
112119
$this->selection->expects($this->any())->method('getSelectionQty')->willReturn(1);
113120
$this->selection->expects($this->any())->method('getSelectionPriceType')->willReturn(1);
121+
$this->selection->expects($this->any())->method('getSelectionCanChangeQty')->willReturn(1);
114122
$this->selectionsCollection = $this->createPartialMock(
115123
\Magento\Bundle\Model\ResourceModel\Selection\Collection::class,
116124
['getIterator', 'addAttributeToSort']
@@ -168,6 +176,19 @@ public function testAddData()
168176
'additional_attributes' => $attributes
169177
];
170178
$preparedRow = $preparedData->addData($dataRow, 1);
179+
180+
$bundleValues = [
181+
'name=title',
182+
'type=1',
183+
'required=1',
184+
'sku=1',
185+
'price=1',
186+
'default=',
187+
'default_qty=1',
188+
'price_type=percent',
189+
'can_change_qty=1',
190+
];
191+
171192
$expected = [
172193
'sku' => 'sku1',
173194
'additional_attributes' => 'attribute=1,attribute2="Text",attribute3=One,Two,Three',
@@ -176,7 +197,7 @@ public function testAddData()
176197
'bundle_sku_type' => 'fixed',
177198
'bundle_price_view' => 'As low as',
178199
'bundle_weight_type' => 'fixed',
179-
'bundle_values' => 'name=title,type=1,required=1,sku=1,price=1,default=,default_qty=1,price_type=percent'
200+
'bundle_values' => implode(',', $bundleValues)
180201
];
181202
$this->assertEquals($expected, $preparedRow);
182203
}

dev/tests/integration/testsuite/Magento/BundleImportExport/Model/Import/Product/Type/BundleTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,18 @@ public function testBundleImport()
104104
$optionSku = 'Simple ' . ($optionKey + 1 + $linkKey);
105105
$this->assertEquals($optionIdList[$optionSku], $productLink->getData('entity_id'));
106106
$this->assertEquals($optionSku, $productLink->getData('sku'));
107+
108+
switch ($optionKey + 1 + $linkKey) {
109+
case 1:
110+
$this->assertEquals(1, (int) $productLink->getCanChangeQuantity());
111+
break;
112+
case 2:
113+
$this->assertEquals(0, (int) $productLink->getCanChangeQuantity());
114+
break;
115+
case 3:
116+
$this->assertEquals(1, (int) $productLink->getCanChangeQuantity());
117+
break;
118+
}
107119
}
108120
}
109121
}

dev/tests/integration/testsuite/Magento/BundleImportExport/Model/Import/_files/import_bundle.csv

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ sku,store_view_code,attribute_set_code,product_type,product_websites,name,produc
22
Simple 1,,Default,simple,base,Simple 1,1,100,,1000,0,1,,,,,
33
Simple 2,,Default,simple,base,Simple 2,1,200,,1000,0,1,,,,,
44
Simple 3,,Default,simple,base,Simple 3,1,300,,1000,0,1,,,,,
5-
Bundle 1,,Default,bundle,base,Bundle 1,1,,shipment_type=separately,0,0,1,dynamic,dynamic,Price range,dynamic,"name=Option 1,type=checkbox,required=1,sku=Simple 1,price=0.0000,default=0,default_qty=1.0000,price_type=fixed|name=Option 2,type=checkbox,required=1,sku=Simple 2,price=0.0000,default=0,default_qty=1.0000,price_type=fixed|name=Option 2,type=checkbox,required=1,sku=Simple 3,price=0.0000,default=0,default_qty=1.0000,price_type=fixed"
5+
Bundle 1,,Default,bundle,base,Bundle 1,1,,shipment_type=separately,0,0,1,dynamic,dynamic,Price range,dynamic,"name=Option 1,type=checkbox,required=1,sku=Simple 1,price=0.0000,default=0,default_qty=1.0000,price_type=fixed,can_change_qty=1|name=Option 2,type=checkbox,required=1,sku=Simple 2,price=0.0000,default=0,default_qty=1.0000,price_type=fixed,can_change_qty=0|name=Option 2,type=checkbox,required=1,sku=Simple 3,price=0.0000,default=0,default_qty=1.0000,price_type=fixed"

0 commit comments

Comments
 (0)