We ran into issues in our demo due to discounts not taking immediate effect, and we finally determined the problem was discounts not being applied b/c of cached prices. It would probably be best for the price cache to clear whenever one of the CA conditions/actions forms gets saved and discounts are part of the predicate.

Comments

Island Usurper’s picture

Status: Active » Needs review
StatusFileSize
new1.35 KB

This patch looks for predicates on the three predicate forms that have one of the discount triggers. I don't like the extra call to ca_predicate_load(), but it might not be worth worrying about.

jantoine’s picture

Status: Needs review » Needs work

Lyle,

I applied the patch and installed the module and received the following error:

PHP Fatal error:  Call to undefined function ca_predicate_load() in /var/www/html/oregonaero.com/drupal/sites/all/modules/ubercart/contrib/uc_discount/uc_discount.module on line 57, referer: https://www.oregonaero.com/admin/store/ca

Cheers,

Antoine

Island Usurper’s picture

Status: Needs work » Needs review
StatusFileSize
new1.35 KB

D'oh! It's supposed to be ca_load_predicate(). New patch.

Island Usurper’s picture

StatusFileSize
new1.35 KB

*Sigh*

Forgot to save before making the diff.

jantoine’s picture

Status: Needs review » Needs work

After applying the patch, prices on product nodes automatically reflected a newly created discount. One thing I noticed that might be confusing to customers is that products already in the cart do not reflect the discount, however when you proceed to checkout, the discount is applied. Is there a way to update the cart as well?

Cheers,

Antoine

jantoine’s picture

After further investigation, it appears Ubercart stores the cart cache in the users session and not in the database. I couldn't find a flag to set that would tell Ubercart to rebuild the cart cache, this is only accomplished by passing a 'rebuild' action parameter into the uc_cart_get_contents() function. After considering several options, the best I could come up with was to add a flag to Ubercart that price handling modules could set which uc_cart_get_contents() could then read and rebuild the cart cache if necessary. Is this the best approach, or is there a better option I am overlooking?

Cheers,

Antoine

jantoine’s picture

StatusFileSize
new1.93 KB

After reviewing the issue at http://drupal.org/node/488652, I discovered the hook_cart_item hook provided by Ubercart. This hook does exactly what we want by examining items in the cart for any modifications since having been added to the cart. Updated patch attached.

The new code in this patch was provided by andreiashu at this issue: http://drupal.org/node/488652. Committing this patch would also fix that issue.

Cheers,

Antoine

jantoine’s picture

Status: Needs work » Needs review

Changed Status

jantoine’s picture

Correction... I could not verify that the supplied patch fixes the issue at http://drupal.org/node/488652. The code supplied by andreiashu doesn't solve that issue on my system, but his code does solve the issue posted here, so the supplied patch is still good for this issue. Sorry for the confusion.

Cheers,

Antoine

Island Usurper’s picture

OK, I'm a little confused now. :)

I'm still trying to work out a solution for #488652: calculate_product_discounts not triggered when adding products from admin area because I need to find a spot in the ordered product workflow that I can add the discount that isn't also used in the checkout workflow. But I don't think it has much to do with this issue here.

I haven't seen any problems with products in the cart holding on to the old prices when I changed the discount conditions or actions, though, so I don't see a need for using hook_cart_item(). Cart item prices should be recalculated every time the cart is loaded. Maybe I've missed some situation where it's not.

jantoine’s picture

I am able to reproduce a situation where the cart holds on to the old prices using the following procedures:
1. Add a product to the cart
2. Create a product discount for the product previously added to the cart
3. View the cart
BUG: Discount is not reflected on the product unless the "Update Cart" button is clicked.

Cheers,

Antoine

Island Usurper’s picture

No, I don't need to update the cart for the discounted price to show. In fact, as soon as I add the discount action, I see the total in the cart block change. Make sure you've got the latest dev versions of both Ubercart and UC Discount, as that's what I'm working with.

This might be silly of me to point out, but you would have to refresh the cart page to see the new price.

jantoine’s picture

Status: Needs review » Reviewed & tested by the community

You have to refresh the browser?...jk

Didn't have the latest Ubercart 2.x-dev. With the latest Ubercart dev install, the patch from comment #4 is good. Changing status to "reviews & tested by the community".

Cheers,

Antoine

Island Usurper’s picture

Status: Reviewed & tested by the community » Fixed

Whoops. Forgot to update the issue after committing it. Fixed as of yesterday.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.