5 votes

Check if cart contains valid products for discount code

Try something like this: {% set currentDiscount = craft.commerce.getDiscountByCode(cart.couponCode) %} {% if currentDiscount %} {% set cartProductIds = [] %} {% for item in cart.lineItems %} {% ...
user avatar
  • 6,682
3 votes
Accepted

how to round Discounts (either half of full number) or total of cart

Are you using a custom adjuster for the discount? If yes, then just use round() to round up. ... $num = $adjustment->amount; // 12.48 $adjustment->amount = round($num, 1, PHP_ROUND_HALF_UP); // ...
user avatar
  • 156
3 votes
Accepted

Discount Code applies to cart successfully but doesn't do anything. Am I missing something?

The reason for the discount not being applied is that nearly all your products have not been marked as promotable (by looking at your database): Screenshot: http://jmp.sh/3FAK6NH No sales or ...
user avatar
  • 6,682
2 votes

Check if there is a discount and, is yes, how much

Something like this? {% if item.discount %} <tr> <td>Your discount is {{ item.discount|commerceCurrency( currency ) }}</td> </tr> {% endif %}
user avatar
2 votes
Accepted

List applied discounts that have codes

(There can be only one code on a cart at any one time) Here's some example code that does the sort of thing you want: {% if cart.couponCode %} {% set coupon = craft.commerce.getDiscountByCode(...
user avatar
2 votes

View all discounts applied to a cart and remove discounts from cart

You've sort of answered your own question - Commerce only allows one coupon on a cart at any time (currently). To determine if a coupon is set, and print the code, it's basically: {% if cart....
user avatar
2 votes
Accepted

Payment Method and Discount elements query by ID in Twig

Commerce 1: {% set paymentMethod = null %} {% for pm in craft.commerce.paymentMethods %} {% if pm.id == 2 %}{% set paymentMethod = pm %}{% endif %} {% endfor %} {{ paymentMethod.name }} ...
user avatar
  • 6,682
2 votes
Accepted

Commerce: Is there any way to give a discount for Product A if the costumer buy 3 Product B?

We will need to uncomment this line to allow |filter used in condition formulas: https://github.com/craftcms/commerce/blob/develop/src/services/Formulas.php#L198 If you do that manually yourself this ...
user avatar
  • 6,682
2 votes

Applying coupon codes via URL

The following code can be used in the init method of a custom module. Event::on( View::class, View::EVENT_BEFORE_RENDER_PAGE_TEMPLATE, function($event) { // Check query string for ...
user avatar
1 vote
Accepted

Craft Commerce: discount taxation

Got to bottom of this - is down to how the Tax Rules are set-up. Taxable Subject was set to Line Item but should have been set to Order Total.
user avatar
  • 1,731
1 vote
Accepted

Commerce 1 find if Discount object is valid based on start/end dates (Twig)

In Commerce 1, craft.commerce.discounts will return an array of Commerce_DiscountModel objects of all available discounts. public function getAllDiscounts($criteria = []) { $records = ...
user avatar
  • 66.5k
1 vote

Applying several discounts for amount range (> 100$ -> 5%, > 200$ -> 10%)

The Commerce GUI doesn't let you set a whole cart discount but you can do it as an adjuster in a module/plugin. Setup the scaffolding for a module at pluginfactory then add a folder inside called the ...
user avatar
  • 6,477
1 vote

Applying several discounts for amount range (> 100$ -> 5%, > 200$ -> 10%)

Found the answer: in both discounts "Don’t apply any subsequent discounts to an order if this discount is applied" has to be active. and the discount with the higher value (in my case > ...
user avatar
  • 319
1 vote

Commerce Discount: spend $X, get product free

I don't think avoiding an adjuster or plugin approach here really gains you anything much and it probably creates potential issues - it will likely just make the discount rules confusing as you can't ...
user avatar
1 vote
Accepted

Show all discounts at checkout with Craft Commerce

Hmm, something else is at play here. I use: {% if cart.totalDiscount != 0 or cart.couponCode %} - {{ cart.totalDiscount | currency(cart.currency) }} ...and it works. Are you sure the promotion ...
user avatar
1 vote

How to apply a discount on cart weight ?

It would probably be best to make your own shipping adjuster. I have attached an example plugin here: http://jmp.sh/wC95ZPj The adjuster plugin I have linked can look at the weight of the cart, it's ...
user avatar
  • 6,682
1 vote

Check if there is a discount and, is yes, how much

For some reason the {% if item.discount %} isn't working for me. I've solved it by comparing the item.discount value. If not 0.0000 then it may show up {% if item.discount != '0.0000' %} {{"...
user avatar
  • 113
1 vote

Error trapping on discount codes based on Cart contents

So this is for coupons? If a coupon can't be applied during an updateCart, you'll get back the rather unhelpful response in JSON of {"error":"Cart not completely updated."} We intercept this, and ...
user avatar
1 vote

In Commerce, can I apply a discount only on a specific number of one product?

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) { .... <...
user avatar
1 vote
Accepted

In Commerce, can I apply a discount only on a specific number of one product?

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.
user avatar
  • 353
1 vote

Check if cart contains valid products for discount code

I have now updated this code for Craft Commerce 2: {% set codeError = null %} {% set cartProductIds = [] %} {% set discountCodeOK = null %} {# THIS CHECKS THE DISCOUNT CODE FOR IF THERE ARE ANY VALID/...
user avatar
  • 1,834
1 vote

Check if cart contains valid products for discount code

So some persistence I have this working as follows: {% set currentDiscount = craft.commerce.getDiscountByCode(cart.couponCode) %} {% if currentDiscount %} {% set cartProductIds = [] %} {% ...
user avatar
  • 1,834

Only top scored, non community-wiki answers of a minimum length are eligible