Discount on Amount in Cart does not work properly
I try to add simple discount: 7% if total sum is grater than $60
At admin/commerce/config/taxes/types i have new type: discount
At admin/commerce/config/taxes i created new tax rate Discount 7% (component)
In this component i created condition “Data comparsion” and seleced option “commerce-line-item:order:commerce-order-total:amount”
And lets test it: order for total sum $58.88: http://i.imgur.com/FIfVe.png Looks ok, no discount.
But when i went back to “view cart” and click on checkout i saw the same product list with discount 7% http://i.imgur.com/QDghA.png It happens randomly. Sometimes the discount appears sometimes does not appear. I did not change anything in rules settings.
Another strange thing: total sum is $67.88 http://i.imgur.com/mp7AI.png but in debugging variable commerce_order_total this value is set to 63.13 so after discount. In previous case (58.88) this value was set to 58.88 so before discount calculation.
I was reading http://www.drupalcommerce.org/discussions/1123/discount-amount-cart but this didn’t help me.
Discount rule settings: http://i.imgur.com/q2ONU.png http://i.imgur.com/Au0qj.png
List of contrib modules: http://i.imgur.com/5Sp4h.png
Drupal 7.14
Commerce 7.x-1.3
Can anybody help me with this problem?
Comments
set up a discount and handle the VAT in correct way
I have very very similar problem. So I tried to use VAT hack to calculate discounts. I would like to make several type discounts: if the subtotal of the cart is greater than 200 EUR and lower than 400 EUR, then the discount would be 10%. If the subtotal of the cart is greater than 400 EUR and lower than 600 EUR then the discount is 20% and so on... I created rules like grzegorz.bartman, but it doesn't work correctly. It calculates discount even the subtotal is lower than that price what I typed in. Also it is very important, that the VAT should calculate from the discounted price and not from the subtotal price. Actually the VAT is calculated from the subtotal price (which is price without any discounts), and not from the discounted price. Can anyone help to us, how to create discounts in this way?
I tried to use hook_commerce
I tried to use hook_commerce_tax_type_calculate_rates and i found this:
My case:
1. Cart: Total $63.38 http://imgur.com/BtV5W
2. Checkout: http://i.imgur.com/jGVVn.png - Discount 7% work OK (no title, but this is no big problem)
3. Go back to Cart and remove one product for $4.50 http://i.imgur.com/gfTno.png
4. Discount 7% is still in summary http://i.imgur.com/qcdAB.png
5. commerce_cart_order_load($user->uid) object still has information about discount http://i.imgur.com/IS4BE.png
6. Now when i refresh checkout page discount disappear http://i.imgur.com/9ZMHz.png and commerce_cart_order_load($user->uid) object works ok http://i.imgur.com/BSfG9.png
So problem is in function commerce_cart_order_load - this function do not refresh commerce_order_total attribute when user change something in cart and click on Checkout button.
Now i used custom code and custom module: http://pastebin.com/75JCuR7f
Maybe the same problem is when i try use rules?
Did the custom code solve the
Did the custom code solve the problem?
Anyway, please create an issue (http://drupal.org/node/add/project-issue) with your problem (copy and paste the same text, with pictures) and probably the developer of a module will modificate the module.
With custom code i have still
With custom code i have still the same problem.
I posted issue at drupal.org: http://drupal.org/node/1786628
I solved problem with rules:
I solved problem with rules:
Condition: Order balance comparsion
Argument: [site:current-cart-order]
which argument is the subtotal?
Wow! It sounds great. Do you know, which is the argument of subtotal? Because the discount is calculated from the "Order total", but I need that the discount be calculated from subtotal. (I need it because I have a VAT calculation after the discount)
I don't have VAT so i can't
I don't have VAT so i can't help you.
My problem with discounts still occurs. Evidently there is a problem with the cache when user change values in cart and click on button Checkout. Order total is cached and has old value and discount value is not changing.
http://pastebin.com/itsC001x
http://pastebin.com/itsC001x - rule condition with Subtotal
Code...
What do I do with that code? I can't find that file in my install.
Code...
I added the code to my commerce_discount.rules.inc file; however, I don't see the condition in my Rules. I even uninstalled the module, reinstalled it, and cleared the cache.
I have my own custom module
I have my own custom module named commerce_discounts. If you want to use in other module you have to change prefix of function name.
sweet!
The module solved my problem! I spent my afternoon hitting my head agains all walls figuring out why the tax rates would not do what I wanted them to do... ouch!
Thanks a lot @grzegorz.bartman
The solution...
I was looking at the solution at pastebin, but wasn't certain what to do with it since I don't have a file named that. I have something similar - commerce_discount.rules.inc - but it's not the same file.
Code...
For others who may look at this and need to know:
I added the code to my commerce_discount.rules.inc file at the bottom. There is one line right at the top that has to be edited:
function commerce_discounts_rules_condition_info() {
It too has the extra "s" at the end of discount. Fix that and then subtotal becomes an option inside Rules.