feat: add Cart::coupon(), Cart::tax(), Cart::shipping()

Proxy methods that accept first-class Coupon, TaxRule, and ShippingRate
objects and delegate to Cart::condition() via toCondition().
This commit is contained in:
Joel Male
2026-05-27 21:27:23 +10:00
parent 2513e07436
commit c3a734bd7f
2 changed files with 118 additions and 0 deletions
+18
View File
@@ -5,7 +5,10 @@
namespace Wearepixel\Cart;
use Closure;
use Wearepixel\Cart\Coupons\Coupon;
use Wearepixel\Cart\Helpers\Helpers;
use Wearepixel\Cart\Shipping\ShippingRate;
use Wearepixel\Cart\Tax\TaxRule;
use Wearepixel\Cart\Validators\CartItemValidator;
use Wearepixel\Cart\Exceptions\InvalidItemException;
use Wearepixel\Cart\Exceptions\UnknownModelException;
@@ -276,6 +279,21 @@ public function condition(array|CartCondition $condition): self
return $this;
}
public function coupon(Coupon $coupon): self
{
return $this->condition($coupon->toCondition());
}
public function tax(TaxRule $taxRule): self
{
return $this->condition($taxRule->toCondition());
}
public function shipping(ShippingRate $shippingRate): self
{
return $this->condition($shippingRate->toCondition());
}
public function getConditions(bool $array = false, bool $active = false): CartConditionCollection|array
{
$conditions = new CartConditionCollection($this->driver->getConditions());