First-class Objects
Instead of building raw CartCondition arrays, you can extend the provided base classes.
Coupon
namespace App\Cart\Coupons;
use Wearepixel\Cart\Coupons\Coupon;
class TenPercentOff extends Coupon
{
protected string $code = 'SAVE10';
protected string $value = '-10%';
protected string $target = 'subtotal';
public function isValid(): bool
{
return true; // add your own validation logic
}
}
// Apply to the cart
Cart::coupon(new TenPercentOff);
TaxRule
namespace App\Cart\Tax;
use Wearepixel\Cart\Tax\TaxRule;
class GstTaxRule extends TaxRule
{
protected string $name = 'GST';
protected string $value = '10%';
protected string $target = 'subtotal';
public function isApplicable(): bool
{
return true;
}
}
Cart::tax(new GstTaxRule);
ShippingRate
namespace App\Cart\Shipping;
use Wearepixel\Cart\Shipping\ShippingRate;
class FlatRateShipping extends ShippingRate
{
protected string $name = 'Standard Shipping';
protected string $value = '+10';
protected string $target = 'total';
public function isApplicable(): bool
{
return true;
}
}
Cart::shipping(new FlatRateShipping);