Skip to content

Commit

Permalink
#9342: Add "selection_can_change_qty" support
Browse files Browse the repository at this point in the history
  • Loading branch information
adam-paterson committed Mar 2, 2018
1 parent 77fefd8 commit fe9054e
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 10 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 @@ -311,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' => isset($selection['can_change_qty']) ? ($selection['can_change_qty'] ? 1 : 0) : 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 @@ -105,15 +105,15 @@ public function testBundleImport()
$this->assertEquals($optionIdList[$optionSku], $productLink->getData('entity_id'));
$this->assertEquals($optionSku, $productLink->getData('sku'));

switch ($optionKey) {
case 0:
$this->assertEquals(1, $productLink->getData('selection_can_change_qty'));
break;
switch ($optionKey + 1 + $linkKey) {
case 1:
$this->assertEquals(0, $productLink->getData('selection_can_change_qty'));
$this->assertEquals(1, (int) $productLink->getCanChangeQuantity());
break;
case 2:
$this->assertEquals(1, $productLink->getData('selection_can_change_qty'));
$this->assertEquals(0, (int) $productLink->getCanChangeQuantity());
break;
case 3:
$this->assertEquals(1, (int) $productLink->getCanChangeQuantity());
break;
}
}
Expand Down

0 comments on commit fe9054e

Please sign in to comment.