Skip to content

Commit

Permalink
ENGCOM-732: MAGETWO-70390 selection can change qty #100
Browse files Browse the repository at this point in the history
  • Loading branch information
Stanislav Idolov authored Mar 9, 2018
2 parents e3f1e56 + 23baebf commit d8333f9
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,8 @@ protected function getFormattedBundleSelections($optionValues, SelectionCollecti
'price' => $selection->getSelectionPriceValue(),
'default' => $selection->getIsDefault(),
'default_qty' => $selection->getSelectionQty(),
'price_type' => $this->getPriceTypeValue($selection->getSelectionPriceType())
'price_type' => $this->getPriceTypeValue($selection->getSelectionPriceType()),
'can_change_qty' => $selection->getSelectionCanChangeQty(),
];
$bundleData .= $optionValues
. ImportModel::DEFAULT_GLOBAL_MULTI_VALUE_SEPARATOR
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,7 @@ protected function populateSelectionTemplate($selection, $optionId, $parentId, $
} else {
$productId = $selection['product_id'];
}

$populatedSelection = [
'selection_id' => null,
'option_id' => (int)$optionId,
Expand All @@ -310,7 +311,8 @@ protected function populateSelectionTemplate($selection, $optionId, $parentId, $
? self::SELECTION_PRICE_TYPE_FIXED : self::SELECTION_PRICE_TYPE_PERCENT,
'selection_price_value' => (isset($selection['price'])) ? (float)$selection['price'] : 0.0,
'selection_qty' => (isset($selection['default_qty'])) ? (float)$selection['default_qty'] : 1.0,
'selection_can_change_qty' => 1,
'selection_can_change_qty' => isset($selection['can_change_qty'])
? ($selection['can_change_qty'] ? 1 : 0) : 1,
];
if (isset($selection['selection_id'])) {
$populatedSelection['selection_id'] = $selection['selection_id'];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,20 @@ protected function setUp()
);
$this->selection = $this->createPartialMock(
\Magento\Catalog\Model\Product::class,
['getSku', 'getSelectionPriceValue', 'getIsDefault', 'getSelectionQty', 'getSelectionPriceType']
[
'getSku',
'getSelectionPriceValue',
'getIsDefault',
'getSelectionQty',
'getSelectionPriceType',
'getSelectionCanChangeQty'
]
);
$this->selection->expects($this->any())->method('getSku')->willReturn(1);
$this->selection->expects($this->any())->method('getSelectionPriceValue')->willReturn(1);
$this->selection->expects($this->any())->method('getSelectionQty')->willReturn(1);
$this->selection->expects($this->any())->method('getSelectionPriceType')->willReturn(1);
$this->selection->expects($this->any())->method('getSelectionCanChangeQty')->willReturn(1);
$this->selectionsCollection = $this->createPartialMock(
\Magento\Bundle\Model\ResourceModel\Selection\Collection::class,
['getIterator', 'addAttributeToSort']
Expand Down Expand Up @@ -168,6 +176,19 @@ public function testAddData()
'additional_attributes' => $attributes
];
$preparedRow = $preparedData->addData($dataRow, 1);

$bundleValues = [
'name=title',
'type=1',
'required=1',
'sku=1',
'price=1',
'default=',
'default_qty=1',
'price_type=percent',
'can_change_qty=1',
];

$expected = [
'sku' => 'sku1',
'additional_attributes' => 'attribute=1,attribute2="Text",attribute3=One,Two,Three',
Expand All @@ -176,7 +197,7 @@ public function testAddData()
'bundle_sku_type' => 'fixed',
'bundle_price_view' => 'As low as',
'bundle_weight_type' => 'fixed',
'bundle_values' => 'name=title,type=1,required=1,sku=1,price=1,default=,default_qty=1,price_type=percent'
'bundle_values' => implode(',', $bundleValues)
];
$this->assertEquals($expected, $preparedRow);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,18 @@ public function testBundleImport()
$optionSku = 'Simple ' . ($optionKey + 1 + $linkKey);
$this->assertEquals($optionIdList[$optionSku], $productLink->getData('entity_id'));
$this->assertEquals($optionSku, $productLink->getData('sku'));

switch ($optionKey + 1 + $linkKey) {
case 1:
$this->assertEquals(1, (int) $productLink->getCanChangeQuantity());
break;
case 2:
$this->assertEquals(0, (int) $productLink->getCanChangeQuantity());
break;
case 3:
$this->assertEquals(1, (int) $productLink->getCanChangeQuantity());
break;
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ sku,store_view_code,attribute_set_code,product_type,product_websites,name,produc
Simple 1,,Default,simple,base,Simple 1,1,100,,1000,0,1,,,,,
Simple 2,,Default,simple,base,Simple 2,1,200,,1000,0,1,,,,,
Simple 3,,Default,simple,base,Simple 3,1,300,,1000,0,1,,,,,
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"
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 comments on commit d8333f9

Please sign in to comment.