2

I know that I can apply a discount if a specific number of products is ordered. I could also add a discount for a specific product, with a specific amount. But, am I able to create a discount with this conditions:

  • Applies to entire product type
  • A specific number of one product is added to the cart

So, if I set this discount for 3 products, but people buy 2 x PRODUCT A, 1 x PRODUCT B, it would not apply. If customers buy 3 x PRODUCT A, 2 x PRODUCT B, it would apply for product A.

I could probably fix it with a plugin, but is it possible out of the box? Am I missing something?

1

As far as the release notes from Commerce 1.2: https://craftcommerce.com/changelog#build1323

It can only be given a minimum quantity of items now.

| improve this answer | |
  • If i look into your question, i would create a discount coupon -> Conditions -> Add Products select Product A -> Minimum Purchase Quantity and Maximum Purchase Quantity set to 3 that would solve it. If it works please upvote it. – Bram B Oct 12 '16 at 12:27
1

You can achieve this with a custom adjuster. Please refer the code snippet below.

Create a new adjuster and apply your logic here

// check each line item
foreach($lineItems as $lineItem)
{
....
<your business logic here
....
$discount_total = <amount>;
}

$order->baseDiscount = $order->baseDiscount - $discount_total;

$myAdjuster->type = "Custom discount";
$myAdjuster->name = "Group discount";
$myAdjuster->description = "Total of discount";
$myAdjuster->amount = -$discount_total;
$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];
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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