feat(product): 恢復並實作商品起停用狀態功能,包含表單開關與列表顯示
This commit is contained in:
@@ -152,6 +152,7 @@ class ProductController extends Controller
|
||||
'price' => (float) $product->price,
|
||||
'member_price' => (float) $product->member_price,
|
||||
'wholesale_price' => (float) $product->wholesale_price,
|
||||
'is_active' => (bool) $product->is_active,
|
||||
]
|
||||
]);
|
||||
}
|
||||
@@ -188,14 +189,17 @@ class ProductController extends Controller
|
||||
'price' => 'nullable|numeric|min:0',
|
||||
'member_price' => 'nullable|numeric|min:0',
|
||||
'wholesale_price' => 'nullable|numeric|min:0',
|
||||
'is_active' => 'boolean',
|
||||
]);
|
||||
|
||||
$validated['is_active'] = true;
|
||||
|
||||
if (empty($validated['code'])) {
|
||||
$validated['code'] = $this->generateRandomCode();
|
||||
}
|
||||
|
||||
if (!isset($validated['is_active'])) {
|
||||
$validated['is_active'] = true;
|
||||
}
|
||||
|
||||
$product = Product::create($validated);
|
||||
|
||||
return redirect()->route('products.index')->with('success', '商品已建立');
|
||||
@@ -224,6 +228,7 @@ class ProductController extends Controller
|
||||
'price' => (float) $product->price,
|
||||
'member_price' => (float) $product->member_price,
|
||||
'wholesale_price' => (float) $product->wholesale_price,
|
||||
'is_active' => (bool) $product->is_active,
|
||||
],
|
||||
'categories' => Category::where('is_active', true)->get()->map(fn($c) => (object)['id' => $c->id, 'name' => $c->name]),
|
||||
'units' => Unit::all()->map(fn($u) => (object)['id' => (string) $u->id, 'name' => $u->name, 'code' => $u->code]),
|
||||
@@ -251,14 +256,17 @@ class ProductController extends Controller
|
||||
'price' => 'nullable|numeric|min:0',
|
||||
'member_price' => 'nullable|numeric|min:0',
|
||||
'wholesale_price' => 'nullable|numeric|min:0',
|
||||
'is_active' => 'boolean',
|
||||
]);
|
||||
|
||||
$validated['is_active'] = true;
|
||||
|
||||
if (empty($validated['code'])) {
|
||||
$validated['code'] = $this->generateRandomCode();
|
||||
}
|
||||
|
||||
if (!isset($validated['is_active'])) {
|
||||
$validated['is_active'] = true;
|
||||
}
|
||||
|
||||
$product->update($validated);
|
||||
|
||||
if ($request->input('from') === 'show') {
|
||||
|
||||
@@ -31,10 +31,12 @@ class Product extends Model
|
||||
'price',
|
||||
'member_price',
|
||||
'wholesale_price',
|
||||
'is_active',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'conversion_rate' => 'decimal:4',
|
||||
'is_active' => 'boolean',
|
||||
];
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user