|
@@ -363,10 +363,10 @@ class FlexibleVariantController extends Controller
|
|
|
]);
|
|
]);
|
|
|
$basePrice = null;
|
|
$basePrice = null;
|
|
|
|
|
|
|
|
- // if (! empty($variantData['variant_id'])) {
|
|
|
|
|
- // $variant = ProductVariant::find($variantData['variant_id']);
|
|
|
|
|
- // $basePrice = $variant->basePrices->first();
|
|
|
|
|
- // }
|
|
|
|
|
|
|
+ if (! empty($variantData['id'])) {
|
|
|
|
|
+ $variant = ProductVariant::find($variantData['id']);
|
|
|
|
|
+ // $basePrice = $variant->basePrices->first();
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
if (! empty($variantData['copied_id'])) {
|
|
if (! empty($variantData['copied_id'])) {
|
|
|
$copiedVariant = ProductVariant::find(
|
|
$copiedVariant = ProductVariant::find(
|
|
@@ -393,35 +393,32 @@ class FlexibleVariantController extends Controller
|
|
|
|
|
|
|
|
$variants[$variantIndex]['variant_id'] = $variant->id;
|
|
$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,
|
|
|
|
|
+ ],
|
|
|
|
|
+ ]);
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
}
|