Discount not reflected on total order

Valdes@www.drup... - October 7, 2009 - 09:22
Project:UC Discount Framework
Version:6.x-1.x-dev
Component:Miscellaneous
Category:bug report
Priority:normal
Assigned:Unassigned
Status:reviewed & tested by the community
Description

I have created more roles and more discounts for the same product, depending if the user is a customer, a reseller, etc. Then through Conditional Actions I have applied to the product the discount (let's say 10%) linked to the role entitled to the 10%'s discount.
On the product node I can see the discount is correctly applied. But when I purchase I get the discount applied only to the subtotal, while VAT e the Total Order are shown not discounted. If I also add the shipping cost, I get a first subtotal discounted, the shipping cost, a second subtotal not discounted and then VAT and Total Order not discounted.

I do not know what I'm doing wrong here. I tried to apply the discount eigther with the add mode and the multiply mode, but VAT and total seem not to "hear" the discount. Could you help me telling me what I have to do to solve this problem?

Thank you very much!

Attached is an image.png taken from the checkout page to help my english ;)
The Total original price ordered is of 400 euros.
As you can see, discounts have been applied and the subtotal is correctly 253 euros.
Then shipping cost is added for a 13 euros.
Then we have an overall subtotal without VAT, but it doen't report the discount: it is of 413 euros and then VAT is applied to this second subtotal.

AttachmentSize
image.png17.54 KB

#1

Island Usurper - October 9, 2009 - 20:29
Category:support request» bug report
Status:active» needs review

I've been busy working on the 2.0 release of Ubercart, and I haven't been keeping this module in sync with those changes like I'd planned. I finally found some time to do it, though, so here's a patch for you to look at and test.

I think a large part of the problems with uc_discount are fixed by #595832: hook_line_item_alter() is called twice, but it needs some good reviews to make sure I haven't missed anything. You'll also need #600478: Subtotal excluding taxes doesn't use uc_price() if you use shipping quotes.

AttachmentSize
597992_uc_2.0_catch_up.patch 8.9 KB

#2

Valdes@www.drup... - October 10, 2009 - 16:07

Thank you Island!

Your patches work almost perfectly.
The only error left is that products' VAT is calculated on the original (not discounted) product's prices. VAT applied to shipping cost is correctly calculated (I don't have and will not have uc_vat module enabled).

Now I get this picture (with a VAT of 20%, original products amount of € 300,00 and a discount of 50%):

Subtotal € 150
Shipping € 10
Subtotal without taxes € 160
VAT 20 € 62 (instead of € 32 - shipping's VAT is correct -2 euro-, products VAT should be € 30 not 60)
Total order € 222 (instead of € 192 due to wrong VAT calculation)

However, you made a very good job so far :-)

#3

Island Usurper - October 13, 2009 - 15:24

That's an interesting observation. I just updated the patch at #600478-7: Subtotal excluding taxes doesn't use uc_price(), so if you can test that out again, that would be great.

#4

Valdes@www.drup... - October 13, 2009 - 16:44

Now the ../cart/checkout page is correct (see screenshot-1.png), but in the ../cart/checkout/review page there is still an error (see screenshot-2.png) because in the "Subtotal excluding taxes" it counts only the shipping cost, not the product's cost, VAT is applied to the original, not discounted product's price and so the total is wrong too.

AttachmentSize
Screenshot-1.png 23.67 KB
Screenshot-2.png 21.4 KB

#5

Valdes@www.drup... - October 20, 2009 - 08:31

Hi Island,

did you have any chance to give a look to the checkout/review's page problem as per #4 above?
I attempted to see what is wrong in the code, but i'm not a programmer and I'm not been successful ;-)

So, I'm looking forward for your good news.

#6

matero - November 9, 2009 - 21:33

I've patched with 597992_uc_2.0_catch_up.patch

Now the discount shows up in the total. Nice.

but...

Now on the completed order page I get:

warning: __clone method called on non-object in .../sites/all/modules/uc_discount/uc_discount.module on line 110.

The error shows up even with my "Calculate product discounts" Conditional Action deactivated.

Uggh
Any Ideas?

#7

kazan - November 15, 2009 - 20:40

Just want to confirm the same error as #6, which happens after clicking 'submit' on the review order page. I am running:

ubercart 2.0
date conflict patch 611044
no locks patch (drupal.org/node/618932)
discount framework patch 597992

Error doesn't seem related to products with discounts - an order with a single non-discounted product also throws this error on submit. The order itself is created, but the order totals do not reflect the discount.

Let me know if I can provide more info.

#8

GiorgosK - November 25, 2009 - 19:22

Here is an updated patch that works with ubercart 2.2
seems to resolve the problems from #4,5,6,and 7

NOTE: Does not need ANY other patch for discounts or ubercart core
THUS, don't use ANY of the patches mentioned in this thread ;-)

patch uc_discount 6.x-1.x-dev 2009-Aug-22
from within the modules directory
and please report back

NOTE: it also includes the small patch found here #623124: Show discount on cart and checkout pages in order to display discounts on the checkout page

NOTE to developers:
difference with previous patch is

<?php
//line 109 uc_discount.module
   
case 'order_product':
       
$node = clone $context['subject']['node'];
       
$item = $context['subject']['product'];
       
$cache = 'order_product:'. $node->nid .':'. $price_info['price'] .':'. serialize($item->data);

?>

to
<?php
   
case 'order_product':
      if (isset(
$context['subject']['node'])){
       
$node = clone $context['subject']['node'];
       
$item = $context['subject']['product'];
       
$cache = 'order_product:'. $node->nid .':'. $price_info['price'] .':'. serialize($item->data);
      }
      else if (isset(
$context['subject']['order_product'])){
       
$order_product = clone $context['subject']['order_product'];
       
$cache = 'order_product:'. $order_product->nid .':'. $price_info['price'] .':'. serialize($order_product->data);
      }
?>

since on the cart/checkout/complete page I found out that $context['subject']['node'] does not appear to exist but $context['subject']['order_product'] appeared to have all that was needed for $cache

used a debugger for this and hope my assumptions are correct

AttachmentSize
597992_1.patch 9.53 KB

#9

Valdes@www.drup... - November 26, 2009 - 16:37

Thank you for your job GiorgosK, but unfortunately it doesn't solve my issue. So far the best result I reached is as per #4 above (ubercart 2.0 and Island patches) where the checkout page was correct.

I have seen here http://drupal.org/node/600478#comment-2305980 that you tried 2.2 taxes with and without http://drupal.org/project/uc_discount module in use and you noticed no problem whatsoever and that you have no problems without the 600478_tax_subtotal.patch (http://drupal.org/files/issues/600478_tax_subtotal_0.patch) using uc 6.x 2.2, taxes behave as expected.

I wonder if you just activated the uc_discount module or if you also configured it assigning some discounts, because I'm getting a complete different picture.

This is my situation:

Through conditional actions I created discounts assigning them to roles and I can see the correct discounts applied to products based on the different role I use to access the site, so I assume that part of the story is ok.

With regard to the checkout I get the following situations (I will use some screenshots as sometimes images describe better than words):

Situation 1) Using Ubercart 2.2 and uc_discount 6.x-1.x-dev 2009-Aug-22 (not patched) and accessing it with a role with no discout associated (so discounts are not shown) everything is fine: checkout page, preview page, order page and the order emailed. See screenshot nodiscount-nopatch.png

Situation 2) same as 1 above but this turn I use your patch 597992_1.patch (http://drupal.org/files/issues/597992_1.patch). The result is the same as in 1 above, so I get no problem with taxes eighter with or without your patch (which is likely the same you got).

Situation 3) Using Ubercart 2.2 and uc_discount 6.x-1.x-dev 2009-Aug-22 (not patched) but accessing it by a role with a discout of 30% associated. On checkout page Subtotal excluding taxes doens't reflect the discount, while preview page, order page and the order emailed do not reflect the discount at all event on product items. See screenshot withdiscount-nopatch.png

Situation 4) same as 3 above but this turn I use your patch 597992_1.patch (http://drupal.org/files/issues/597992_1.patch) and I get the same result as in 3 above.

So, do you experience the same issues if you apply a real discount or it is just me doing something wrong?

AttachmentSize
nodiscount-nopatch.png 25.1 KB
withdiscount-nopatch.png 32.43 KB

#10

GiorgosK - December 3, 2009 - 12:20

I am actually using discounts per role with the help of conditional actions and I just have ubercart 2.2 and my patch applied to uc_discount and I seems to have solved all those problems

NOTE: a very important point is that you have to have taxes applied to discounts as well

in admin/store/settings/taxes/1/edit under "Taxed line items:" you should check both Discount and Tax as seen in the attached screen shot. That should do it.
EDIT: tax line does not need to be checked.

If this does not seem to help I would advise you to run update.php since it can clear all the cache. This was giving me a lot of headaches actually.

AttachmentSize
uc_discount_with_taxes.png 9.8 KB

#11

Valdes@www.drup... - November 29, 2009 - 16:54

Well, I took some time doing several tests and I run updated.php quite a lot of times ;-)
I kept cecking my files with your patch to ensure I didn't miss a comma and the final result is that on the checkout page I'm always getting "Subtotal excluding taxes" and "VAT" applied to full price, not to discouted prices, i.e. I'm back to the original post in this tread, the only difference being that this turn the TOTAL is made up of the correct discounted product' subtotal plus the wrong not discounted VAT.

I'm not a programmer so I cannot judge if there is something wrong with the code or if it is just a misconfiguration on my part, in which case I don't know where to look at. All products in my site are subject to VAT and to be discounted, so I didn't create any class and I'm just using the standard product content type.

I testes also by checking Discount and Taxes on admin/store/settings/taxes/1/edit as you suggested, altough I don't understand why you are applying tax to taxes. On Ubercart site I found this post where Lyle says not to do so, see http://www.ubercart.org/forum/support/11358/tax_product_vs_tax_order. Anyway, I guess this is not the source of my problem.

#12

4kant - December 1, 2009 - 11:05

Hi Valdes,

I do have the same issue as you.
I think, discounts are well configured by you in CA.

Furthermore I´m using two more product classes.
As you said: the "Subtotal" value shown in checkout page is the correct discount total.
And although I tried without any tax rules the "Order total" value is the "un"-discounted value (price).

Customers are forced to pay the original price(s).

I haven´t tried any patches yet.

CU - 4k

#13

4kant - December 2, 2009 - 13:30

Now I applied the patch #1 (http://drupal.org/files/issues/597992_uc_2.0_catch_up.patch).
Got the same effect as Valdez in #2 in checkout and review.

Furthermore I get an error after submitting the order:

Order number: [order-admin-link]
Customer: [order-first-name] [order-last-name] - [order-email]
Order total: [order-total]
Shipping method: [order-shipping-method]

Products:
- 1 x

Next thing I did was deleting the tax-rule again, emptying cache etc.
Still the same error in checkout/complete

4k

#14

GiorgosK - December 2, 2009 - 14:34

@4kant
the patch you tried does not work because UC2.2 release has some major changes under the covers

if you are using UC2.2 please try newer patches first such as patch from #8 (but apply in a clean installation of uc_discount - without any patches on it)

I have tried all other patches around and don't work but this one I created and its working

Still I needs some testing so we can tell the developer to apply it to the module

#15

4kant - December 2, 2009 - 14:39

@GiorgosK
thanks for your hint.

Just to be clear: there´s no other patch I have to combine with this "597992_1.patch"?

Or do I have to take a look somewhere else too?

#16

GiorgosK - December 2, 2009 - 17:16

just patch from #8 ALONE on clean installation of uc_discount
(everything else I tried created problems)

#17

4kant - December 3, 2009 - 11:12

Hi GiorgosK

here is my report (wrong values are strong):

  1. Applied the patch on a clean uc_discount install. uc_vat installed but no tax rate and flatrate 0 -->
    • Discount product price product shows discount price (correct)
    • Order this product --> Subtotal and Order total are correct in checkout and review page
    • Submit the order --> everything´s OK
    • Combine the discounted product with two non discounted products in the order --> all steps are OK
  2. Add a tax rate (19% European Tax) (Taxed Line items "Discount" and "Tax") -->
    • Tax and Discount price in Cart are OK
    • Tax value in checkout and review page is taken from original price, not discount!
    • subtotal and order total are OK
    • turn off taxed line items --> no difference
  3. uninstall VAT European Vat support -->
    • clear all caches
    • subtotal is correct
    • now the line "subtotal excluding taxes" appears (was turned off in VAT configuration) and shows the original price (correct)
    • tax is taken from the original price (wrong like last case)
    • this time: "order total" is subtotal + tax (wrong!)
    • turn back on tax line items "discount" and "tax" --> no difference
  4. install VAT European VAT Support again (just to be clear whether I didn´t take care before)
    • the total order is back correct (same value as subtotal)
    • the tax value is taken from the original price (still wrong)

With the European Tax (VAT) it´s very close to be correct.

Is there something i can change (try) in configuration?

Thanks

#18

GiorgosK - December 3, 2009 - 11:42

Are you using http://drupal.org/project/uc_vat ?

the discount above and the latest patch assume
the core uc_taxes from uc 2.2 and uc_discount 6.x-1.x-dev from 2009-Aug-22
no other extra modules have been tested and are probably not compatible with this module

if you want uc_vat support/features added you have to create another issue in this module's issue queue or in uc_discount issue queue

Another option would be to try the core uc_taxes which work pretty good with different taxes per region/country ...

- Enable module
- admin/store/settings/taxes/add
Create different taxes for each country/region (remember under Taxed line items: check Discount)
- Click conditions and use Condition: Check an order's billing State/Province and select appropriate regions that apply
admin/store/ca/uc_taxes_1/edit/conditions

#19

4kant - December 3, 2009 - 13:57

- Uninstalled uc_tax
- cleared caches
- delete browser cache
- did what you described (add tax, regions, conditions)

The result is the same as 3.

4kant

#20

GiorgosK - December 3, 2009 - 15:55

did you apply the patch from #8 ?
that is what this patch is doing here !!

#21

4kant - December 3, 2009 - 16:17

#8 - of course.
The effect was that instead of having order totals without discounts they are now correct.

I don´t know where the difference is to your installation/configuration.
Are there some other configurations in CA that I don´t know yet?
Or a tax rate for US parallel?

#22

GiorgosK - December 4, 2009 - 08:52

Just did a test run with a clean drupal install and all works as I described

- Clean install of drupal 6.14, ubercart 2.2, latest dev release of uc_discount and patch from #8
- created an action for discount, (trigger calculate order discounts, action: apply a discount, multiply -0.50)
- created one tax rule with (tax line items: checked Discount)

take a look at the screenshot that proves this

if you want to work with your existing ubercart I am not sure what patches are still in your code
overwrite ubercart files with a clean set of files from http://www.drupal.org/project/ubercart
also install clean code of uc_discount and patch it with 597992_1.patch
do a clean cache and should be ready to go

if this does not work probably you have modified other ubercart related files ... try with a clean install like I did

AttachmentSize
597992_1.patch.gif 13.54 KB

#23

4kant - December 4, 2009 - 10:04

Tried the trigger "Calculate order discounts" as you described in my existing installation.
The result is the same as yours: Everything works like you showed in your screenshot.

The difference between your and my CA-configuration is:

I used the trigger "Calculate product discounts".
This is useful to show discounted price(s) on the product page (and I guess it is important to have this feature).

If I combine both triggers (taking care of correct weights) I realize that the trigger "C. order discounts" does not use the discounted value of "C. product discounts".

4k

#24

GiorgosK - December 4, 2009 - 10:09
Status:needs review» reviewed & tested by the community

Don't think that the original uc_discount was meant to show the discounted price on the product page !!! I think only on the checkout and review pages !!

That is why there is a new module around that does that but have not tested it http://drupal.org/project/uc_member_pricing

thus I am marking this issue as RTBC

#25

Valdes@www.drup... - December 4, 2009 - 23:57

Thank you very much 4kant and GiorgosK for your work.

Well, now we know that GiorgosK's good results are due to the fact he applys discounts to order totals while 4kant and I we are applying discounts on a per product basis, which I feel is a feature really important.

I hope uc_discount was not intended to be used only with order totals and I would like to know Island Usurper opinion about this point. As a matter of fact, I stated in #1 that I was using "more roles and more discounts for the same product, depending if the user is a customer, a reseller, etc." and Island didn't say I was doing wrong at that time. Furthermore I did other tests and I found that with a Drupal 6.14, a fresh UC2.2 and a fresh uc_discount patched as per #8 plus Island patch http://drupal.org/node/600478#comment-2145516 "600478_tax_subtotal.patch" I get completely correct figures on checkout page (as it was in #4). Things then get messed up on preview and order pages, but on my opinion it is just a matter of enanching Island's patch because if the checkout page is correct it means Island's patch is on the right direction.

Just my 2c :)

 
 

Drupal is a registered trademark of Dries Buytaert.