s-cart / s-cart

Free Laravel e-commerce for business: shopping cart, cms content, and more...

Home Page:https://s-cart.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Không xóa được sub ảnh trong product/ sản phẩm

ThanhNguyenDo opened this issue · comments

Describe the bug
A clear and concise description of what the bug is.

To Reproduce
Steps to reproduce the behavior:

  1. Go to 'Admin\Sản phẩm'
  2. Vào edit 1 sản phẩm để xoá hết ảnh phụ
  3. Submit
  4. Nếu xoá hết sub ảnh sẽ k update được, luôn phải để lại 2 ảnh, 1 ảnh chính và 1 ảnh phụ

Expected behavior
Cho phép xoá hết ảnh phụ

Root cause analysis

//Update sub mages
AdminProductController
if ($subImages && in_array($product['kind'], [SC_PRODUCT_SINGLE, SC_PRODUCT_BUILD])) {
$product->images()->delete();
$arrSubImages = [];
foreach ($subImages as $key => $image) {
if ($image) {
$arrSubImages[] = new ShopProductImage(['image' => $image]);
}
}
$product->images()->saveMany($arrSubImages);
}

Khi $subImages length = 0 thì sẽ không vào được block if này

@ThanhNguyenDo
Fixed s-cart/core@c451870
Pls run php composer.phar update s-cart/core
Thanks.