As nice as the UC Ajax Cart module is, it does not work together very well with the discounts module (the UC Discounts Alt module, to be precise, which is the de facto standard discount module for Ubercart).

What happens is that discounts do not get shown in the Ajax cart block. Also, discounts are only shown on the cart page the first time this page is loaded. Updating the cart causes UC Ajax Cart to reload the cart data resulting in the disappearance of the discount data.

Strictly speaking, of course, the problem does not lie with UC Ajax Cart itself but with the way Ubercart has implemented the cart system and how this has forced the developers of the UC Discounts Alt module to work around its limitations in ways that make it impossible for discount data to be shown without another module, such as UC Ajax Cart, making explicit provisions to do so.

That said, here are the two main issues that need to be solved in order for UC Ajax Cart to work together with UC Discounts Alt alongside proposed solutions:

1. If you've set UC Ajax Cart to Ajaxify the cart page, again discounts are not calculated. This could be fixed by duplicating the code in the "discounts.in_.ajax_.cart_.block_.patch" patch. It would be easier, however, if "Ajaxifying the cart page" simply meant that the cart form ('#uc-cart-view-form') gets submitted as soon as a change to it is detected. This way UC Ajax Cart does not have to worry about replicating the functionality in the uc_cart code for generating the cart page and can stick to solving the usability problem of making sure changes to the cart are always registered even if the user forgets to click the Update button.

2. Discounts do not show up in the Ajax cart block. The reason is the UC Ajax Cart module itself tries to figure out what the total price for the cart is. Since the UC Ajax Cart module has no knowledge of UC Discounts Alt, it does not taking discounts into account. The unfortunate result, however, is that the total price shown in the Ajax cart block is wrong.

The solution to this problem is to add knowledge of the UC Discounts Alt module to uc_ajax_cart_preprocess_uc_ajax_cart_block_content and uc_ajax_cart_block_content.tpl.php.

A workaround is to implement your own preprocess_uc_ajax_cart_block_content, calculate the correct total there and then show it in your own copy of uc_ajax_cart_block_content.tpl.php.

This is cumbersome so I'd like to request integrating calculating discounts into UC Ajax Cart itself. See the attached patch "discounts.in_.ajax_.cart_.block_.patch" for the code that is required to do this.

Comments

tunic’s picture

Title: UC Ajax Cart does not play nice with UC » UC Ajax Cart does not play nice with UC Discounts Alt
Assigned: Unassigned » tunic

Thanks for your report and patch, I'll try ASAP.

navid.kashani’s picture

subscribe

akalata’s picture

I've tested this patch on 6.x-2.0 with UC 6.x-2.7, didn't seem to have any effect.

bartezz’s picture

Version: 6.x-2.0-rc1 » 6.x-2.x-dev
Status: Active » Reviewed & tested by the community
StatusFileSize
new2.81 KB

Tried as well. Applied by hand to 6.x-2.x-dev (2012-Jan-24 ) with UC 6.x-2.7 and works like a charm.

@akalata: did you by chance have a copy of uc_ajax_cart_block_content.tpl.php in your theme? I did too and thought it wasn't working :) Removed the uc_ajax_cart_block_content.tpl.php from my theme, clear cache and it worked like a charm! Ofcourse make sure your discount works for the products you have in your cart. This doesn't work with discount coupons and such ;)

Patch by #1 against rc1 reviewed and tested. (patch against 6.x-2.x-dev (2012-Jan-24 ) with exact same code included)

Cheers

PS. my patches always seem to fail testing due to line endings and other shite... it's a battle without end... please excuse these!

tunic’s picture

Status: Reviewed & tested by the community » Fixed

Ok, thank you very much fot the testing, patch in #0 committed to dev.

bartezz’s picture

Status: Fixed » Needs review
StatusFileSize
new2.85 KB

Damnit I spoke too soon! My sincere appologies!

Yes the changes in the patch apply the discounts to AJAX cart and show them in the tpl.
But I needed to test something and disabled uc_discounts_alt and ran into an error. The changes to uc_ajax_cart.theme.inc in #1 do not check if uc_discounts_alt is enabled at all!

I've added a check with module_exists(). Please see my patch.

Cheers

bartezz’s picture

Priority: Normal » Critical

Since you've committed to .dev already changing status!

tunic’s picture

Priority: Critical » Normal
Status: Needs review » Fixed

Added uc_discounts_alt avaibality before use its functions.

Lowering priority as it's fixed.

I was unable to apply your patchs Baretzz, don't know what the problem is.

Thanks for reporting!

bartezz’s picture

Patch in #0 calls get_discounts_for_order() which is a function declared by uc_discounts_alt thus if one does not have this module enabled things go wrong. Therefore I added if (module_exists('uc_discounts_alt')) { in #6.

Didn't know you Added uc_discounts_alt avaibality before use its functions I just read patch in #0 committed to dev. that's why I reported with status critical as this would break a site...

Cheers

tunic’s picture

Bartezz, indeed I didn't add check until you told me, excuse me if my message wasn't clear.

I've committed today the code that checks for the module existence and then I've updated the bug report.

I've tried to apply your patchs but there's something wrong, git refuses to apply them so I made changes manually.

Thanks again for reporting.

loparr’s picture

Hi,
I installed the latest dev version on drupal 6 but the cart keeps displaying total amount before discount. Did you guys managed to make it work?
Thank you

stewart.adam’s picture

The patch above needs to be modified slightly, as although uc_discounts_alt is the name of the Drupal project, the module that gets installed is named 'uc_discounts'. The call to module_exists() needs to be modified to show reflect.

loparr’s picture

So which patch should I apply to which version in order to make it work? thank you

stewart.adam’s picture

Status: Fixed » Needs review
StatusFileSize
new469 bytes

This the patch for latest 6.x-2.x-dev (git).

loparr’s picture

working:) thank you

stewart.adam’s picture

Status: Needs review » Reviewed & tested by the community

Marking RTBC.

tunic’s picture

Status: Reviewed & tested by the community » Fixed

Patch in #14 committed to dev, thanks stewart.adam.

Status: Fixed » Closed (fixed)

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