Docs / Laravel Cart / First-class Objects

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);
Discovery Call

One call.
We'll both know.

20 minutes to walk through your project, ask the hard questions, and work out honestly if we're the right team for it.

  • One call per day - it gets our full attention
  • Australia's only Laravel Premier Partner
  • Senior engineers only - no juniors on your project
  • Brisbane-based, onshore team

Press Esc to close  ·  B to reopen