When I apply a $25 coupon to a $10 order, I end up with a negative total. Checkout doesn't know how to handle that gracefully. Any ideas on how this can be solved?

Thanks,
Tal

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

googletorp’s picture

Category: support » bug

I've seen this as well, but would call this a bug, since this can break a lot of things, like payment methods.

jlyon’s picture

I have also noticed this, and received errors when I tried to checkout with a negative total price. Could this be fixed with a Product Pricing Rule?

ikos’s picture

Have you tried adding an action to the redeem coupon rule that sets the order total to 0 if it's a negative number?

googletorp’s picture

#3 that wouldn't work as the order total is updated every time the order is saved.

valante’s picture

Is there any way to do the following:

- Whenever an order is updated, calculate the total (sans the coupon)
- Check the coupon's real worth
- Edit the coupon line item:
--- Apply the lower of the two: the coupon's real worth or the order total

Of course, this works for only one coupon for order, but it can be expanded to multiple coupons easily enough.

How about it?

googletorp’s picture

#5 Possible yes, but it requires some code and hooks, don't think rules will be enough.

bradhawkins’s picture

I've was able to use rules as a workaround. Definitely a hack, but seems to be working until someone comes up with a better approach.


{ "rules_zero_out_negative_balance" : {
    "LABEL" : "Zero out Negative balance",
    "PLUGIN" : "reaction rule",
    "REQUIRES" : [ "commerce_payment", "rules", "entity" ],
    "ON" : [ "commerce_order_presave" ],
    "IF" : [
      { "commerce_payment_order_balance_comparison" : {
          "commerce_order" : [ "commerce_order" ],
          "operator" : "\u003c",
          "value" : "0"
        }
      }
    ],
    "DO" : [
      { "data_set" : {
          "data" : [ "commerce-order:commerce-order-total" ],
          "value" : { "value" : { "amount" : "0", "currency_code" : "USD" } }
        }
      }
    ]
  }
}
geek-merlin’s picture

i think if we have a coupon product, we can set up a rule that purchases a new coupon with the exceeding value...

geek-merlin’s picture

i got a rule working that sets $coupon_line_item=min($coupon_value,$order_value)

what is NOT YET working is: to have the redeemed value subtracted...

husumiao-1’s picture

This is really crazy. Nobody got fixed this bugs?
Any solutions is worked? Like:
1. Just directly set the order total to 0 if it's negative(This is better if it's worked)?
2. Reset the coupon amount, amount = -(product total price + shipping + ....)?
3. Add new line item to the order, amount = (coupon amount + product total price + shipping + ....)?

Actually i tested the rule look likes doesn't work..

pcambra’s picture

This is really crazy. Nobody got fixed this bugs?

Patches are very welcome.

pcambra’s picture

Version: 7.x-1.0-beta3 » 7.x-1.x-dev
Category: bug » feature

I'm calling this feature request.

Let's workaround what's the expected behavior here, I'd say that we could provide a rule on validation coupon that doesn't allow you to redeem any coupon if the total would negative.

Any extra opinions?

valante’s picture

I think it's quite unfair to users who have a $5 coupon and want to check out a $4.99 order, actually.

Ideally, a fixed amount coupon should function like this:

- Offer the site manager an option whether to reserve any credit or not.
- On checkout, only apply the maximum order total from the coupon.
- If coupon is reserving credit, it should have the difference available for the next use. (Like a pre-loaded credit card.)
- If not, the coupon should be regarded as fully used.

That probably requires quite a re-make of the module, though . . .

pcambra’s picture

I'd say the request in #13 is really really specific, I'd say that's material for a new coupon submodule (like the pct or the amount) that takes care of coupons as "credits".

That probably requires quite a re-make of the module, though . . .

I've just done that, btw.

valante’s picture

I've just done that, btw.

I know. I'm following. :)

I think the entire negative sum issue is very specific to fixed-amount coupons, and the credits issue belongs there. You can't get a negative sum with any other kind of coupon that I can think of. Whether or not the user gets to keep the remaining balance of the coupon should be up to the site manager.

I see two options here:

- Create an option in the fixed amount coupon module that allows the site manager to determine how to treat "credits"
- Create two sub-modules: one for fixed amount coupons with no credits, the other for fixed amount coupons with credits.

The first approach seems more complete, but the second one might be easier to implement, so . . .

Thanks for all your hard work on this module!

pcambra’s picture

Project: Commerce Coupon » Commerce coupon fixed amount

Moving this to the fixed amount queue, let's keep the discussion there, whereas I like the credits idea, I think it shouldn't be the default one.

mrfelton’s picture

How about:

  • An option on the fixed price coupon type to 'Allow negative balance'. (boolean field?)
  • Default it to off, since the majority of times it probably makes no sense to allow negative balances.
  • If negative balances are not allowed (default case), then zero the balance once it gets below 0 - could probably be handled very easily in Rules.

If people want to allow negative balances, and want to something specific with the credit, then that probably belongs in some other module or submodule.

Is really a feature request? Seems more like a bug to me that we are letting order get a negative balance, when there is nothing in place to handle negative balances, and it just breaks the order process.

Let's workaround what's the expected behavior here, I'd say that we could provide a rule on validation coupon that doesn't allow you to redeem any coupon if the total would negative.

I don't think disallowing use of the coupon is very clever. If I walked into your store with a £10 gift voucher, and wanted to buy something that cost £9.50, would you turn me away?!

pcambra’s picture

Is really a feature request? Seems more like a bug to me that we are letting order get a negative balance, when there is nothing in place to handle negative balances, and it just breaks the order process.

Then I'm not getting what's the point of allowing negative balances as a setting of the coupon type.

I don't think disallowing use of the coupon is very clever. If I walked into your store with a £10 gift voucher, and wanted to buy something that cost £9.50, would you turn me away?!

This would mean that you're redeeming 9.50 out of 10 and it will introduce a big feature handling on refunds.
IMHO refusing to redeem coupons with an amount bigger than the order total is a good default.

As I think this module and coupon itself, it should only contain default settings and behaviors, you can actually do whatever you want with rules and hooks for coupons, even handling the negative total issue.

ponies’s picture

Refunds are a big deal. Perhaps a new coupon could be generated for the remainder.

I am unable to check out with a negative balance though. This issue takes the commerce out of drupal commerce when it comes up.

kevinquillen’s picture

The weird part is, as stated above, if a user has a $5 coupon and a $4.99 order, you can get a negative total, which means two things:

  1. A coupon can only be redeemable once even if the order total is lower than the coupon, without making the price go negative- OR:
  2. You have to generate a new coupon for the difference and assign it back to the user, and email them the code.

#2 above is more 'normal' as far as maintaining a credited balance which is basically what I am using or want to use coupons for. I want people to be able to generate a coupon and assign it to a user in certain situations (such as a rainout- this is an event registration system) which is a voucher for the full amount they paid in the first place, to use on a future registration.

torgosPizza’s picture

My two cents: #1 as described in #20 is more the 'usual' option for coupons. Physical coupons in stores always say, "Valid for one widget of equal or lesser value.." in other words, you can only apply the coupon in an amount up to, but not exceeding, the item cost. In the case of the coupon equaling the total amount available, the coupon should be considered "redeemed" while making the order total $0.

I, too, have a need for a "credits" system similar to gift certificates. I think an additional submodule would suffice in which Coupons act as credits; if there is a balance left over after redemption (say you only apply $5 of a $10 coupon) either the Coupon balance is adjusted, or a new Coupon is created with a value equaling the new balance.

Interested to see if anyone's tackled this yet; if not, I may have a go in the near future.

pcambra’s picture

I think an additional submodule would suffice in which Coupons act as credits; if there is a balance left over after redemption (say you only apply $5 of a $10 coupon) either the Coupon balance is adjusted, or a new Coupon is created with a value equaling the new balance

Nailed it.

I believe we should implement a basic support in the coupon module by now, I'm ok with not allowing to redeem a coupon if the coupon amount is greater than the order total with maybe an extra option of allow you to redeem it just for the total amount.

In any case you can actually do all this stuff with rules right now, so patches are higly welcome.

jonathan_hunt’s picture

FWIW, the rules_zero_out_negative_balance rule in #7 worked for me.

choicelildice’s picture

Hi all,

I have been working on a site that needed gift certificate functionality for Drupal commerce, so I created a gift certificate module that is based off commerce coupon. With gift certificates, you obviously want the user to be able to apply part of the the certificate to an order, and keep the remaining balance for later. I was going to include this functionality in the module (http://drupal.org/sandbox/choicelildice/1791702) but after reading this issue queue, decided that there was use cases for a remaining credit outside of just gift certificates. So I created an additional module (http://drupal.org/sandbox/choicelildice/1839962) to keep track of a remaining balance on coupons, so they can be used for more than 1 order. This is usable (I will most likely make it required) for gift certificates, and should solve some peoples issues in this queue that want the coupon to "hold onto credit." Let me know if you want me to push it into the queue to become a full fledged module, and if there are developers with ideas to make it better, I always welcome feedback as well.

torgosPizza’s picture

choicelildice,

These look like really good starts! I haven't gotten to dive in very deeply yet, but it looks like your Gift Certificates module requires features and strongarm. Is there a reason for this? I dug into the strongarm include and I'm seeing configuration for fields like product:field_experience_registration which I doubt most sites will need or have on their nodes.

Is there any chance your module will work without having strongarm and features as dependencies?

choicelildice’s picture

Torgos,

For Commerce Gift Certitificates, I am going to leave Features as required for now, as it sets up some basic gift certificate content out of the box. Features currently sets up the gift certificate product, line item type, and coupon type. I removed Strongarm and the dependency on Strongarm.

torgosPizza’s picture

In that case, sounds reasonable enough. (Agreed that being able to auto-configure the required line items and product types for your module is a benefit.)

Thanks! Will take a look soon.

fullsaildan’s picture

Has there been any progress on this?

I really need this functionality for a site and don't want to re-invent the wheel if I don't have to.

thanks!

choicelildice’s picture

Fullsaildan,

You can use the commerce_coupon_credit sandbox module I created (http://drupal.org/sandbox/choicelildice/1839962), if you would like to keep the "credit" on the coupon if it is for more then the order total. This module also prevents the negative order total issue.

Let me know if you have issues or questions regarding the module.

fullsaildan’s picture

Hey Choicelildice!

Sorry it's been a good month since I've started testing this out. In looking at the module you created, it seems it creates another a coupon for the balance, I don't think this will work for my particular use because we have to keep track of balances for unclaimed property laws(ugh!). So wanted to see if you had any ideas on how to keep it all on the same coupon? I'm willing to write the code but my understanding is the coupon would end up defaulting to the original value if I didn't limit it to one use?

thanks in advance!

torgosPizza’s picture

@fullsaildan, can you explain a little more? Are you saying that your coupon must not be usable after it's been redeemed once, even if it includes a balance? It sounds like that's something that could be added as a feature.

I haven't had a chance yet to investigate the sandbox module in #29 but I will soon, hopefully.

choicelildice’s picture

Hey Guys, I am not ignoring these responses, they are on my radar, just been really busy lately! Just an FYI, some other devs and I are planning a mini code sprint to work on getting my gift certificates module and coupon credit modules up to full module status soon. Until then, I am open to feedback and ideas, just bear with me as this stuff really only gets worked on when I get the time, or a client is in need! Good luck, and I will update you when I have more.

choicelildice

torgosPizza’s picture

@choicelildice Awesome, thanks! I have plenty of experience (and need) for gift certificates with our site, as they drive tons of business, so I'm willing to help out in whatever way I can. Please keep us posted and thanks for taking the initiative!

fullsaildan’s picture

Hey Torgos and Choice,

No no, looking back through how the code works, I think it mostly does what it needs to. Here is the issue:

Many US states require that you track and account for the value of a gift certificate, some of them even require you to send any leftover amount to the state in a holding pot if they aren't used within a certain amount of time.

Initially I thought the code was taking the leftover value and creating a brand new coupon for the gift cert which would make it really hard to track. The way I am getting around it is by attaching 2 fields to the coupon, one for an original value and the other for a comments area(since commenting isn't possible for entities). We are using rules to write it the amount used and for what in the comments.

Actually a note for any others that want to use Gift Certificates for events or services performed in the future, here in the US: Most US accountants will want you to refrain from actually "claiming" the gift certificate revenue until the day the event occurs. Otherwise you end up with an Unearned Revenue for the books. So I had to get creative, we thought about not closing the sale until the day of. This was not ideal, it might make it possible for people to assign the GC to other registrations etc. So we decided to create a "reserved value" on the card, on checkout it adds the cost of the event to the reserved and we setup a rule to check for an available amount when people were "booking". Then run an additional process on the day of to actually deduct gift certificates.

Choice: If you need help writing code let me know. I'd be happy to dig in.

rvallejo’s picture

Hey all, just jumping in on the discussion, but I've been working on setting up Gift Certificates for a site over the past couple days and have everything working so far except for the negative balance issue. Sounds like I've been going at it in a pretty similar way as what's in progress here (no custom module, I just created a custom fixed amount coupon type, custom line item type for purchasing, product with product display, and some rules to handle purchasing/creating gift certificates, adjusting the balance, etc.).

I'm interested in the work being done on the submodules and would like to offer help in whatever way I can — I'll definitely start by giving the modules a test run on this site and send my feedback!

torgosPizza’s picture

@rvallejo: How did you create your custom line item type? I'd love to see how you've created your solution. Thanks!

rvallejo’s picture

@torgosPizza: Glad to share! I actually just had to do some reworking of gift certificates for the site I'm building (due to some of the client's needs and also an issue I noticed in my rules set-up). I ended up not spending much time testing out the posted solution, as it seemed I had something pretty similar close to finished anyway and had to handle some specific quirks of my client's operations, but I'd like to contribute what I can and compare setups.

For my line item for purchasing, I used Commerce Customizable products. Nothing too fancy, mostly just a number of extra fields exposed on the add to cart form to collect information for sending the gift certificate (Name, Email, Address, Gifter Name, Message, etc.), which all correspond to fields on my custom Coupon type. I initially had a custom Amount decimal field, similar to the Donation module, exposed to the add to cart form using the "Select or Other" module/widget to allow customers to specify custom amounts for gift certificates, intending to create one single gift certificate product. Due to some limitations in the client's offline order management program, I ended up disabling this functionality, going with multiple gift certificate products with fixed prices, using the standard line item price fields. I also added a field to store the generated coupon code for exporting to the offline order management program, adding the code when the coupon is created after checkout.

I did make one change to the standard coupon line item type, which was to add a field for the remaining balance which gets updated on order update via rules at the same time that I handle the negative balance issue. I added this field to the coupon view for the checkout pane (using a line item reference relationship and line item order argument/contextual filter) to make it more obvious to the customer how much is left on the gift certificate while still making their order.

My coupon type has the same fields as my purchase line item type, which get filled from the line item fields after the coupon is created via Rules. The coupon type uses a fixed amount price field, and I also added a text field to hold the SKU of the Gift Certificate Product. No Maximum Uses field, as validation is based on remaining balance. (On another note, I use an Unlimited boolean on regular fixed coupons to ignore max uses validation).

I didn't do anything fancy at all for my Product type and Display content type.

As far as handling negative totals and balance/credit: I actually didn't find it too difficult to handle this using just rules. Looping over each order line item, I have a component to check for a coupon line item, adding up the coupon values to subtract from the order total amount and generating a list of coupon line items. Then, looping over the list of coupon line items, I have separate components to check if the coupon value is less than or greater than the calculated order total before coupons. If less than the order total, coupon line item is set to the full coupon value; if greater than, coupon line item is set to full order amount, and a remaining balance field is set to let the customer know how much more they can use on the coupon/gift certificate. At the end of this loop, I add the adjusted coupon value back into the order total variable so that subsequent coupons factor in previous ones. On checkout, a separate rule subtracts the applied value from the coupon fixed amount, leaving the remaining balance for future use (and could potentially store additional information to the coupon at the same time, such as comments)

I can provide rules exports, or features if that'll work for coupons (haven't checked yet), or can go into more detail if anyone is interested. I set up the whole thing using just Commerce Coupon, Commerce Fixed Coupon, Commerce Customizable Products and Rules, no custom modules though it might be a better solution in the long term.

stefank’s picture

Hi @rvallejo

Sounds like a great solution. I've been looking for a similar solution. Could you please provide the rules export please?

Many Thanks

adster13’s picture

@rvallejo: I've got a similar setup to you and have it almost working.... having some trouble on the negative totals... I would love to see your rules exports for the handling negative totals and balance/credit.

rvallejo’s picture

Hey @stefank and @adster13: I've been a bit busy lately but I'll try to get some rules exports up this weekend. I'll have to go through them and try to pull out some of the things unique to the site I was building to make sure they'll work, but I'm happy to help in any way I can. I could maybe even do a chat session to go over them if that might help; I'll let you take a look at the exports and decide if you need any more clarification.

rvallejo’s picture

FileSize
18.09 KB

Okay, here are my exports and a list of things some of them rely on. Some of the fields and things are generally useful, some are specific to my needs. If you just want to import all the rules and see how they work, you'll have to make sure the prerequisites are all met or else the rules will break. Otherwise, try manually editing the rules exports to eliminate the fields you don't need. Let me know how it works, if you have any questions, or notice any flaws!

Rules (in order they should be imported, first to last; also numbered in this order in the zip file):

For Negative Totals/Adjusting Value:

Component (rule): Check Coupon Line Items
Component (rule): Calculate Gift Certificate if Less Than Order Total
Component (rule): Calculate Gift Certificate if Greater Than Order Total
Rule: Adjust Coupon Line Item Total

For Gift Certificates:

Component (rule): Fill Gift Certificate Fields
Component (rule): Create Gift Certificate for Line Item
Rule: Create Gift Certificate
Rule: Gift Certificate: Send E-mail
Component (rule): Gift Certificate: Set as invalid if maxed out
Rule: Gift Certificate Validation: Check the balance
Rule: Redeem a Gift Certificate
Component (rule): Add Order Note if Gift Certificate More Than Order
Component (rule): Gift Certificate: Set as invalid if maxed out
Component (rule): Calculate and Set Gift Certificate Balance
Rule: Adjust Gift Certificate Balance

Prerequisites (or else the rules probably won't work…machine names in parenthesis):

Modules

Commerce/Rules/Commerce Coupon/Commerce Fixed Coupon (duh)
Commerce Customizable Products (for custom line item types)
Address Field and Email (for field types)

Coupons

Type: Fixed Amount (commerce_coupon_fixed)
> Price Field: Fixed Amount (commerce_coupon_fixed_amount)
> Boolean Field: Unlimited (field_unlimited)

Type: Gift Certificate (gift_certificate)
> Price Field: Fixed Amount (commerce_coupon_fixed_amount)
> Text Field: Recipient Name (field_recipient_name)
> Email Field: Recipient E-mail (field_recipient_email)
> Postal Address Field: Recipient Address (field_recipient_address)
> Long Text Field: Message (field_gift_message)
> Text Field: Gifter Name (field_gifter_name)
> Text Field: SKU (field_coupon_sku)

Line Items

Type: Coupon (commerce_coupon)
> Price Field: Remaining Balance (field-remaining-balance)

Type: Gift Certificate Purchase (gift_certificate)
> Text Field: Display path (commerce_display_path)
> Product Reference Field: Product (commerce_product)
> Decimal Field: Amount (field_gift_amount) —My setup doesn't actually use this anymore, but I had it set up with Select Or Other module similar to Commerce Donate
> Text Field: Recipient Name (field_recipient_name)
> Email Field: Recipient E-mail (field_recipient_email)
> Text Field: Gifter Name (field_gifter_name)
> Postal Address Field: Recipient Address (field_recipient_address)
> Long Text Field: Message (field_gift_message)
> Price Field: Unit price (commerce_unit_price)
> Price Field: Total (commerce_total)
> Text Field: Web Code (field_coupon_web_code)

Orders

> Text Field: Order Notes (field_order_notes) —This is mostly for some other specific needs, but I put a note in their related to Gift Certificates

Products

Type: Gift Certificate (gift_certificate)

Nodes

Type: Gift Certificate Display
> Product Reference Field: Products (field_products) —limited to Gift Certificate products

Other notes:

I made some minor changes to the default coupon rules.
For adjusting amounts/preventing negative totals: I added a condition to the default redemption rule (Redeem a coupon with fixed amount) to check that the fixed-amount field is greater than 0 to make sure that adjusted-balance coupons are not valid when they reach 0.

For gift certificates specifically: I adjusted my default coupon validation and redemption rules (Coupon Validation: Check the number of redemptions; Redeem a coupon with fixed amount) to limit which coupon types are checked for number of uses, excluding my Gift Certificate coupon type,

pcambra’s picture

This issue has gone a little out of control, can someone post a patch in the lines of #21 and #22?
Otherwise this is a conversation about gift certificates that I agree is useful, but should happen elsewhere

rvallejo’s picture

If you notice in my last post, the first four exports (3 components and 1 rule), are specifically for handling the negative total issue, and it should be easy enough to sort out what prerequisites are specifically for negative totals vs. gift certificates. If that's all someone wants, that's how I did it and the rest can be ignored.

pcambra’s picture

That's great, would you be up to provide a patch with only those components that are required?

rvallejo’s picture

I can work on making a patch against the Coupon Fixed Amount module, basically just adding my rules into the includes. I won't plan on including any of the credit/balance or unlimited functionality I set up for the site I was building, as those seem superfluous for the issue at hand. I still haven't fully explored choicelildice's sandbox modules from #24, though they're both for credit and gift certificates, to compare how he handled negative totals as part of that.

Re: the conversation from #21 and #22, my rules make the default to allow coupons when more than the order total, as I saw no benefit in the converse. I can make the rule inactive by default, or add a boolean field on the coupon type to make it an option or something, if people really want the option to deny coupons when the redeemable value is greater than the order total. One issue I see for this, though, is that after tax, shipping, etc. get added in, and depending on when coupons are added to an order, a coupon may get denied early in the checkout process, where it may later be valid/less than the order total. My rules account for updated totals currently, but it gets tricky if you want to outright deny a coupon early in the process. Unless I can store the coupon in the coupon reference field on the order, and only add the line item at a point where the order total value becomes greater than the coupon value. Suggestions welcome—I might not get to making the patch for a week or two though, things have been busy and I'm mostly off the project I was working on this for.

rvallejo’s picture

By coincidence, the company I built the Commerce site for got in touch with me today and wants to add some coupons with a minimum order total condition. It occurred to me that creating such conditional coupons could be easier, and might perhaps provide a solution for the question of whether to allow coupons when greater than the order total.

In the discussion back around #17 there were some ideas of making an option to allow negative balances or not for each coupon. It hit me that I could kill two birds with one stone if I add in a minimum order total field—default to 0 for general use coupons; set to coupon value to prevent using coupons until the order total is greater-than-or-equal-to; set to some arbitrary amount to enable incentivized coupons (eg. off orders $100 or more). I think this is a much better way of handling the admin option when combined with rules to prevent negative balances. Personally, I think negative balances should never be allowed as doing so might break other pieces of the checkout process, and I like the extra functionality which, I think, is fairly common.

In searching around, I found this sandbox from xvendo for Commerce Amount Coupon – http://drupal.org/sandbox/xvendo/1864598. Haven't tried it yet, but the readme says it's an alternative to the fixed price coupon module; I think I would prefer something rules based that integrates with/expands fixed amount coupons, as the discussion here has been heading towards, but I figured I'd post it for documentation sake.

Horroshow’s picture

I tried Commerce Amount Coupon, the foundation is there and the idea exactly what most admin expect from a coupon module. But unfortunately I wasn't able to save a coupon and I submitted the issue in the queue. I'm sure a good developer could finish the job quickly... I really hope there's an interest for that module as it seems promising.

kimberlydb’s picture

My rule is nearly the same as #7 but that one would wipe all the other subtotal line items (like tax, promo codes etc). So I just change the total amount, not the total, total.

{ "rules_zero_out_negative_balance" : {
    "LABEL" : "Zero out Negative balance",
    "PLUGIN" : "reaction rule",
    "REQUIRES" : [ "commerce_payment", "rules", "entity" ],
    "ON" : [ "commerce_order_presave" ],
    "IF" : [
      { "commerce_payment_order_balance_comparison" : {
          "commerce_order" : [ "commerce_order" ],
          "operator" : "\u003C",
          "value" : "0"
        }
      }
    ],
    "DO" : [
      { "data_set" : {
          "data" : [ "commerce-order:commerce-order-total:amount" ],
          "value" : "0"
        }
      }
    ]
  }
}
pun_pun’s picture

Issue summary: View changes

kimberlydb, thank you for your solution #48. It works fine for me.

TravisJohnston’s picture

Thanks Kimberlydb for your rule in #48. It works great as far as zeroing-out the order total. Though I would like to see this done on a line-item level versus order total. We have a price attribute before cart that 98% of the time works fine, but sometimes it applies 2 discounts which could make the total of the line-item a -$ amount.

david.czinege’s picture

I have also noticed this issue, and i have made 2 patches to fix it:

  • commerce_coupon_fixed_amount-fix-negative-order-total-1318392-51-7.x.patch
  • commerce_coupon-fix-negative-order-total-1318392-51-7.x.patch


Apply commerce_coupon-fix-negative-order-total-1318392-51-7.x.patch to commerce_coupon contrib module's 7.x-1.x branch)

After that apply commerce_coupon_fixed_amount-fix-negative-order-total-1318392-51-7.x.patch to commerce_coupon_fixed_amount contrib module's 7.x-1.x branch)

This sollution examines if the coupon will bring the order to less than zero. If it is true, set the coupon amount to the value of the order total, so that it stops at zero.

david.czinege’s picture

Status: Active » Needs review
Plecto’s picture

Solution #48 works fine for me too. Thanks kimberlydb.

ahimsauzi’s picture

Anyone knows if this was address on the 7.x-2 branch? #48 works great, thanks @kimberlydb! My only issue with #48 is that the line items still show an amount that would total to a -$ amount which in my use case causes issues with fulfillment :(

torgosPizza’s picture

@ahimsauzi: Yes, if you use the 2.x version of Commerce Coupon (and Commerce GC if you need gift certificate functionality on your site) this issue is fixed there. I highly recommend upgrading your modules, but keep in mind there is no migration path (that I know of) for coupon entities.

ahimsauzi’s picture

Thanks for confirming @torgosPizza! We are working on updating to the 2.x branch but in the meantime if anyone else needs another way to resolve the issue, I implemented a rule that throws an error if order amount is less than a fixed coupon amount. Similar rule could be used for percent amount coupon but I did not test that.

{ "rules_coupon_is_more_than_order_total_amount" : {
    "LABEL" : "Coupon is more than order total amount",
    "PLUGIN" : "reaction rule",
    "OWNER" : "rules",
    "TAGS" : [ "coupon", "custom" ],
    "REQUIRES" : [ "rules", "commerce_coupon" ],
    "ON" : { "commerce_coupon_validate" : [] },
    "IF" : [
      { "entity_has_field" : { "entity" : [ "coupon" ], "field" : "commerce_coupon_fixed_amount" } },
      { "data_is" : {
          "data" : [ "commerce-order:commerce-order-total:amount" ],
          "op" : "\u003C",
          "value" : [ "coupon:commerce-coupon-fixed-amount:amount" ]
        }
      }
    ],
    "DO" : [
      { "drupal_message" : {
          "message" : "The coupon value cannot be larger the the order total.",
          "type" : "error"
        }
      },
      { "commerce_coupon_action_is_invalid_coupon" : [] }
    ]
  }
}
pallavi13gupta’s picture

I am facing the same issue. I tried to import rule proposed by @ahimsauzi on #56, but it is giving me error.

"Integrity check for the imported configuration failed. Error message: Unknown action commerce_coupon_action_is_invalid_coupon."