Closed (duplicate)
Project:
Ubercart Discounts (Alternative)
Version:
6.x-1.0-beta33
Component:
Miscellaneous
Priority:
Normal
Category:
Support request
Assigned:
Unassigned
Reporter:
Created:
2 Jul 2009 at 02:30 UTC
Updated:
27 May 2011 at 22:39 UTC
Jump to comment: Most recent file
Comments
Comment #1
ryangroe commentedThe latest version of the module should show the same discounts on the cart page as it does on the the product page. Attached is an example showing the discounts in the cart page.
Comment #2
a_lawry commentedThanks for the reply.
I was actually referring to the cart block not the cart page.
Everything is ok on the cart page once you go to it but while you are browsing around the store adding products to the cart the total shown on the cart block is the subtotal (ie it would show $400 in your example).
How can I get the discounts total for the cart block?
Thanks for your help.
Comment #3
mrwhizkid commentedI'm also looking for a solution to this issue. It can be confusing for customers when they don't see the accurate amount in the cart.
Comment #4
hackboy2600 commentedI too am looking for a solution to this, I have tried a couple of times to add a hook into the Discount module but have come up with no luck.
Is there a way to swap the price in the block with the discounted price?
I have tried that once but I don't know if Ubercart was able to recognize the discount field or if i was even using the right one.
If anyone knows the variable name for the discounted price couldn't we just add that into the cart.module file replacing $price?
Comment #5
IT Guy 3000 commentedYes, seeing the discount price in the cart block would be great. It's a bit confusing to customers as is. Subscribing.
Comment #6
a_lawry commentedI'm now working around this in my theme.
I've done the following:
1. Copied theme_uc_cart_block_content($help_text, $items, $item_count, $item_text, $total, $summary_links) from the uc_cart module into my template.php (and renamed it).
2. Made a new function based on uc_discounts_cart_pane($items) that only returns the total of the discounts. I've called it uc_discounts_cart_block_discounts($items).
3. Edited theme_uc_cart_block_content() in my theme to add a Total discounts line which displays the total.
4. Edited theme_uc_cart_block_content() in my theme to display $total - $total_discounts as the total line.
That's it. Now my cart block is displaying the correct discounted total. I tried displaying the itemised discounts in the cart block as well but the messages were too long.
Comment #7
mikec commentedWould you mind sharing your work around, @a_lawry? I tried to do the same thing, but I can't call my created uc_discounts_cart_block_discounts($items) from my renamed theme_uc_cart_block_content(). The call to
$discounts = get_discounts_for_order($order, $errors, $warnings, $messages);raises an SQL error and returns an empty $discounts array.
Comment #8
Zalatar commentedYes this would be great to see implemented into the module.
If nothing else maybe a_lawry can post some detailed directions for all of us.
Z
Comment #9
a_lawry commentedHi,
Here's what I have done so far.
This is from my template.php my theme is called menkom_jaguar. It is a copy of the function theme_uc_cart_block_content() from the uc_cart module.
And I've also added a new function to the module which you can see in the above code:
This function returns an array with the keys 'total' and 'details'. I've returned 'details' in case I want to put the full details of the discounts into the block. But I found this doesn't look that good at the moment. So you could simplify it to just return the total.
Comment #10
mikec commentedThanks a ton, @a_lawry. This is the line I that you corrected for me:
$discount_info = uc_discounts_cart_block_discounts(uc_cart_get_contents());I didn't know about the uc_cart_get_contents() function, and based on the two function's prototypes, I tried to pass $items into uc_discounts_cart_block_discounts, which didn't work. Everything works well now.
Comment #11
totnorbi commentedTo which .module file do I have to copy the new function? uc_cart?
Comment #12
jdln commentedsubscribing
Comment #13
pauljb commentedsubscribe
Comment #14
jdln commenteda_lawry, ive added the first load of code from post 9 to my template.php file and changed menkom_jaguar to my themes name.
Where does the 2nd load of code go?
Thanks
Comment #15
jdln commentedI messaged a_lawry about where to put his code and he said this;
‘The first lot of code needs to go in your theme and renamed.
The second lot of code is placed in the uc_discounts (alternative) module. It increases the functionality of the module a bit to return the discounts as an array of information. You can then output that information anywhere on your site.’
Im assuming the uc_discounts module is the file called uc_discounts.module.
I get a white screen unless I remove the opening and closing php tags from both pieces of code. Im assuming this is because the files im copying to already have content so already have opening php tags.
So I think ive done everything right but their is no (visible) change to my site. To find the discounted price I need to find the number from an array. Ive added
<?php dprint_r($GLOBALS) ?>to my page.tpl.php.Ive then added some products to my cart. I can see the price is £15 but £12 with discounts. Ive gone to a different page and now searched for the text ‘12’ in the arrays. However I can’t find it anywhere.
Have I added the code correctly so far? Is so, how do I find out how to call the discounted value?
Thanks
Comment #16
a_lawry commentedYou need to clear the theme registry to make sure the theme function is recognised.
Comment #17
jdln commentedThat hasn't changed anything. Im using the zen theme so ive set this;
'For easier theme development, the theme registry is being rebuilt on every page request. It is extremely important to turn off this feature on production websites.'
Thanks
Comment #18
jdln commentedIve made a fresh install of drupal and ubercart to try and get this working. With both the garland theme and a zen sub theme, as soon as I add the first load of code to template.php I get a white screen!
This is so frustrating as its the last thing I need to do for my site.
Comment #19
jdln commentedIm not getting the blank screen if I change zensubtheme_my_1_uc_cart_block_content to zensubtheme_my_1_theme_uc_cart_block_content
However, I dont know if the code is doing anything. Their is no visible change to my site. If I add this to my page template;
On the shopping cart page I can see the 'Subtotal including discounts' number in the code. However when I search for this number on other pages it isnt there.
If the fix was working, would the cart block appear differently or do I have to theme it? If i do have to theme it, how can I check if its working?
Thanks
Comment #20
mhel commented@jdln I maybe reading it wrong, but on #18 both codes should be applied at the same time, one for the template the other to the uc_discounts.module .
On #19 rename your function back to your first one without _theme_ and try commenting this line:
$subtotal += get_discounts_taxed_price($item->price, $item) * $item->qty;on the second code in #9. I myself can't find where get_discounts_taxed_price() is defined.Clear your cache first. admin->settings->performance .
If that works, you might want to add this
if ($discount_info)just below this line $discount_info = uc_discounts_cart_block_discounts(uc_cart_get_contents()); at the first code on #9 above.Note: php tags not included, it's just for posting clarity :-)
Edit 1: Forgot to thank a_lawry for the mods, thanks :)
Edit 2: Corrected the line for if condition.
Comment #21
jdln commentedIm still getting the white screen.
If I use dreamweaver to search for the text 'uc_cart_block_content' in my source code of my entire site the only instance found is in the template.php where I just added it. Should it already exist somewhere else?
Thanks
Comment #22
a_lawry commentedIt's a while since I looked at any of this.
Yes that's correct the first lot of code added to your theme and the second to the uc_discounts module.
theme_uc_cart_block_content() is on line 667 of uc_cart.module in the ubercart/uc_cart module. That is not the latest version of ubercart so it may been rearranged lately. That is the theme function that displays the ubercart cart block and the one that you need to override in your theme to make changes to it.
Make sure you add the second lot of code to the module and that is working first. If drupal can't find that function the theme function will cause a white screen because it can't find the function and throws an error.
Comment #23
jdln commentedOK. Ive got it working if I removed this from uc_discounts.module (hallelujah!);
Mhel, what does this do?
One last thing, I want to get the pre discount price in the shopping cart block aswell. By pasting the following into my template.php I can add a table row in the correct place, but how do i call the original price?
Thanks so much to everyone, the help is hugely appreciated.
Comment #24
mhel commentedThat line just hides the label "Total discounts" if discount is not available.
The full line should look like this I added the braces for clarity.
For your second question, I'm not sure what you mean. On my setup I can see the pre-discount price like this (for a 10% discount).
item 1 $249.50
Qty. Discount $24.95
Total $224.55
Comment #25
jdln commentedAh, thanks for clearing up my first question.
As for the second question. Im viewing my cart block collapsed so currently it says;
15 Items £27.00 View cart
Ive removed the "Total discounts" text. 27 is the price with discounts applied. What I want to do is print the price before discounts (Ill use css to put a line through it);
15 Items £30.00 £27.00 View cart
Thanks again
Comment #26
mhel commentedIn that case you probably don't need your THEMENAME_uc_cart_block_content(), and just use THEMENAME_uc_cart_block_summary(). Make the changes from your original post with the lines with php tags. (take the tag off when you use it, that's the only way I know how to emphasize it inside code tags)
On my setup it looks like this:
22 items Total: $315.50 / $283.95
I'm guessing my responses is more suitable posted in a forum than in issues I'm new to php/drupal/ubercart pls. pardon me :)
Comment #27
jdln commentedWith your code im getting this;
3 Items £27.00 / £24.00
But my subtotal is £30 and the subtotal including discounts is £27.00.
If I only add the 2nd load of code then I get this;
3 Items £27.00 / £27.00
Thanks
Comment #28
mhel commentedTry not using your THEMENAME_uc_cart_block_content(), I mean discard that whole function if you're still using it.
If you examine that function you will see that it already use
$total - $discount_info['total']which get pass as a parameter toTHEMENAME_uc_cart_block_summaryand that is already the discounted value.Comment #29
jdln commentedUsing your code from 26 as well as removing what you suggested in 28 makes it works.
Thanks again.
Comment #30
jdln commentedOop, just realized when a discount is being applied i get this;
1000 Items £100.00 / £90.00
So far so good, but when a discount is not being applied I get this;
1 Item £0.10 / £0.10
When a discount is not being applied, how can I stop the price being shown twice?
This is what I have in my template.php
And this is what I have in my ub_discounts.module;
If I add this;
if ($discount_info)below this$discount_info = uc_discounts_cart_block_discounts(uc_cart_get_contents());in my template.php, then when discounts are applied the block summary looks normal, but the summary isn't shown if no discounts are being applied.So, what I need to do is stop one of these being shows when no discounts are being applied;
uc_currency_format($total)oruc_price(($total - $discount_info['total']), $context)Could someone tell me how to do this? This really should be the last change.
Thanks again
Comment #31
jdln commentedIt would be best if the uc_currency_format($total) wasn't shown when no discounts were applied, as ive added a span tag to this to apply a css linethrough to it.
Comment #32
mhel commentedTry the code below, I also changed the uc_currency to uc_price to do the formatting.
Comment #33
jdln commentedYour code works for no discounts but gave me a white screen if their were discounts. I played around a bit and got it working with this;
Which ive added my css to;
All working brilliantly! Thanks a lot.
Comment #34
davident commentedI had this same issue and have found that changing one line in the override function will correct the issue.
Here are the lines of interest.
//$total += ($item->price) * $item->qty;
//$total += ($display_item['#total']) * $item->qty;
Line 1 is the default setup that displays the total without discounts. Since each line item does show its correct discount, we just use that value to calculate the total, instead of $item->price.
Comment #35
jdln commentedThe code causes a white screen with the latest version of the module.
Comment #36
jrust commentedDuplicate of a newer 2.x issue: #909942: Discounts in Cart Block