From 9bec24b2cb85132e0b852e150336f9e2ff870492 Mon Sep 17 00:00:00 2001 From: Edward Yang Date: Mon, 5 Dec 2022 18:46:27 +0800 Subject: [PATCH] =?UTF-8?q?=E8=8E=B7=E5=8F=96=E5=BD=93=E5=89=8D=E8=B4=A7?= =?UTF-8?q?=E5=B8=81ID?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- beike/Helpers.php | 12 ++++++++++++ beike/Shop/Services/CheckoutService.php | 16 ++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/beike/Helpers.php b/beike/Helpers.php index edefacbc..7f21bbe8 100644 --- a/beike/Helpers.php +++ b/beike/Helpers.php @@ -456,6 +456,18 @@ function current_currency_code(): string return Session::get('currency') ?? system_setting('base.currency'); } +/** + * 获取当前货币 + * + * @return string + */ +function current_currency_id(): string +{ + $currencyCode = current_currency_code(); + $currency = \Beike\Models\Currency::query()->where('code', $currencyCode)->first(); + return $currency->id ?? 0; +} + /** * 数量格式化, 用于商品、订单统计 * diff --git a/beike/Shop/Services/CheckoutService.php b/beike/Shop/Services/CheckoutService.php index a3537592..84a61505 100644 --- a/beike/Shop/Services/CheckoutService.php +++ b/beike/Shop/Services/CheckoutService.php @@ -108,6 +108,22 @@ class CheckoutService } + /** + * 计算当前选中商品总重量 + * @todo + * @return int + */ + public function getCartWeight(): int + { + $weight = 0; + $selectedProducts = $this->selectedProducts; + foreach ($selectedProducts as $product) { + $weight += $this->weight->convert($product['weight'], $product['weight_class_id'], $this->config->get('config_weight_class_id')); + } + return $weight; + } + + /** * @throws \Exception */