Skip to content

Commit 8c25bda

Browse files
authored
Merge pull request #6885 from magento-l3/MC-42420
MC-42420: Magento Admin can not add a Simple Product to the Order by SKU after deleting a Customizable Option (SKU with blank spaces)
2 parents 8b2ed7e + 4e73874 commit 8c25bda

File tree

2 files changed

+32
-2
lines changed

2 files changed

+32
-2
lines changed

app/code/Magento/Catalog/Model/Product.php

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -883,8 +883,8 @@ public function beforeSave()
883883

884884
$this->getTypeInstance()->beforeSave($this);
885885

886-
$hasOptions = $this->getData('has_options') === "1";
887-
$hasRequiredOptions = $this->getData('required_options') === "1";
886+
$hasOptions = $this->getData('has_options') === "1" && $this->isProductHasOptions();
887+
$hasRequiredOptions = $this->getData('required_options') === "1" && $this->isProductHasOptions();
888888

889889
/**
890890
* $this->_canAffectOptions - set by type instance only
@@ -934,6 +934,21 @@ public function beforeSave()
934934
parent::beforeSave();
935935
}
936936

937+
/**
938+
* Check based on options data
939+
*
940+
* @return bool
941+
*/
942+
private function isProductHasOptions() : bool
943+
{
944+
if ($this->getData('options') === null) {
945+
$result = true;
946+
} else {
947+
$result = is_array($this->getData('options')) && count($this->getData('options')) > 0;
948+
}
949+
return $result;
950+
}
951+
937952
/**
938953
* Check/set if options can be affected when saving product
939954
*

app/code/Magento/Catalog/Test/Unit/Model/ProductTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1113,6 +1113,21 @@ public function testSaveWithProvidedRequiredOptions()
11131113
$this->assertTrue($this->model->getRequiredOptions());
11141114
}
11151115

1116+
/**
1117+
* Test for save method with provided options settled via magic method
1118+
*/
1119+
public function testSaveWithProvidedRequiredOptionsValue()
1120+
{
1121+
$this->model->setHasOptions("1");
1122+
$this->model->setRequiredOptions("1");
1123+
$this->model->setData("options", null);
1124+
$this->configureSaveTest();
1125+
$this->model->beforeSave();
1126+
$this->model->afterSave();
1127+
$this->assertTrue($this->model->getHasOptions());
1128+
$this->assertTrue($this->model->getRequiredOptions());
1129+
}
1130+
11161131
public function testGetIsSalableSimple()
11171132
{
11181133
$typeInstanceMock =

0 commit comments

Comments
 (0)