|
@@ -171,6 +171,14 @@ class CartData
|
|
|
#[ApiProperty(description: 'Total quantity of all items')]
|
|
#[ApiProperty(description: 'Total quantity of all items')]
|
|
|
public ?int $itemsQty = null;
|
|
public ?int $itemsQty = null;
|
|
|
|
|
|
|
|
|
|
+ #[Groups(['query', 'mutation'])]
|
|
|
|
|
+ #[ApiProperty(description: "Customer's current reward points balance")]
|
|
|
|
|
+ public int $rewardPoints = 0;
|
|
|
|
|
+
|
|
|
|
|
+ #[Groups(['query', 'mutation'])]
|
|
|
|
|
+ #[ApiProperty(description: 'Reward points that can be earned from the current cart')]
|
|
|
|
|
+ public int $earnableRewardPoints = 0;
|
|
|
|
|
+
|
|
|
#[Groups(['query', 'mutation'])]
|
|
#[Groups(['query', 'mutation'])]
|
|
|
#[ApiProperty(description: 'Subtotal including tax')]
|
|
#[ApiProperty(description: 'Subtotal including tax')]
|
|
|
public ?float $subTotalInclTax = null;
|
|
public ?float $subTotalInclTax = null;
|
|
@@ -402,6 +410,39 @@ class CartData
|
|
|
$data->selectedShippingRateTitle = null;
|
|
$data->selectedShippingRateTitle = null;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ // 积分信息:用户当前积分 + 当前购物车可获得积分
|
|
|
|
|
+ $data->rewardPoints = 0;
|
|
|
|
|
+ $data->earnableRewardPoints = 0;
|
|
|
|
|
+
|
|
|
|
|
+ if ($cart->customer_id) {
|
|
|
|
|
+ try {
|
|
|
|
|
+ $rewardPointRepository = app(\Longyi\RewardPoints\Repositories\RewardPointRepository::class);
|
|
|
|
|
+
|
|
|
|
|
+ // 用户当前积分
|
|
|
|
|
+ $data->rewardPoints = (int) $rewardPointRepository->getCustomerPoints($cart->customer_id);
|
|
|
|
|
+
|
|
|
|
|
+ // 当前购物车可获得积分(复用订单积分计算逻辑)
|
|
|
|
|
+ $rule = \Longyi\RewardPoints\Models\RewardActiveRule::active()
|
|
|
|
|
+ ->ofType(\Longyi\RewardPoints\Models\RewardActiveRule::TYPE_ORDER)
|
|
|
|
|
+ ->first();
|
|
|
|
|
+
|
|
|
|
|
+ if ($rule) {
|
|
|
|
|
+ $customer = \Webkul\Customer\Models\Customer::find($cart->customer_id);
|
|
|
|
|
+
|
|
|
|
|
+ if ($customer && $rule->isApplicableToCustomer($customer)) {
|
|
|
|
|
+ $pointsPerCurrency = $rule->getPointsForCustomer($customer);
|
|
|
|
|
+
|
|
|
|
|
+ if ($pointsPerCurrency > 0) {
|
|
|
|
|
+ $data->earnableRewardPoints = (int) floor(($cart->base_grand_total ?? 0) * $pointsPerCurrency);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch (\Throwable $e) {
|
|
|
|
|
+ // 积分计算失败不阻塞购物车接口
|
|
|
|
|
+ report($e);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
return $data;
|
|
return $data;
|
|
|
}
|
|
}
|
|
|
|
|
|