重构结账页total计算
This commit is contained in:
parent
55423be548
commit
fc496aa4dd
|
|
@ -191,7 +191,7 @@ class CheckoutService
|
|||
'shipping_methods' => $shipments,
|
||||
'payment_methods' => $payments,
|
||||
'carts' => $carts,
|
||||
'totals' => $totalService->getTotals(),
|
||||
'totals' => $totalService->getTotals($this),
|
||||
];
|
||||
|
||||
return hook_filter('checkout.data', $data);
|
||||
|
|
|
|||
|
|
@ -83,9 +83,10 @@ class TotalService
|
|||
|
||||
|
||||
/**
|
||||
* @param CheckoutService $checkout
|
||||
* @return array
|
||||
*/
|
||||
public function getTotals(): array
|
||||
public function getTotals(CheckoutService $checkout): array
|
||||
{
|
||||
foreach (self::TOTAL_CODES as $code) {
|
||||
$serviceName = Str::studly($code) . 'Service';
|
||||
|
|
@ -93,7 +94,7 @@ class TotalService
|
|||
if (!class_exists($service) || !method_exists($service, 'getTotal')) {
|
||||
continue;
|
||||
}
|
||||
$service::getTotal($this);
|
||||
$service::getTotal($checkout);
|
||||
}
|
||||
|
||||
return $this->totals;
|
||||
|
|
|
|||
|
|
@ -11,12 +11,17 @@
|
|||
|
||||
namespace Beike\Shop\Services\TotalServices;
|
||||
|
||||
use Beike\Shop\Services\TotalService;
|
||||
use Beike\Shop\Services\CheckoutService;
|
||||
|
||||
class OrderTotalService
|
||||
{
|
||||
public static function getTotal(TotalService $totalService)
|
||||
/**
|
||||
* @param CheckoutService $checkout
|
||||
* @return array
|
||||
*/
|
||||
public static function getTotal(CheckoutService $checkout)
|
||||
{
|
||||
$totalService = $checkout->totalService;
|
||||
$amount = $totalService->amount;
|
||||
$totalData = [
|
||||
'code' => 'order_total',
|
||||
|
|
|
|||
|
|
@ -12,18 +12,19 @@
|
|||
|
||||
namespace Beike\Shop\Services\TotalServices;
|
||||
|
||||
use Beike\Shop\Services\TotalService;
|
||||
use Illuminate\Support\Str;
|
||||
use Beike\Shop\Services\CheckoutService;
|
||||
|
||||
class ShippingService
|
||||
{
|
||||
/**
|
||||
* @param TotalService $totalService
|
||||
* @param CheckoutService $checkout
|
||||
* @return array|null
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function getTotal(TotalService $totalService): ?array
|
||||
public static function getTotal(CheckoutService $checkout): ?array
|
||||
{
|
||||
$totalService = $checkout->totalService;
|
||||
$shippingMethod = $totalService->shippingMethod;
|
||||
if (empty($shippingMethod)) {
|
||||
return null;
|
||||
|
|
|
|||
|
|
@ -13,11 +13,17 @@
|
|||
namespace Beike\Shop\Services\TotalServices;
|
||||
|
||||
use Beike\Shop\Services\TotalService;
|
||||
use Beike\Shop\Services\CheckoutService;
|
||||
|
||||
class SubtotalService
|
||||
{
|
||||
public static function getTotal(TotalService $totalService)
|
||||
/**
|
||||
* @param CheckoutService $checkout
|
||||
* @return array
|
||||
*/
|
||||
public static function getTotal(CheckoutService $checkout)
|
||||
{
|
||||
$totalService = $checkout->totalService;
|
||||
$amount = self::getAmount($totalService);
|
||||
$totalData = [
|
||||
'code' => 'sub_total',
|
||||
|
|
|
|||
|
|
@ -12,13 +12,18 @@
|
|||
|
||||
namespace Beike\Shop\Services\TotalServices;
|
||||
|
||||
use Beike\Shop\Services\CheckoutService;
|
||||
use Beike\Admin\Repositories\TaxRateRepo;
|
||||
use Beike\Shop\Services\TotalService;
|
||||
|
||||
class TaxService
|
||||
{
|
||||
public static function getTotal(TotalService $totalService): ?array
|
||||
/**
|
||||
* @param CheckoutService $checkout
|
||||
* @return array|null
|
||||
*/
|
||||
public static function getTotal(CheckoutService $checkout): ?array
|
||||
{
|
||||
$totalService = $checkout->totalService;
|
||||
$taxEnabled = system_setting('base.tax', false);
|
||||
if (!$taxEnabled) {
|
||||
return null;
|
||||
|
|
|
|||
Loading…
Reference in New Issue