Skip to content

Commit aed2eea

Browse files
committed
Product should be assigned to option while option is assigned to product.
1 parent 6047e8e commit aed2eea

File tree

2 files changed

+10
-18
lines changed

2 files changed

+10
-18
lines changed

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2030,9 +2030,11 @@ public function getOptions()
20302030
*/
20312031
public function setOptions(array $options = null)
20322032
{
2033-
foreach ($options as $option) {
2034-
if ($option instanceof \Magento\Catalog\Api\Data\ProductCustomOptionInterface) {
2035-
$option->setProduct($this);
2033+
if ($options) {
2034+
foreach ($options as $option) {
2035+
if ($option instanceof \Magento\Catalog\Api\Data\ProductCustomOptionInterface) {
2036+
$option->setProduct($this);
2037+
}
20362038
}
20372039
}
20382040
$this->setData('options', $options);

dev/tests/integration/testsuite/Magento/Catalog/Model/Product/CreateCustomOptionsTest.php

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,11 @@ public function testCreateOptionsWithTypeDate(array $optionData): void
230230
*/
231231
public function testCreateOptionWithError(array $optionData, \Exception $expectedErrorObject): void
232232
{
233-
$product = $this->productRepository->get('simple');
233+
/**
234+
* storeId == 0 required for 'error_option_without_title' test case.
235+
* See \Magento\Catalog\Model\Product\Option\Validator\DefaultValidator::isValidOptionTitle.
236+
*/
237+
$product = $this->productRepository->get('simple', false, 0);
234238
$createdOption = $this->customOptionFactory->create(['data' => $optionData]);
235239
$product->setOptions([$createdOption]);
236240
$this->expectExceptionObject($expectedErrorObject);
@@ -811,20 +815,6 @@ public function productCustomOptionsTypeDateDataProvider(): array
811815
public function productCustomOptionsWithErrorDataProvider(): array
812816
{
813817
return [
814-
'error_option_without_product_sku' => [
815-
[
816-
'record_id' => 0,
817-
'sort_order' => 1,
818-
'is_require' => 1,
819-
'sku' => 'test-option-title-1',
820-
'max_characters' => 50,
821-
'title' => 'Test option title 1',
822-
'type' => 'area',
823-
'price' => 10,
824-
'price_type' => 'fixed',
825-
],
826-
new CouldNotSaveException(__('The ProductSku is empty. Set the ProductSku and try again.')),
827-
],
828818
'error_option_without_type' => [
829819
[
830820
'record_id' => 0,

0 commit comments

Comments
 (0)