Skip to content

Commit 97b1b15

Browse files
committed
Merge remote-tracking branch 'l3/MC-38575' into PR-01-21
2 parents 1c78cdb + 0998b1e commit 97b1b15

File tree

2 files changed

+37
-6
lines changed

2 files changed

+37
-6
lines changed

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

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -877,15 +877,17 @@ public function getAttributes($groupId = null, $skipSuper = false)
877877
*/
878878
public function beforeSave()
879879
{
880-
$this->setTypeHasOptions(false);
881-
$this->setTypeHasRequiredOptions(false);
882-
$this->setHasOptions(false);
883-
$this->setRequiredOptions(false);
880+
if ($this->getData('has_options') === null) {
881+
$this->setHasOptions(false);
882+
}
883+
if ($this->getData('required_options') === null) {
884+
$this->setRequiredOptions(false);
885+
}
884886

885887
$this->getTypeInstance()->beforeSave($this);
886888

887-
$hasOptions = false;
888-
$hasRequiredOptions = false;
889+
$hasOptions = $this->getData('has_options') === "1";
890+
$hasRequiredOptions = $this->getData('required_options') === "1";
889891

890892
/**
891893
* $this->_canAffectOptions - set by type instance only

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

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1095,6 +1095,35 @@ public function testSaveAndDuplicate()
10951095
$this->model->afterSave();
10961096
}
10971097

1098+
/**
1099+
* Test for save method behavior with type options
1100+
*/
1101+
public function testSaveWithoutTypeOptions()
1102+
{
1103+
$this->model->setCanSaveCustomOptions(false);
1104+
$this->model->setTypeHasOptions(true);
1105+
$this->model->setTypeHasRequiredOptions(true);
1106+
$this->configureSaveTest();
1107+
$this->model->beforeSave();
1108+
$this->model->afterSave();
1109+
$this->assertTrue($this->model->getTypeHasOptions());
1110+
$this->assertTrue($this->model->getTypeHasRequiredOptions());
1111+
}
1112+
1113+
/**
1114+
* Test for save method with provided options data
1115+
*/
1116+
public function testSaveWithProvidedRequiredOptions()
1117+
{
1118+
$this->model->setData("has_options", "1");
1119+
$this->model->setData("required_options", "1");
1120+
$this->configureSaveTest();
1121+
$this->model->beforeSave();
1122+
$this->model->afterSave();
1123+
$this->assertTrue($this->model->getHasOptions());
1124+
$this->assertTrue($this->model->getRequiredOptions());
1125+
}
1126+
10981127
public function testGetIsSalableSimple()
10991128
{
11001129
$typeInstanceMock =

0 commit comments

Comments
 (0)