diff --git a/beike/Shop/Services/TotalService.php b/beike/Shop/Services/TotalService.php index 0772cb57..5d4ce1b9 100644 --- a/beike/Shop/Services/TotalService.php +++ b/beike/Shop/Services/TotalService.php @@ -114,7 +114,9 @@ class TotalService */ private function getTotalClassMaps() { - $maps = []; + $maps = [ + 'sum_quantity' => "\Beike\\Shop\\Services\\TotalServices\\SumQuantityService" + ]; foreach (self::TOTAL_CODES as $code) { $serviceName = Str::studly($code) . 'Service'; $maps[$code] = "\Beike\\Shop\\Services\\TotalServices\\{$serviceName}"; diff --git a/beike/Shop/Services/TotalServices/ShippingService.php b/beike/Shop/Services/TotalServices/ShippingService.php index 1df0b4a3..ccbc1d91 100644 --- a/beike/Shop/Services/TotalServices/ShippingService.php +++ b/beike/Shop/Services/TotalServices/ShippingService.php @@ -93,6 +93,7 @@ class ShippingService{ if($logisticsId <= 0){ // 获取当前收货地址国家ID $address = $cart->guest_shipping_address ?? $cart->guest_payment_address; + if(!$address) return []; $countryId = $address['country_id']; // 获取全部物流 返回第一个物流信息ID $logisticsList = Logistics::getAll($countryId,['type','first_weight','first_weight_fee','continuation_weight_max','add_weight','continuation_weight_fee','num_fee']); diff --git a/beike/Shop/Services/TotalServices/SumQuantityService.php b/beike/Shop/Services/TotalServices/SumQuantityService.php new file mode 100644 index 00000000..f5b7405a --- /dev/null +++ b/beike/Shop/Services/TotalServices/SumQuantityService.php @@ -0,0 +1,22 @@ +totalService; + $sumQuantity = $totalService->countProducts(); + $totalData = [ + 'code' => 'sum_quantity', + 'title' => trans('admin/dashboard.product_total'), + 'amount' => $sumQuantity, + 'amount_format' => $sumQuantity, + ]; + $totalService->totals[] = $totalData; + + return $totalData; + } +} diff --git a/plugins/FlatShipping/Bootstrap.php b/plugins/FlatShipping/Bootstrap.php index 21c5371b..235b1c80 100644 --- a/plugins/FlatShipping/Bootstrap.php +++ b/plugins/FlatShipping/Bootstrap.php @@ -53,13 +53,13 @@ class Bootstrap $amount = $totalService->amount; $shippingType = plugin_setting('flat_shipping.type', 'fixed'); $shippingValue = plugin_setting('flat_shipping.value', 0); - if ($shippingType == 'fixed') { - return $shippingValue; - } elseif ($shippingType == 'percent') { - return $amount * $shippingValue / 100; + $sumQuantity = $totalService->countProducts(); + if($sumQuantity > 0){ + if ($shippingType == 'fixed') return $shippingValue; + elseif ($shippingType == 'percent') return $amount * $shippingValue / 100; } - return 0; + return 0; } } diff --git a/themes/default/product/product.blade.php b/themes/default/product/product.blade.php index 72b48520..112db3c8 100644 --- a/themes/default/product/product.blade.php +++ b/themes/default/product/product.blade.php @@ -239,7 +239,12 @@ {{-- 购买数量 - 单规格 --}}