|
@@ -285,6 +285,7 @@ class FlexibleVariantController extends Controller
|
|
|
foreach ($this->_selectedOptions as $optionIndex => $option) {
|
|
foreach ($this->_selectedOptions as $optionIndex => $option) {
|
|
|
$optionModel = empty($option['id']) ? new ProductOption() : ProductOption::findOrFail($option['id']);
|
|
$optionModel = empty($option['id']) ? new ProductOption() : ProductOption::findOrFail($option['id']);
|
|
|
|
|
|
|
|
|
|
+ $mapOptionValues = $optionModel->values()->pluck('id','code')->toArray();
|
|
|
|
|
|
|
|
$optionModel->label = $option['label'];
|
|
$optionModel->label = $option['label'];
|
|
|
$optionModel->type = $option['type'];
|
|
$optionModel->type = $option['type'];
|
|
@@ -296,11 +297,8 @@ class FlexibleVariantController extends Controller
|
|
|
$option['id'] = $optionModel->id;
|
|
$option['id'] = $optionModel->id;
|
|
|
|
|
|
|
|
foreach ($option['option_values'] as $optionValueIndex => $value) {
|
|
foreach ($option['option_values'] as $optionValueIndex => $value) {
|
|
|
- $optionValueModel = empty($value['id']) ?
|
|
|
|
|
- new ProductOptionValue([
|
|
|
|
|
- 'product_option_id' => $option['id'],
|
|
|
|
|
- ]) :
|
|
|
|
|
- ProductOptionValue::find($value['id']);
|
|
|
|
|
|
|
+ $optionValueModel = ProductOptionValue::find($value['id'] ?: ($mapOptionValues[$value['code']] ?? null))
|
|
|
|
|
+ ?? new ProductOptionValue(['product_option_id' => $option['id']]);
|
|
|
|
|
|
|
|
$optionValueModel->label = $value['label'];
|
|
$optionValueModel->label = $value['label'];
|
|
|
$optionValueModel->code = $value['code'];
|
|
$optionValueModel->code = $value['code'];
|