From 8d7c37509fdc663aa6ba7cb87ac633ad9f1980be Mon Sep 17 00:00:00 2001 From: wuhui_zzw <1760308791@qq.com> Date: Thu, 17 Aug 2023 15:47:05 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=EF=BC=9A=E5=95=86=E5=93=81?= =?UTF-8?q?=E8=AF=A6=E6=83=85=E9=A1=B5=E9=9D=A2=E4=B8=8B=E5=8D=95=E4=BC=98?= =?UTF-8?q?=E5=8C=96=EF=BC=8C=E6=94=AF=E6=8C=81=E5=A4=9A=E8=A7=84=E6=A0=BC?= =?UTF-8?q?=E4=B8=8B=E5=8D=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Shop/Http/Controllers/CartController.php | 29 +- beike/Shop/Http/Requests/CartRequest.php | 6 +- resources/lang/en/shop/products.php | 34 +- resources/lang/zh_cn/shop/products.php | 34 +- themes/default/product/product.blade.php | 359 ++++++++++++------ 5 files changed, 307 insertions(+), 155 deletions(-) diff --git a/beike/Shop/Http/Controllers/CartController.php b/beike/Shop/Http/Controllers/CartController.php index 29521e1b..a03d1aaa 100644 --- a/beike/Shop/Http/Controllers/CartController.php +++ b/beike/Shop/Http/Controllers/CartController.php @@ -56,21 +56,30 @@ class CartController extends Controller { try { $skuId = $request->sku_id; - $quantity = $request->quantity ?? 1; + $quantity = $request->quantity ?? 1; $buyNow = (bool) $request->buy_now ?? false; $customer = current_customer(); - - $sku = ProductSku::query() - // ->whereRelation('product', 'active', '=', true) - ->findOrFail($skuId); - - $cart = CartService::add($sku, $quantity, $customer); - if ($buyNow) { - CartService::select($customer, [$cart->id]); + // 多规格批量加入购物车处理 + if(is_int($skuId)){ + // 非多规格下单 + $sku = ProductSku::query()->findOrFail($skuId); + $cart = CartService::add($sku, $quantity, $customer); + $cartIds = [$cart->id]; + }else{ + // 多规格下单 + $skuList = array_values(json_decode($skuId,TRUE)); + foreach($skuList as $item){ + if((int)$item['quantity'] > 0){ + $sku = ProductSku::query()->findOrFail($item['id']); + $cart = CartService::add($sku, $item['quantity'], $customer); + $cartIds[] = $cart->id; + } + } } - $cart = hook_filter('cart.store.data', $cart); + if ($buyNow) CartService::select($customer, $cartIds); + $cart = hook_filter('cart.store.data', $cart); return json_success(trans('shop/carts.added_to_cart'), $cart); } catch (\Exception $e) { return json_fail($e->getMessage()); diff --git a/beike/Shop/Http/Requests/CartRequest.php b/beike/Shop/Http/Requests/CartRequest.php index d94f0b54..3ea783a2 100644 --- a/beike/Shop/Http/Requests/CartRequest.php +++ b/beike/Shop/Http/Requests/CartRequest.php @@ -36,8 +36,8 @@ class CartRequest extends FormRequest $skuId = (int) $this->get('sku_id'); return [ - 'sku_id' => 'required|int', - 'quantity' => ['required', 'int', function ($attribute, $value, $fail) use ($skuId) { + 'sku_id' => 'required', + 'quantity' => ['required', 'int', /*function ($attribute, $value, $fail) use ($skuId) { $sku = ProductSku::query()->where('id', $skuId)->first(); $skuQuantity = $sku->quantity; if ($value > $skuQuantity) { @@ -46,7 +46,7 @@ class CartRequest extends FormRequest if($sku->product->price_setting == 'num' && $value < $sku->product->numprices[0]->num){ $fail(trans('shop/products.quantity_error')); } - }], + }*/], 'buy_now' => 'bool', ]; } diff --git a/resources/lang/en/shop/products.php b/resources/lang/en/shop/products.php index e20985bf..8a0e161c 100644 --- a/resources/lang/en/shop/products.php +++ b/resources/lang/en/shop/products.php @@ -1,26 +1,30 @@ * @created 2022-08-18 08:31:03 * @modified 2022-08-18 08:31:03 */ - return [ - 'search' => 'Search', - 'add_to_favorites' => 'Add To Favorites', - 'add_to_cart' => 'Add To Cart', - 'buy_now' => 'Buy Now', - 'product_details' => 'Product Details', - 'in_stock' => 'In Stock', - 'out_stock' => 'Out Stock', - 'model' => 'Model', - 'quantity_error' => 'Quantity Error', - 'inquiry' => 'Inquiry', - 'enter_contacts' => 'Please enter contacts', - 'enter_email' => 'Please enter email', - 'enter_content' => 'Please enter content', + 'search' => 'Search', + 'add_to_favorites' => 'Add To Favorites', + 'cancel_to_favorites' => 'Cancel To Favorites', + 'add_to_cart' => 'Add To Cart', + 'buy_now' => 'Buy Now', + 'product_details' => 'Product Details', + 'in_stock' => 'In Stock', + 'out_stock' => 'Out Stock', + 'model' => 'Model', + 'quantity_error' => 'Quantity Error', + 'buy_sku_error' => 'Specification information error', + 'inquiry' => 'Inquiry', + 'enter_contacts' => 'Please enter contacts', + 'enter_email' => 'Please enter email', + 'enter_content' => 'Please enter content', + 'add_buy_sku' => 'Add Buy Sku', + 'product_total' => 'Product Total', + 'shipping_fee' => 'Shipping Fee', + 'order_total' => 'Order Total', ]; diff --git a/resources/lang/zh_cn/shop/products.php b/resources/lang/zh_cn/shop/products.php index d67a7a3b..44ffbc83 100644 --- a/resources/lang/zh_cn/shop/products.php +++ b/resources/lang/zh_cn/shop/products.php @@ -1,26 +1,30 @@ * @created 2022-08-18 08:31:03 * @modified 2022-08-18 08:31:03 */ - return [ - 'search' => '搜索', - 'add_to_favorites' => '加入收藏夹', - 'add_to_cart' => '加入购物车', - 'buy_now' => '立即购买', - 'product_details' => '商品详情', - 'in_stock' => '有货', - 'out_stock' => '缺货', - 'model' => '型号', - 'quantity_error' => '数量错误', - 'inquiry' => '咨询', - 'enter_contacts' => '请输入联系人', - 'enter_email' => '请输入邮件', - 'enter_content' => '请输入内容', + 'search' => '搜索', + 'add_to_favorites' => '加入收藏夹', + 'cancel_to_favorites' => '取消收藏', + 'add_to_cart' => '加入购物车', + 'buy_now' => '立即购买', + 'product_details' => '商品详情', + 'in_stock' => '有货', + 'out_stock' => '缺货', + 'model' => '型号', + 'quantity_error' => '数量错误', + 'buy_sku_error' => '规格信息错误', + 'inquiry' => '咨询', + 'enter_contacts' => '请输入联系人', + 'enter_email' => '请输入邮件', + 'enter_content' => '请输入内容', + 'add_buy_sku' => '添加购买规格', + 'product_total' => '产品总计', + 'shipping_fee' => '运费', + 'order_total' => '订单总额', ]; diff --git a/themes/default/product/product.blade.php b/themes/default/product/product.blade.php index 0dfb6529..6adf7414 100644 --- a/themes/default/product/product.blade.php +++ b/themes/default/product/product.blade.php @@ -26,7 +26,58 @@ @if (!request('iframe')) @endif - +
@@ -108,8 +159,8 @@
{{ __('product.quantity') }}:
- - + +
@endhookwrapper @@ -142,7 +193,7 @@
@endif - + {{--商品规格--}}

@{{ variable.name }}

@@ -186,80 +237,89 @@
- - @if ($product['active']) -
- @hook('product.detail.buy.before') + {{-- 购买数量 - 单规格 --}} +
+ +
+ + +
+
+ {{--购买&进入购物车按钮--}} +
+ @hook('product.detail.buy.before') + {{--添加购买规格--}} + + {{-- 购买数量 - 多规格 --}} +
@hookwrapper('product.detail.quantity.input') -
- -
- - +
+
+ @{{ skuInfoValue.name }}:@{{ skuInfoValue.value }} +
+
+ +
+ + +
@endhookwrapper - @hookwrapper('product.detail.add_to_cart') - - @endhookwrapper - @hookwrapper('product.detail.buy_now') - - @endhookwrapper - @hook('product.detail.buy.after')
- - @if (current_customer() || !request('iframe')) - @hookwrapper('product.detail.wishlist') -
- + @endhookwrapper + {{-- 直接下单产品 - 显示立即购买按钮 --}} + @if ($product['active']) + @hookwrapper('product.detail.buy_now') + -
- @endhookwrapper - @endif - @else - {{--
{{ __('product.has_been_inactive') }}
--}} -
- @hook('product.detail.buy.before') - @hookwrapper('product.detail.quantity.input') -
- -
- - -
-
- @endhookwrapper - @hookwrapper('product.detail.add_to_cart') - - @endhookwrapper + @endhookwrapper + @endif + @hook('product.detail.buy.after') + {{-- 加入收藏 --}} + @if ((current_customer() || !request('iframe'))) + @hookwrapper('product.detail.wishlist') + + @endhookwrapper + @endif
- @endif +
+ {{--价格实时计算--}}
    -
  • Product Total@{{ product_total }}
  • -
  • Shipping Fee@{{ shipping_fee }}
  • -
  • Order Total@{{ order_tota }}
  • +
  • + {{ __('shop/products.product_total') }} + @{{ product_total }} +
  • +
  • + {{ __('shop/products.shipping_fee') }} + @{{ shipping_fee }} +
  • +
  • + {{ __('shop/products.order_total') }} + @{{ order_tota }} +