diff --git a/vendor/magento/module-catalog/Model/Product/Option/Repository.php b/vendor/magento/module-catalog/Model/Product/Option/Repository.php index bb4e247de32..bb0f0c47922 100644 --- a/vendor/magento/module-catalog/Model/Product/Option/Repository.php +++ b/vendor/magento/module-catalog/Model/Product/Option/Repository.php @@ -158,6 +158,7 @@ class Repository implements \Magento\Catalog\Api\ProductCustomOptionRepositoryIn $option->setData('product_id', $product->getData($metadata->getLinkField())); $option->setData('store_id', $product->getStoreId()); + $backedOptions = $option->getValues(); if ($option->getOptionId()) { $options = $product->getOptions(); if (!$options) { @@ -174,6 +175,9 @@ class Repository implements \Magento\Catalog\Api\ProductCustomOptionRepositoryIn } $originalValues = $persistedOption->getValues(); $newValues = $option->getData('values'); + if (!$newValues) { + $newValues = $this->getOptionValues($option); + } if ($newValues) { if (isset($originalValues)) { $newValues = $this->markRemovedValues($newValues, $originalValues); @@ -182,6 +186,8 @@ class Repository implements \Magento\Catalog\Api\ProductCustomOptionRepositoryIn } } $option->save(); + // Required for API response data consistency + $option->setValues($backedOptions); return $option; } @@ -249,4 +255,28 @@ class Repository implements \Magento\Catalog\Api\ProductCustomOptionRepositoryIn } return $this->hydratorPool; } + + /** + * Get Option values from property + * + * Gets Option values stored in property, modifies for needed format and clears the property + * + * @param \Magento\Catalog\Api\Data\ProductCustomOptionInterface $option + * @return array|null + */ + private function getOptionValues(\Magento\Catalog\Api\Data\ProductCustomOptionInterface $option): ?array + { + if ($option->getValues() === null) { + return null; + } + + $optionValues = []; + + foreach ($option->getValues() as $optionValue) { + $optionValues[] = $optionValue->getData(); + } + $option->setValues(null); + + return $optionValues; + } }