Skip to content

Commit bf8ee30

Browse files
Merge forwardport of #13036 to 2.3-develop branch
Applied pull request patch https://github.com/magento/magento2/pull/13036.patch (created by @vinayshah) based on commit(s): 1. 843bc62 2. f89e04d 3. df96b51 Fixed GitHub Issues in 2.3-develop branch: - #12705: Integrity constraint violation error after reordering product with custom options (reported by @alena-marchenko)
2 parents d678f15 + 4ed8f5b commit bf8ee30

File tree

3 files changed

+45
-2
lines changed

3 files changed

+45
-2
lines changed

app/code/Magento/ConfigurableProductSales/Model/Order/Reorder/OrderedProductAvailabilityChecker.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public function __construct(
4545
public function isAvailable(Item $item)
4646
{
4747
$buyRequest = $item->getBuyRequest();
48-
$superAttribute = $buyRequest->getData()['super_attribute'];
48+
$superAttribute = $buyRequest->getData()['super_attribute'] ?? [];
4949
$connection = $this->getConnection();
5050
$select = $connection->select();
5151
$orderItemParentId = $item->getParentItem()->getProductId();

app/code/Magento/Quote/Model/Quote/Item.php

+3
Original file line numberDiff line numberDiff line change
@@ -745,6 +745,9 @@ public function saveItemOptions()
745745
unset($this->_options[$index]);
746746
unset($this->_optionsByCode[$option->getCode()]);
747747
} else {
748+
if (!$option->getItem() || !$option->getItem()->getId()) {
749+
$option->setItem($this);
750+
}
748751
$option->save();
749752
}
750753
}

app/code/Magento/Quote/Test/Unit/Model/Quote/ItemTest.php

+41-1
Original file line numberDiff line numberDiff line change
@@ -850,7 +850,18 @@ public function testSetOptionsWithNull()
850850
private function createOptionMock($optionCode, $optionData = [])
851851
{
852852
$optionMock = $this->getMockBuilder(\Magento\Quote\Model\Quote\Item\Option::class)
853-
->setMethods(['setData', 'setItem', 'getCode', '__wakeup', 'isDeleted', 'getValue', 'getProduct'])
853+
->setMethods([
854+
'setData',
855+
'setItem',
856+
'getItem',
857+
'getCode',
858+
'__wakeup',
859+
'isDeleted',
860+
'delete',
861+
'getValue',
862+
'getProduct',
863+
'save'
864+
])
854865
->disableOriginalConstructor()
855866
->getMock();
856867
$optionMock->expects($this->any())
@@ -1189,4 +1200,33 @@ public function testRemoveErrorInfosByParamsAllErrorsRemoved()
11891200
$this->assertFalse($this->model->getHasError());
11901201
$this->assertEquals('', $this->model->getMessage());
11911202
}
1203+
1204+
/**
1205+
* Test method \Magento\Quote\Model\Quote\Item::saveItemOptions
1206+
*/
1207+
public function testSaveItemOptions()
1208+
{
1209+
$optionMockDeleted = $this->createOptionMock(100);
1210+
$optionMockDeleted->expects(self::once())->method('isDeleted')->willReturn(true);
1211+
$optionMockDeleted->expects(self::once())->method('delete');
1212+
1213+
$optionMock1 = $this->createOptionMock(200);
1214+
$optionMock1->expects(self::once())->method('isDeleted')->willReturn(false);
1215+
$quoteItemMock1 = $this->createPartialMock(\Magento\Quote\Model\Quote\Item::class, ['getId']);
1216+
$quoteItemMock1->expects(self::once())->method('getId')->willReturn(null);
1217+
$optionMock1->expects(self::exactly(2))->method('getItem')->willReturn($quoteItemMock1);
1218+
$optionMock1->expects(self::exactly(2))->method('setItem')->with($this->model);
1219+
$optionMock1->expects(self::once())->method('save');
1220+
1221+
$optionMock2 = $this->createOptionMock(300);
1222+
$optionMock2->expects(self::once())->method('isDeleted')->willReturn(false);
1223+
$quoteItemMock2 = $this->createPartialMock(\Magento\Quote\Model\Quote\Item::class, ['getId']);
1224+
$quoteItemMock2->expects(self::once())->method('getId')->willReturn(11);
1225+
$optionMock2->expects(self::exactly(2))->method('getItem')->willReturn($quoteItemMock2);
1226+
$optionMock2->expects(self::once())->method('setItem')->with($this->model);
1227+
$optionMock2->expects(self::once())->method('save');
1228+
1229+
$this->model->setOptions([$optionMockDeleted, $optionMock1, $optionMock2]);
1230+
$this->model->saveItemOptions();
1231+
}
11921232
}

0 commit comments

Comments
 (0)