Skip to content

Commit b1b8686

Browse files
committed
wip
1 parent 43b86c1 commit b1b8686

5 files changed

Lines changed: 31 additions & 2 deletions

File tree

src/Interfaces/Checkoutable.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,4 +133,14 @@ public function removeCoupon(string|Coupon $coupon): void;
133133
* Get the applicable discount rules.
134134
*/
135135
public function getApplicableDiscountRules(): Collection;
136+
137+
/**
138+
* Get the discount total.
139+
*/
140+
public function getDiscountTotal(): float;
141+
142+
/**
143+
* Get the formatted discount total.
144+
*/
145+
public function getFormattedDiscountTotal(): string;
136146
}

src/Models/Cart.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,7 @@ public function toOrder(): Order
209209
$this->order->applyCoupon($coupon);
210210
});
211211

212+
$this->order->calculateDiscount();
212213
$this->order->calculateTax();
213214
});
214215
} catch (Throwable $exception) {

src/Models/Item.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ public function getFormattedGrossPrice(): string
246246
*/
247247
public function getTotal(): float
248248
{
249-
return $this->getGrossPrice() * $this->getQuantity();
249+
return ($this->getGrossPrice() * $this->getQuantity()) - $this->getDiscount();
250250
}
251251

252252
/**

src/Models/Shipping.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ public function getFormattedGrossPrice(): string
248248
*/
249249
public function getTotal(): float
250250
{
251-
return $this->getGrossPrice() * $this->getQuantity();
251+
return ($this->getGrossPrice() * $this->getQuantity()) - $this->getDiscount();
252252
}
253253

254254
/**

src/Traits/AsOrder.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,16 @@ public function getDiscount(): float
449449
{
450450
$value = $this->__getDiscount();
451451
$value += $this->coupons->sum('coupon.value');
452+
453+
return $value;
454+
}
455+
456+
/**
457+
* Get the discount total.
458+
*/
459+
public function getDiscountTotal(): float
460+
{
461+
$value = $this->getDiscount();
452462
$value += ($this->needsShipping() ? $this->shipping->getDiscount() : 0);
453463
$value += $this->items->sum(static function (Item $item): float {
454464
return $item->getDiscount();
@@ -457,6 +467,14 @@ public function getDiscount(): float
457467
return $value;
458468
}
459469

470+
/**
471+
* Get the formatted discount total.
472+
*/
473+
public function getFormattedDiscountTotal(): string
474+
{
475+
return $this->getCurrency()->format($this->getDiscountTotal());
476+
}
477+
460478
/**
461479
* Get the discountable currency.
462480
*/

0 commit comments

Comments
 (0)