I'm looking for a way to offer "3 for 2 / 2 for 1" type options with Commerce.

I've been able to achieve this just by adding a default value to a coupon code input.

It works, kinda. If we need to stick with that then we'd be satisfied but where it fails is; say I have 6 items in the cart, I only get the offer on the first 3.

This is a small store with just a handful of items for sale so not a deal breaker but I can imagine other larger stores doing similar.

Adjusters have been mentioned on Twitter but unsure how to follow that through.


2 Answers 2


The documentation for adjusters is here:

https://craftcommerce.com/docs/adjusters and https://craftcommerce.com/docs/order-adjustment-model

Essentially your plugin creates a class that fulfils the interface at: plugins/commerce/Commerce/Adjusters/Commerce_AdjusterInterface.php - which is very simple:

interface Commerce_AdjusterInterface
     * The adjust method modifies the order values (like baseShippingCost),
     * and records all adjustments by returning one or more orderAdjusterModels
     * to be saved on the order.
     * @param Commerce_OrderModel $order
     * @param array $lineItems
     * @return \Craft\Commerce_OrderAdjustmentModel[]
    public function adjust(Commerce_OrderModel &$order, array $lineItems = []);

Your plugin (in your main plugin .php file) then just registers your new adjuster to hook it up. I'd suggest storing your actual adjuster classes in files in an Adjusters folder, lime Commerce itself does.

//at the top, to include your class


//this registers the adjuster with Commerce so it will be applied to carts
public function commerce_registerOrderAdjusters(){
  return [
    new \Commerce\Adjusters\BusinessLogic_TaxRemover

The adjuster (as you can see) has access to the order and line items and you can basically use any code you like to implement your discount offer, e.g. checking if the qty of something is over 3, and then reducing the price. It builds & returns Commerce_OrderAdjustmentModels which describe the adjustment(s) made by the adjuster.

Here's a super simple example adjuster:


namespace Commerce\Adjusters;
use Craft\Commerce_LineItemModel;
use Craft\Commerce_OrderAdjustmentModel;
use Craft\Commerce_OrderModel;

class BusinessLogic_TaxRemover implements Commerce_AdjusterInterface {

 public function adjust(Commerce_OrderModel &$order, array $lineItems = []){

    $myAdjuster = new Commerce_OrderAdjustmentModel();

    $order->baseDiscount = $order->baseDiscount - 5;

    $myAdjuster->type = "Test";
    $myAdjuster->name = "Test Adjuster";
    $myAdjuster->description = "Takes $5 off the order";
    $myAdjuster->amount = -5.0;
    $myAdjuster->orderId = $order->id;
    //if your Adjuster affects lineItems rather than the total, you record the ids here
    $myAdjuster->optionsJson = ['lineItemsAffected'=>null];
    $myAdjuster->included = false;

    return [$myAdjuster];



My advice is to being it to generate plugin scaffolding using: http://pluginfactory.io/ - to get you started - removes a lot of the pain points in getting started (such as the cursed capitilisation issues which I swear are the hardest part about getting started with plugins!).

Alternatively, you can take the scaffolding from https://github.com/lindseydiloreto/craft-businesslogic - and put in there, which makes good sense as this pretty much the textbook definition of business logic. Just clone that, add your adjuster class, and do the registration and away you go!

As long as you're comfortable with PHP implementing a discounter like you describe is really quite simple. If you're not then it's a perfect way to get more comfortable and I'm sure folks will be happy to help along the way!

  • I guess it's time to start getting my hands dirty with plugins. I'm a front-end guy and writing plugins scares me :) Mar 14, 2016 at 10:27
  • 1
    Find us on Slack if you need help as you go. You'll get there! :) Mar 14, 2016 at 11:04
  • Nice Answer. Craft Commerce is pretty new too, I'd imagine they'll be some handy plugins with nice UIs for this sort of thing to make of the pain easier ;) Mar 15, 2016 at 3:57
  • @StevenGrant Perhaps accept this answer? Although I agree with the above, likely a good discounts plugin is in Commerce's future, for now you'd have to do it like this. Mar 16, 2016 at 1:17

Best way to collate this sort of feedback or request is here, Steven: http://feedback.craftcms.com/forums/285221-feature-requests

Let us know where you add it, so we can back it too...

Hope it helps

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.