|
|
@@ -388,35 +388,32 @@ class FlexibleVariantController extends Controller
|
|
|
|
|
|
$variants[$variantIndex]['variant_id'] = $variant->id;
|
|
|
|
|
|
- $productOptions = collect($this->_selectedOptions)
|
|
|
- ->mapWithKeys(function ($option) use ($variant) {
|
|
|
- return [
|
|
|
- $option['id'] => [
|
|
|
- 'position' => $option['position'],
|
|
|
- ],
|
|
|
- ];
|
|
|
- });
|
|
|
- //同步选项
|
|
|
- $this->_product->options()->sync($productOptions);
|
|
|
-
|
|
|
- $variantIds=collect($variants)->pluck('id');
|
|
|
- //删除无用的变体
|
|
|
- $this->_product->variants()->whereNotIn('id', $variantIds)->delete();
|
|
|
- DB::commit();
|
|
|
- return response()->json([
|
|
|
- 'success' => true,
|
|
|
- 'message' => 'Variants saved successfully',
|
|
|
- 'data' => [
|
|
|
- 'variants' => $variants,
|
|
|
- 'selected_options' => $this->_selectedOptions,
|
|
|
- ],
|
|
|
- ]);
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
+ $productOptions = collect($this->_selectedOptions)
|
|
|
+ ->mapWithKeys(function ($option) use ($variant) {
|
|
|
+ return [
|
|
|
+ $option['id'] => [
|
|
|
+ 'position' => $option['position'],
|
|
|
+ ],
|
|
|
+ ];
|
|
|
+ });
|
|
|
+ //同步选项
|
|
|
+ $this->_product->options()->sync($productOptions);
|
|
|
+
|
|
|
+ $variantIds=collect($variants)->pluck('id');
|
|
|
+ //删除无用的变体
|
|
|
+ $this->_product->variants()->whereNotIn('id', $variantIds)->delete();
|
|
|
+ DB::commit();
|
|
|
+ return response()->json([
|
|
|
+ 'success' => true,
|
|
|
+ 'message' => 'Variants saved successfully',
|
|
|
+ 'data' => [
|
|
|
+ 'variants' => $variants,
|
|
|
+ 'selected_options' => $this->_selectedOptions,
|
|
|
+ ],
|
|
|
+ ]);
|
|
|
|
|
|
|
|
|
}
|