¨4.0.1¨

This commit is contained in:
¨NW¨
2023-12-03 14:07:47 +00:00
parent c08b36d1b6
commit f35052522d
1112 changed files with 43019 additions and 24987 deletions

View File

@@ -11,6 +11,7 @@ class CartCoupon implements JsonSerializable
private $coupon;
private $couponCondition;
public function __construct($cart, $coupon, $couponCondition)
{
$this->cart = $cart;
@@ -18,74 +19,111 @@ class CartCoupon implements JsonSerializable
$this->couponCondition = $couponCondition;
}
public function entity()
{
return $this->coupon;
}
public function id()
{
return $this->coupon->id;
}
public function code()
{
return $this->coupon->code;
}
public function isFreeShipping()
{
return $this->coupon->free_shipping;
}
public function usageLimitReached($customerEmail)
{
return $this->fresh()->coupon->usageLimitReached($customerEmail);
}
public function didNotSpendTheRequiredAmount()
{
return $this->fresh()->coupon->didNotSpendTheRequiredAmount();
}
public function spentMoreThanMaximumAmount()
{
return $this->fresh()->coupon->spentMoreThanMaximumAmount();
}
public function fresh()
public function fresh(): static
{
$this->coupon = $this->coupon->refresh();
return $this;
}
public function didNotSpendTheRequiredAmount()
{
return $this->fresh()->coupon->didNotSpendTheRequiredAmount();
}
public function spentMoreThanMaximumAmount()
{
return $this->fresh()->coupon->spentMoreThanMaximumAmount();
}
public function usedOnce()
{
$this->coupon->increment('used');
}
public function __toString()
{
return json_encode($this->jsonSerialize());
}
public function jsonSerialize()
{
return $this->toArray();
}
public function toArray(): array
{
return [
'code' => $this->code(),
'value' => $this->value(),
'free_shipping' => $this->coupon->free_shipping,
];
}
public function code()
{
return $this->coupon->code;
}
public function value()
{
if ($this->coupon->free_shipping) {
return $this->cart->shippingMethod()->cost();
}
return Money::inDefaultCurrency($this->calculate());
}
private function calculate()
public function __get($attribute)
{
return $this->couponCondition->getCalculatedValue($this->productsTotalPrice());
return $this->coupon->{$attribute};
}
private function productsTotalPrice()
private function calculate()
{
return $this->couponCondition->getCalculatedValue($this->couponApplicableProductsTotalPrice());
}
private function couponApplicableProductsTotalPrice()
{
return $this->couponApplicableProducts()->sum(function ($cartItem) {
return $cartItem->total()->amount();
return $cartItem->totalPrice()->amount();
});
}
private function couponApplicableProducts()
{
return $this->cart->items()->filter(function ($cartItem) {
@@ -99,6 +137,7 @@ class CartCoupon implements JsonSerializable
});
}
private function inApplicableProducts($cartItem)
{
if ($this->coupon->products->isEmpty()) {
@@ -108,6 +147,7 @@ class CartCoupon implements JsonSerializable
return $this->coupon->products->contains($cartItem->product);
}
private function inExcludedProducts($cartItem)
{
if ($this->coupon->excludeProducts->isEmpty()) {
@@ -117,6 +157,7 @@ class CartCoupon implements JsonSerializable
return $this->coupon->excludeProducts->contains($cartItem->product);
}
private function inApplicableCategories($cartItem)
{
if ($this->coupon->categories->isEmpty()) {
@@ -126,6 +167,7 @@ class CartCoupon implements JsonSerializable
return $this->coupon->categories->intersect($cartItem->product->categories)->isNotEmpty();
}
private function inExcludedCategories($cartItem)
{
if ($this->coupon->excludeCategories->isEmpty()) {
@@ -134,27 +176,4 @@ class CartCoupon implements JsonSerializable
return $this->coupon->excludeCategories->intersect($cartItem->product->categories)->isNotEmpty();
}
public function toArray()
{
return [
'code' => $this->code(),
'value' => $this->value(),
];
}
public function jsonSerialize()
{
return $this->toArray();
}
public function __toString()
{
return json_encode($this->jsonSerialize());
}
public function __get($attribute)
{
return $this->coupon->{$attribute};
}
}