Contrib type:
ModuleModeration:
Not ready for moderationStatus:
Work in progressCompatibility:
Ubercart 1.xA version of this module has been moved to drupal.org for further development. See this comment for more info.
This allows you to define discounts to be applied during checkout. Conditions and actions are supplied by submodules. The following conditions and actions are defined:
order_total:
- condition: compare the total price to a specified amount
- action: discount the total price by a specified amount or percentage
product:
- condition: Are there $qty number of $product in the order
- action: Discount a specified amount or percentage off $qty number of $product
role:
- condition: does the user belong to a certain role
Notes:
The Discounts module has not yet been well-tested with taxes.
Please use the drupal.org issue tracker for this module to post bug reports and help with future development of this module. The issue tracker here will most likely be closed as soon as any pertinent issues are migrated.
Project page on drupal.org:
http://drupal.org/project/uc_discounts

Re: Discounts
There are now three conditions (order total, product, and role) and two actions (discount from order total, discount products). Discounts are now seen on the checkout screens and do indeed get stored as part of the order. The Discounts contribution description has been updated, and a new file attached.
Re: Re: Discounts
The file is not in gunzip , but in bunzip
Re: Re: Re: Discounts
Force of habit. Reattached in gzip now.
Re: Re: Re: Re: Discounts
thanks a lot marshal. I think I would like it.
But I get following errors after adding a new discount:
* warning: Invalid argument supplied for foreach() in {mypath}\modules\ubercart\uc_discounts\uc_discounts.module on line 1637.* warning: Invalid argument supplied for foreach() in {mypath}\modules\ubercart\uc_discounts\uc_discounts.module on line 1669.
I'm too tired for checking the reason this night. Do you have an idea what wents wrong?
thanks.
Re: Re: Re: Re: Re: Discounts
This error is because you have no conditions defined, resulting in $condition_list being NULL. I'm uploading a new version which fixes this for conditions and actions.
Great work marshal! Thank
Great work marshal!
Thank you!
Some annotation:
- It would be cool, if the discount could be displayed at the shopping card.
- Like descriped in this thread: http://www.ubercart.org/forum/development/224/strange_behavior_hook_line... there's a problem with the set_line_item() function.
- I think it's better to group all modules (main and submodules) together (Otherwise people like me wondering, why they can't define conditions
Thank you
I agree with michels, you've done a great job with this module. I get a strange problem though - but it may be a result of my previous code "tweaking" of the other modules
Problem: After sending an order (with all correctly calculated values) I go to: admin/store/orders and get this warning: Invalid argument supplied for foreach() in /modules/ubercart/uc_discounts/uc_discounts.module on line 370.
Further more total sum is incorrect there. Sth like this:
Subtotal: 755,81 zł
Shipping Cost: 0,00 zł
Rebate: -113,37 zł
Total: 755,81 zł
Can you please help? Greets from Poland
I exactly have the same problem
I just test on a new drupal/ubercart/discount installation, and when I purchase a product, and then to display the order I have the following error :
argument supplied for foreach() in /modules/ubercart/uc_discounts/uc_discounts.module on line 370.
Re: I exactly have the same problem
foreach() can handle empty arrays, so what that's saying is that $cart is not an array at all. Looking over the code for uc_cart_get_contents(), this should not be possible.
The following adds a check for a cart which is not an array or is empty, for debugging purposes. It would be helpful to see if either of the messages below display when you get the error.
--- uc_discounts.module (revision 19)
+++ uc_discounts.module (working copy)
@@ -366,6 +366,16 @@
}
$cart = uc_cart_get_contents();
+ if (!is_array($cart)) {
+ drupal_set_message('Bad cart - is not an array.');
+ return array();
+ }
+ elseif (empty($cart)) {
+ drupal_set_message('Cart is empty, no discounts will be applied');
+ // nothing in the cart? no discounts
+ return array();
+ }
+
$cart_copy = array();
foreach ($cart as $cart_item) {
$cart_copy[] = drupal_clone($cart_item);
Discounts by Groups of products
Marshall,
Is there any way to offer discounts based on a group of products. ie I would like to offer 10% off the purchase of 3 or more widgets from category X
Impossible to remove a discount.
I tried to remove a test discount I just created, and when I go to edit, and press the delete button, I just return to discount listing and the deleted discount is still here.
Am I alone to have the problem ?
zmove
alpha7c updates
this problem, as well as the one described above, are likely a result of running alpha7c code without appropriate changes to uc_discounts.module to account for the updated checkout panes for alpha7c. Here's a patch which makes uc_discounts comply with this API change:
<?php--- trunk/5.x/projects/sites/scw/modules/ubercart/uc_discounts/uc_discounts.module (revision 443)
+++ trunk/5.x/projects/sites/scw/modules/ubercart/uc_discounts/uc_discounts.module (revision 449)
@@ -247,6 +247,5 @@
return;
}
- $pane = uc_cart_checkout_new_pane('discounts');
- $pane->fields['pane']['description'] = uc_cart_checkout_pane_description('discounts', t('The following discounts will be applied to your order:'));
+ $description = t('The following discounts will be applied to your order:');
// create discounts table@@ -276,12 +275,10 @@
$table = theme('table', $header, $rows);
-
$pane->fields['pane']['discounts'] = array(- '#value' => $table,
- );
+ $contents['discounts'] = array('#value' => $table );
// add line item$script = "set_line_item('discount', 'Discount', -$discount_total, 1)";
drupal_add_js("\$(document).ready( function() { ". $script ." } );", 'inline');
- return $pane;
+ return array('description' => $description, 'contents' => $contents, 'next-button' => FALSE);
case
'review':?>
Re: alpha7c updates
Thanks for the patch, it worked great. This was top on my list of things to do today, and you just made it a whole lot easier.
Re: Re: alpha7c updates
has the original .gz file been updated with this too?
About tax support
Hi there,
I'm posting here to speak about the integration with taxe system.
In the note below the module description, it says that the module is not well tested with taxes.
So I test, and it doesn't work.
I will try to make it compatible, The best way would be to add a checkbox in the tax module to check or un check if you want to apply taxes on the discount.
Re: About tax support
I made uc_discounts module compatible with uc_taxes module.
However, when you think about how tax have to be applied, you can easily conclude that the uc_taxes module have to implement uc_discounts and not uc_discounts that have to implement uc_taxes.
Why ? because taxes is a thing that have to apply at the very end of your order. When you calculate a discount, it have to apply to an excluding tax amount and, then, tax have to be calculated on the new price without tax. That's why it's more easy to understand and to implement in the uc_taxes.module than the uc_discount.module.
So I created a patch of the Alpha 7c uc_taxes.module. This is a very little and easy to understand patch.
I only changes some lines in the uc_taxes_calculate($order) function to substract the discount amount to total before calculating taxes amount.
It could be really great if uc_taxes.module could implement the uc_discounts inrtegration in core, to not be obliged to modify it each time an update is made.
This is the patch content
<?php--- D:/Taf/Kalys/Sites/drupal/sites/all/modules/ubercart/uc_taxes/uc_taxes_original.module Thu Sep 20 10:45:32 2007
+++ D:/Taf/Kalys/Sites/drupal/sites/all/modules/ubercart/uc_taxes/uc_taxes.module Thu Sep 20 14:31:14 2007
@@ -425,15 +425,31 @@
if ((uc_taxes_match_area($rule, $order)) && eval($conditions)){
$rate = $rule->rate;
$amount = 0;
+ $total = 0;
$debug = ' (';
if (is_array($order->products)) {
foreach($order->products as $item){
$node = node_load($item->nid);
if (in_array($node->type, $rule->taxed_product_types)){
- $amount += $item->price * $item->qty * $rate;
+ $total += $item->price * $item->qty;
$debug .= ' + '. $item->price;
}
}
+ // Start of uc_discounts implementation
+ if (module_exists('uc_discounts')) {
+ $apply_discounts = uc_discounts_apply_discounts();
+
+ if (empty($apply_discounts)) {
+ return;
+ }
+ $discount_total = 0;
+ foreach ($apply_discounts as $discount) {
+ $discount_total -= $discount['amount'];
+ }
+ $total += $discount_total;
+ // End of uc_discounts implementations
+ }
+ $amount += $total * $rate;
}
$debug = substr($debug, 3);
$taxed_line_items = $rule->taxed_line_items;
@@ -461,6 +477,7 @@
$taxes[$rule->id] = array('id' => $rule->id, 'name' => $rule->name /* . $debug */, 'amount' => $amount, 'weight' => $rule->weight);
}
}
+
return $taxes;
}
?>
zmove
Re: Discounts
I get the error "Fatal error: Call to undefined function: uc_cart_checkout_new_pane() in uc_discounts.module on line 249" when checking out, any ideas?
I really need this module to work!
Re: Re: Discounts
Yes, just apply the spiderman .diff....
Re: Re: About tax support
zmove, I don't really want to make a special case for discounts in uc_taxes because it already handles line items in general.
I looked into the discounts module because I thought that they were added as line items, but I think I know why taxes aren't able to pick them up. Firstly, uc_discounts doesn't implement hook_line_item(). This prevents Übercart modules from knowing that discount-type line items exist. Secondly, the discounts are applied to the order during the 'review' step, which is after the taxes are calculated in the 'process' step.
If someone could roll up a patch to do that, I think that'd be the best solution.
Re: Re: Re: About tax support
Thanks for your answer Lyle. I will try to modify the discount module, because I don't like to hack core, and if I hacked the uc_taxes.module, it's because I thinked that there were no alternatives.
Correct me if I'm wrong, but by looking through the code, I noticed that the tax module calculate the taxes by calculating the tax rate for each product. See this code in uc_taxes_calculate() that is called by uc_line_item_tax()
<?php...
foreach($order->products as $item){
$node = node_load($item->nid);
if (in_array($node->type, $rule->taxed_product_types)){
$amount += $item->price * $item->qty * $rate;
...
?>
So even if the discount module use the hook_line_item, I don't know if the tax module could correctly calculate the tax (maybe I'm wrong, I'm far to understand all drupal and ubercart behavior so, maybe I need more explanation ^^)
For the last point, I don't understand you Lyle, you say that the discount is calculated on the review step.. what do you mean by review step ? the order review page ? Because the discount module show the discount amount on a checkout pane, so I don't understand well what do you mean by review step.
regards,
zmove
Re: Re: Re: Re: About tax support
The function that builds the checkout pane gets an $op parameter. This parameter has three valid values: 'view', 'process', and 'review'. uc_discount_checkout_pane() only uses 'view' and 'review'. What it should do is calculate the amount in 'process', and then display it in 'review'.
The tax on the discount might be off, but only for discounts on particular products. Discounts to the order in general will also discount those taxes that apply to the discount line item. However, the tax rules can't distinguish between discounts on specific products like they can distinguish between product types. Might have to make a hook to deal with that somewhere.
Hi there,
After some test and some modification. The tax is well applied after the discount but only on the order review page. the tax is not well applied on the checkout page.
Lyle, you seems to say that the discount is calculated on the order review page, so I tried to put the discount calculation on the 'process' case. But it changed nothing, I already try to put the discount in a hook_line_item but it didn't change the checkout payment pane and it add an extra discount line to the order review page.
I upload the discount.module I obtain after a day of testing... My brain has reached his limit without succes...
Re: Hi there,
After some tests, I noticed a strange thing.
the Taxe don't apply on the payment checkout pane, but, if you choose your address by selecting it in the dropdown menu (when your address is saved). The Tax is recalculated and take care of the discount amount.
very strange.
Re: Discounts
I apologize for my absence from this. Unfortunately, our sponsor had a staffing change a while back, and decided to go in a different direction. As a result, it's difficult for me to keep up with this and work on the Discounts module. We are, of course, open to other sponsors.
Re: Re: Discounts
I need working role discounts for my project now - with user friendly display on checkout page:
item1 .......... $1item2 .......... $7
-------------------
subtotal ....... $8
discount(25%) .. $2
total........... $6
I am able pay for it some money, but I am afraid that my resources are not enough
But I can post you a lot of super Czech beer 
//sorry for my english
Re: Re: Re: Discounts
I've never had Czech beer.
I need to get this going as well. I just have a couple things on my list first.
patch: product class discounts and various bugfixes
the following is a patch that may be relevant to others using this module. it "fixes" a number of things in the module (whether they are "real" bugs or not- they didn't work the way we needed them to), and adds support for discounts based on product classes, in addition to individual products.
the core infrastructure of this module seems very solid, although there were a few issues (mostly covered in zmove's helpful post, many of which are addressed in this patch. one of the basic requirements we had, however, was to be able to apply discounts to all products of a given class.
this revealed some of the limitations of the extensibility framework that marshal has begun. overall, i think this framework makes a lot of sense, but a) doesn't cover enough cases, and b) has a few inherent limitations which are hard to address with the conditions/actions approach (more on that in a moment).
so first off, we added some support to the uc_discounts.module itself to allow for non-integer-based "items" to be provided by the sub-modules. in this way, we could add a uc_discounts_product_class.module (an initial implementation of which is included in the patch) which would allow the user to choose a product class for both conditions and actions, and thereby allow multiple products from the same class to "count" toward a given discount.
the rest of the patch to uc_discounts.module itself is mainly fixing a few logic errors and implementing the full range of operators. patches to uc_discounts_product.module effectively clean up the internal logic of single product discounts to conform to the needs of our clients (again, i'm not 100% clear what the original intention was here, but it didn't work for our needs, at least). apologies for the various debug messages in here, although maybe they will help understand what is actually going on in the dark corners of this module
the one limitation i found in working with the new product_class module was that it seems tricky to provide conditions/actions that can be used independently of each other. for example, when i first went to build a per-product-class discount module, i thought i should be able to simply provide a new type of condition, and use the existing per-product action to actually apply the discount. however, in practice i found i couldn't get this to work, because the actions callbacks seem to rely on the conditions, and vice versa. it's possible this can work, but i couldn't find a way.
beyond that, one of the things we'd like to have from a discounts module that it's not immediately obvious how to achieve with the current framework is the ability to show the user applied discounts at the product level. for example, if you buy a lot of buttons, you get them at a discounted rate. at the moment, the total discount is calculated and displayed in a separate table, but it would be nice to show the customer what the discount is per-button, in the list of products on the checkout/review order pane. this way, they could see immediately how much the buttons are costing them, without having to do the math (regular price shown in list - discount shown in separate table).
as always, feedback is appreciated, and hopefully all of this is of use to somebody. i've no doubt we'll be revisiting all of this stuff in the not-too-distant future, as ubercart evolves and our requirements grow
patch: multi/cross-product discounts and price-based conditions
following on from my previous comment, this patch adds support for discounts which apply to combinations of products/classes, and also implements a new "amount" field which allows for defining an additional conditional: if the product in question's sell_price is equal to the "amount" field, then it counts towards the discount.
the first piece of this is to allow for discounts where if customers buy a certain number of either buttons or stickers, in combination, then they get a bulk discount. i accomplished this in a somewhat hackish way, by extending the "items" field in the conditions/actions table to store a serialized array of products/classes, and treat them appropriately when considering whether a given order should get a discount.
this approach seems less than ideal, and i imagine that in a perfect world we could define any number of products/classes which would match a given condition/action. these should really be stored in a separate table, so that one could say "any combination of this particular product and this class of products should receive a discount" (at the moment, you can only choose a product *or* a class).
the second thing this patch does is to provide an "amount" field on conditions, to allow for selecting products/classes with a specific price. this allowed us to restrict discounts to only "regular priced" products, and not apply them to "on sale" or package products within a given class.
this feature is mostly working, although i've had a couple reports in the last day or so that something's not quite right and discounts are sometimes being mis-applied (still trying to track down this bug).
once again, any and all feedback is greatly appreciated, and we hope this code can be useful to somebody, especially if it contributes to increasing the usefulness of this module for the community at large
alternative approach to taxes support
I've implemented a slightly different approach to the same problem as described by zmove, and though it's not ideal, i thought i'd post it here for completeness:
<?phpIndex: uc_taxes/uc_taxes.module
===================================================================
--- uc_taxes/uc_taxes.module (revision 528)
+++ uc_taxes/uc_taxes.module (revision 529)
@@ -414,6 +414,18 @@
if (empty($order->delivery_country)){
$order->delivery_country = $order->billing_country;
}
+ # apply discounts to the order
+ $discounts = db_query("SELECT * FROM {uc_order_line_items} WHERE order_id=%d AND type='discount'", $order->order_id);
+ if (empty($discounts)) {
+ return;
+ }
+ $d_amount = 0;
+
+ while ($data = db_fetch_object($discounts)) {
+ // store as negative
+ $d_amount += $data->amount;
+ }
+
$tax_rules = uc_taxes_get_rates();
$subtotal = 0;
$taxes = array();
@@ -430,10 +442,13 @@
foreach($order->products as $item){
$node = node_load($item->nid);
if (in_array($node->type, $rule->taxed_product_types)){
- $amount += $item->price * $item->qty * $rate;
+ $amount += $item->price * $item->qty; # * $rate;
$debug .= ' + '. $item->price;
}
}
+ $amount -= $d_amount;
+ if ($amount < 0) { $amount = 0; }
+ $amount = $amount * $rate;
}
$debug = substr($debug, 3);
$taxed_line_items = $rule->taxed_line_items;
?>
Importantly, this approach avoids calling uc_discounts_apply_discounts, which seems to do strange things when called more than once on a given order.
As suggested by Lyle, I think this is probably better accomplished by having uc_discounts properly implement hook_line_item, so that taxes can (optionally) apply before/after the discount amount is considered.
This is brilliant!
This is exactly what I needed to make this module work, thank you.
final
Is it possible to post final version of discount module file, with all those revisions applied? I would really appreciate, because I badly need this working, but I don't know how to apply all these diff files. Thank you very much.
Re: final
Hey guys - anyone have the complete module? I tried applying the patches and I keep getting Hunk failed, malformed patch, missing header, etc etc. Nothing seems to be quite right.
If someone can post the complete tarball I'd be much obliged
Re: Re: final
I too would greatly appreaciate a working tarball. I went through and tried to apply the various patches. None of them apply cleanly, and based on the two hours of bug hunting I've already done, it appears that those that did run, often applied themselves into the wrong place. If I do manage to get it working, I'll gladly post what I have to this thread.
Re: Re: Re: final
Here's what I have. Not sure it's 100% functional, but I got it to a point where it's not generating parsing errors anymore.
Re: Re: Re: Re: final
Thank you for your repackaging surge_martin.
I tested your files and noticed several errors :
So, in fact, I have no error now, but nothing works.... I'm on alpha 8, maybe it need an integration with workflow... don't know.
Humm,
Humm,
Just testing this for a future project:
For me anything post the year 2037, flags the error 'End date can not be before the start date'?
Also, maybe 'Setting the end date in the past is pointless.' should be changed to read better to clients...
sorry to be a stick in the mud!
Not as good as the message on the tax module though - 'Misusing this field can really mess up your site. DO NOT BE STUPID.' - genius!
Anyway, back to my actual point; I too have the errors listed in the post above as well as the end_date error I have mentioned.
Is this to do with the repackaged file by surge_martin, or do I need to apply any patches for 7e?
Many thanks
Paul
Re: Humm,
I sent spiderman a PM asking for a most recent module, but haven't heard back yet. I'm hoping someone has the most recent / complete module that we can take and continue developing from.
Re: Re: Re: Re: Re: final
Same problem, on alpha8, discounts gets never applied even with the most large condition possible.
I'm thinking of getting back to alpha 7e because I NEED working role discounts.
Re: Re: Re: Re: Re: Re: final
I'm looking at getting a discount system going that uses Workflow-ng. So far it's looking like the discounts will be applied as items are added to the cart. This means that the product pages won't show the discount, but they'll see the difference in the shopping cart. Advertising the discounts in the product body or in blocks around the site should encourage customers to take advantage of them.
Re: Re: Re: Re: Re: Re: Re: final
Sweet! What's your status on that? Right now we're using a Product Kit to allow discounts on products, but some people are confused in thinking that, if they add the components one at a time, they'll still get the discount (which obviously is not the case at this point). So a discount system that allows for this type of functionality is wholly welcome.
Re: Re: Re: Re: Re: Re: Re: final
I agree with Lyle, we have to don't forget that the discount is a marketing tool, so the customer have to see them in product node discounted body, not only on the cart or checkout.
Re: Re: Re: Re: Re: Re: Re: final
What's the status of the module? I would be willing to help pay to have this module working with some new features ASAP. Anyone up for some paid programing?
Re: Re: Re: Re: Re: Re: Re: final
Hi
I got the role based discounts working. I'm using alpha8, and the uc_discounts.zip posted by surge_martin..
Since I just picked this package up, I don't want to mess up the code conduct or anything like it..
Just thought I'd post my discoveries, and see what Lyle or any other maintainer says. Also has to be said that I only need role based discounts, so none other tested.
1. The uc_discounts_condition_form_validate in uc_discounts.module, first lines is a numeric check on form value prop, this is not valid for the role condition, which doesn't have a value.
2. uc_discounts_apply_discounts() in uc_discounts.module, there is a foreach loop that checks operators. Now this thing kills the role condition: if ($c == 0) { $condition_groups[$i] = FALSE; } It does so, because role discount doesn't include a count_check. That leads to this test never passing: if (array_search(TRUE, $condition_groups) !== FALSE) {
Now after fixing those problems, the condition kicks inn, but discounts pane is never added to the checkout.
I fixed that by adding a separate products based action with a apply_callback to the role discount..But that is probably not the way it was intended. I'll look into that some more.
Edit:
Looked into it..
It looks like the sql statement in uc_discounts_product_apply function in uc_discounts_product.module doesn't fit the role discount need. The products are actions if it is a role condition, so that statement makes the condition_list empty, and the function returns 0, hence no pane.
If anyone is interested in diffs, lemme know(need to remove debug statements).
Anyways thanks for an uberproduct!!
thanks!
cool, working fine. What I'm missing is a module that grants discount on how many articles purchased.
Re: Re: Re: Re: Re: Re: Re: Re: final
Can you post a patch with your changes? Thanks!
uc_discounts update
I've tried to leave this code somewhat better than how I found it ...
Here are my changes since surge_martin's version:
This version installs and runs on a site with Ubercart alpha 8.
Admin options not showing up
Not sure why, but the only options that appear after install are to set user permissions. There is an empty bullet that appears in the Customer admin section. I'm guessing this is where the admin options would be, if they appeared.
Any ideas?
Thanks.
Re: Admin options not showing up
Thank you detour, I will try your discount improvement on a sandbox and I will give you feedback.
Hi,
Hi,
I'm having similar issues with the Admin options.
The link shows it pointing to http://localhost/shop/admin/store/discounts/valuehtml
but I can only get to it by going to http://localhost/shop/admin/store/discounts/value
Here is a picture.
http://img253.imageshack.us/img253/4350/discountsyw4.jpg
(The discounts menu item there is one I made manually)
Other than the link/menu stuff, it works great!
Fix for menu and other issues
Thanks for the reports back.
I'm attaching an updated version of uc_discounts that fixes the store administration path issues. The valuehtml path seems to be from a deprecated/incomplete feature. I've removed it and made one other small improvement to the menu code.
Also, I've corrected two lines of code that relate to showing the discounted price on the product's page.
Let me know if this resolves the issue, and if anything else comes up.
Re: Fix for menu and other issues
Thanks for all your work on this, detour.
The admin options for the Discounts module now appear. Thanks.
Still not having success with applying discounts.
I'm trying to set up roll based discounts. I have...
- set up new roll via rolls (called 10 Percent Discount)
- created a new discount (set to active, expiry date in 1 year, end processing and exclusive not selected, max discounts 0)
- set up condition (property: user roll, condition group: 1, CO: =, role: 10 Percent Discount)
- action (property: discount all prods of a type, product type: product general [a custom product class], quantity: 1, amount: 10%)
Modules: discounts, product, product type, role.
Results:
- discount not applied
- discount not showing up in product views or cart
Thanks.
Re: Re: Fix for menu and other issues
Hi
The role discount doesn't have its own apply_callback. It uses the action from the product discount.
The SQL statement in that function rules out any actions that doesn't belong to a product role.
In uc_discounts_product.module look for the uc_discounts_product_apply function around line 136.
Change:
$sql = "SELECT * FROM {uc_discounts_conditions} WHERE discount_id=%d ";$sql .= "AND property='product' AND item_id='%s' ";
$sql .= "ORDER BY condition_group, weight";
To:
$sql = "SELECT * FROM {uc_discounts_conditions} WHERE discount_id=%d ";//$sql .= "AND property='product' AND item_id='%s' ";
//$sql .= "AND item_id='%s' ";
$sql .= "ORDER BY condition_group, weight";
I've just commented it out for the time beeing.
Try that, and let me know how it works. I've changed some other things too, and can't remember if they were related to that problem. I'm working on sorting out the nodeapi hook to display discounted prices around the shop. It doesn't work for me atleast.
Discounts won't work
I installed discounts and configured one to work for a role. It doesn't work - when logged in as a user with that role, the product is not discounted.
I went back to the discount configuration, and changed the dates to see what would happen. There seems to be something wrong with the dates aspect of this:
I set the start date to 1/1/2007 and the end date to 12/31/2050 and when i try to save it I get an error message saying the end date can't be before the start date. I moved the end date back a few times, and it still gave me the same message. I moved it to December of 2008 and then it let me save it.
But, the discount still isn't working. It seems like there must something else wrong with the dates, and the system is treating this discount like it doesn't apply to the current date.
We have a bunch of students for our training program who need to receive this discount or they're going to get mad and confused. I hope someone can help us soon.
Thanks/
Re: Discounts won't work
Hi
Check the post above yours..
You need to get detours latest compilation, the tar.gz posted the 10th.
Then fix the stuff mentioned in the post above yours.
Another thing I've found is that when viewing your orders in /admin/store/orders..
And got my juice back, which I lost editing my posts..
The line items are correct. Like subtotal+shipping-discount and so on..But the calculation of the total, and thereby setting the payment/balance is actually based on the discount of the products currently in your cart.
Probably should've put that in a separate post
Working on that now. The order 'bug' that is..
role based discount is not working plz need your help
what i have tried is
1) installed this module into my drupal with ubbercart
2) applied role based disocunt.
3) created condition and action in discount configuaration
condition for : item1 10%
role: member (created by me means userdefined)
action:- in amount i have entered 20%
and when i do the transaction i cant see any discount / not in cart/nowhere plz
help me ....
thanx in advance...
Re: Re: Discounts won't work
Thanks for your reply; I'm sorry I didn't see those items before you pointed them out to me.
However, unfortunately, I tried both things you told me -- installed the newer version of the module and modified those lines of code, and the discount still doesn't show up - on the product detail, in the cart, or during checkout.
Any other idea? I really appreciate your help.
Re: Re: Re: Discounts won't work
Hi
Well, I reverted some changes and made a patch file..
There shouldn't be any other changes needed.
When you upgraded the uc_discounts module, did you get the drupal module upgrade notification?
Did you run the db upgrade?
After upgrading the module, you should've seen that all actions in your previous discount lost their titles.
What I did was to delete all conditions and actions in the discount.
Make sure it is still active.
Recreate the rolebased condition.
Recreate the discount actions.
And as I mentioned the nodeapi hook doesn't work. So the discount is only seen on the checkout pane. If it still isn't working, try to uncomment some of the drupal messages, and see where it fails.
Re: Re: Re: Re: Discounts won't work
I did upgrade the db after upgrading the module.
Can anyone tell me how to patch a module? I've been using Drupal in depth for about 2 years, but I've only upgraded modules -- I've never patched one, and I haven't been able to find any guidance on how to do that.
Re: Re: Re: Re: Re: Discounts won't work
Sorry for complicating stuff..
The patch isn't really needed. It was just to show that other than the SQL statement change, you shouldn't need to change anything else to get rolebased discounts to work.
So, if you made that change.
Try to uncomment some if the drupal_set_message's laying around in the code.
And see where it stops.
Re: Discounts
discount seen in drupal but when it is on sandbox discount disappears der and it shows the total without discount plz plz help me.........
thanx in advance
Roll Based Discounts
Hi. Just to summarize how to get roll based discounts working...
1. Install the latest version of the module (posted Dec 10th)
2. In the uc_discounts_product.module, change:
$sql = "SELECT * FROM {uc_discounts_conditions} WHERE discount_id=%d ";
$sql .= "AND property='product' AND item_id='%s' ";
$sql .= "ORDER BY condition_group, weight";
To:
$sql = "SELECT * FROM {uc_discounts_conditions} WHERE discount_id=%d ";
//$sql .= "AND property='product' AND item_id='%s' ";
//$sql .= "AND item_id='%s' ";
$sql .= "ORDER BY condition_group, weight";
3. Make sure the DB has been updated if a earlier version of the module was installed.
* The patch posted on Dec 17th is not needed.
** The discount will only show up on the checkout page at this point.
It is still not working for me. No discount function seems to run at all when I go to the checkout page. Any ideas? Thanks.
Re: Roll Based Discounts
I tried uninstalling and reinstalling the module once again, and it works for me now. Thanks.
A Patch for Multi Products
Using the latest .tar.gz (from Dec. 10th) I found two bugs that were causing the multi product module not to work. 1.) The actions data type seems to have changed so no discounts were being applied. 2.) There was no support for percentage based discounts. The attached patch fixes both of these problems. With the patch applied role based discounts are working fine for me with ubercart alpha8.
One other caveat to note, when creating an Action there is a field called Qty. It will apply the specified discount X number of times. Which means that you should at least put "1" for Qty or no discount will be applied.
Re: Discounts
is it possible to show the discount price on the product page at all? I haven't looked at the code yet but wanted to see if it was something that was in progress or not.
Re: Re: Discounts
Need to show the discount on product on the product page too. To have the original price in < strike> tag and the new price in a span, so custom the display.
And it could be great to have a new package to download instead of the original file + 1000 patches
Re: Re: Re: Discounts
+1 for a new package file
Update for uc_discounts
Attached is an updated version of uc_discounts. I've applied the fixes provided by kiruva and jrust, and added more support for discounting prices before checkout.
This version introduces a new administrative option regarding whether to apply discounts at checkout (the default in previous versions) or when a product is added to the cart. By selecting the latter option, discounts are not displayed as line items on the checkout screen, but are applied directly to the product's price when it is added to the cart. This does not work with every discount condition, as some are applicable only to an entire order.
I've had success using the product, role, and site conditions with the 'discount amount from order total' action. I have not tested the other conditions and actions extensively.
Re: Update for uc_discounts
Thank you for your package, I will test that on a sandbox and will give you feedback
Ok after some tests,
First thanks for taking time to provide us a release containing all patch and improvements done.
I tested the last package and I have some comments, bug report.
About conditions
About actions
<?php# user warning: Table 'SANDBOX.uc_discounts_conditions' doesn't exist query: uc_discounts_multi_product_apply SELECT id FROM (uc_discounts_conditions) WHERE discount_id=8 AND property='product_multi' ORDER BY condition_group, weight in /includes/database.mysqli.inc on line 151.
# warning: in_array() [function.in-array]: Wrong datatype for second argument in /sites/all/modules/ubercart/contrib/uc_discounts/discounts/uc_discounts_multi_product.module on line 130.
?>
The problems seems to come from missing {} in SQL declaration because I have prefix to my tables and my uc_discounts_conditions table equivalent id dp_uc_discounts_conditions. So by writing {uc_discounts_conditions} in your code instead of uc_discounts_conditions, drupal will automatically add table prefix.
Most of conditions seems to work, just need a little work. But the actions need a real rework because pratically nothing work (or maybe I made something wrong, can others testers confirm or infirm if it works or not ?).
Another remark, the discount system don't use the hook_line_item to add the discount in checkout pane. It should, because ATM it is not compatible with taxe module, so this part of the module should be rewritted by using the ubercart hook.
Re: Ok after some tests,
zmove, what version of ubercart are you using? I have only tested it with alpha 8...
Yet another update for uc_discounts
Attached is an updated version of uc_discounts. As zmove notes, recent versions of uc_discounts do not save discounts as line items, and therefore are not compatible with uc_taxes. In this version, I've changed how discounts are saved from a simple modification of the order total (via hook_order) to an order line item. I've also fixed the table name problem that zmove reported, and changed uc_discounts_role to allow discounts based on the 'authenticated user' role.
@zmove, Thanks for your thorough status report on the discount conditions and actions. Can you verify that role based discounts aren't working? They work on my site (and are the primary condition that I've been testing). I'm using a role condition with a 'discount amount from order total' action.
Re: Yet another update for uc_discounts
Many thanks detour, I will try your modification as soon as possible.
I don't know if you are agree, but, by regarding all the great work you make for this module, it could be good you take the module maintain role.
I will give you feedback when I will test the module. Actually I'm updating my ubercart installation to beta.
Re: Yet another update for uc_discounts
After doing a fresh install of the above module, I've had luck viewing the discount as a line item. Granted, I'm not using the taxes module so I cannot comment there. I'll probably have to throw together a sandbox to check out role based conditions. Has anyone done this already?
"End date can not be before the start date" error seen
I'm using Ubercart-beta2 with the uc_discounts-20080107.tar.gz contrib package on Drupal 5.6 with all installed modules up to date.
While creating a discount, I am incorrectly seeing the error message: "End date can not be before the start date" when entering an End Date > Jan 17, 2038. The start date is set to today: Jan 22, 2008. Looks like and EPOCH/ date/math issue. Sorry I haven't into the code to nail down any further. It's been a looong day but I wanted to get this reported asap. I'll continue testing this contrib as I need it for a site under development.
Thanks again guys.
BTW, the UberCart team is awesome. I think you guys epitomize the meaning of Open Source TeamWork!!!
Keep up the great work!
G
I've created an issue for the above problem
http://www.ubercart.org/issue/2785/end_date_can_not_be_start_date_error_...
Hello
Hello
First of thank you all for this great module. Solved a lot of troubles i had with other e-commerce modules..so thanks again
As usual, after the "thank you" comes a question
This is more like a feature request but maybe you guys can think another way to accomplice this.
I would like to configure a discount for products that belong to a specific category term.
Exxample: I have create my catalog and i have also another vocabulary called "promotions" with terms "suggested", "offers" etc. When i assigned a product to the term "offers" i want to receive a 10% discount.
Is this possible?
I guess not with the current version (btw im using uc_discounts-20080107 is this the latest?)
Can anyone suggest an alternative to achieve such functionality?
Thank you
PS
i just realised that i have installed the discount under module directory and not under /modules/ubercart. Is this a problem?
In addition i can not delete the discount. The problem has been solved but it seems it not included in the uc_discounts-20080107. Where i can find a release with all corrections?
Role based discounts
I have not been able to get role based discounts to work:
I have a rule to apply a 10% discount to a certain role.
My system:
Ubercart Beta 3
Drupal 5.5
Database schema Up to date
File system Writable (public download method)
GD library bundled (2.0.28 compatible)
JQuery Update Installed correctly
The current installed version of JQuery is 1.1.2
MySQL database 4.1.16
PHP 5.0.4
Web server Apache/2.0.54 (Fedora)
Let me know if you would like me to try/test anything.
Paul
Extreme Sports
Discounts based on number of products
Greetings all,
I am just trying to create a 20% off discount when a customer orders 2 or more products.
I can't seem to figure out the appropriate settings to use with this module. Can it be done? If not, does anyone have any pointers to find a module that does?
Please let me know when you get a chance,
txcrew
Re: Discounts based on number of products
It seems, that in Beta5 there are some things not working.
For me it's only the "Order total"-Condition that works well. The "Product" and "Product-Type" Conditions doesn't seem to have an effect.
Also, you can't delete Discounts anymore.
Is there anyone who is contributing this module anymore? I think it's quite easier if the one who writes that code makes the adaptions. For me it would take a lot more time.
Great module so far!
Re: Discounts
Had a problem with varying prices within a class when using class-based discounts.
I fixed it here: http://www.ubercart.org/issue/3347/fix_product_classtype_discounts_varyi...
Do I have this right?
First off, thanks hugely for this module, I was just pondering how to set up this type of discounting and came over here, and lo, there it was! But I'm not at all sure I understand how to set up what I want. A screenshot of what I have setup in the discount config screen is here -- http://www.crypticsites.biz/discount_exmpl.gif
What I need it to do is, if someone is purchasing "Blue and Gold Elegance- Custom" *and* they have the role of DIY011, they get a discount of $24.95 -- from looking at the screenshot, do I have it setup correctly? I don't know if I get that "group" thing in the Conditions -- I need both conditions to be true for the discount to apply.
Hope you can clarify this for me...
Also... I grabbed the file that was first listed in this thread; since I'm not doing taxes, do I need to worry about that latest update? I have ubercart 5.x-1.0-beta5, drupal 5.7.
Thanks a million,
Andria
Edit: I removed the 2nd condition, as on further consideration, it seemed unnecessary -- correct?
Also, is the discounted price supposed to show in product-list, or when viewing the product, or in the cart -- or only when they get to the checkout page? I created a user with the appropriate role setting -- DIY011 -- to see if the discounted price showed when viewing the product, but it doesn't; so I don't know if it's supposed to, or if I just don't have it setup properly?
Please advise, pretty please!
Discount on Product and Attributes
Thanks to those taking on this project and updating it. Its a much needed contribution. I know that the product discount actions aren't working yet (Am I wrong here?) however I am wondering if when they are applied are they applied separately to products with separate attributes?
i.e. if i have a product shirt and attributes red and blue and a product discount 10% discount on 2 or more shirts and someone purchases 2 red shirts and 1 blue shirt. Are the red shirts discount and not the blue? or are all three discounted?
Sorry if that's a bit confusing.
Best,
Nathan
Re: Discount on Product and Attributes
Great module guys.... really really great work
bug in uc_discounts_product.module
On line 222, I believe
$action->qty
should read
$product->qty
I did this change and it fixed my problem.
Cheers
I second this
I, too, think it would be a great feature to setup discounts for a specific taxonomy term. This would save users a lot of time setting up discounts for a lot of items under a few/many categories.
Thanks! Great module, btw!
Conditions and properties empty?
First of all, thank you all for the hard work you seem to have put into this module already. I was quite relieved when I stumbled over this, as it seems to be exactly what I'm needing at the moment...
...if I could only get it to work, that is.
Unfortunately, I seem to have a problem that no-one else has mentioned so far: When I create a new discount and try to "add conditions" or "actions", the according boxes are completely empty! I.e. I can't set up any discount condition or action. (Tried the last two versions posted in this thread with Drupal_5.7 and Ubercart_beta6.)
Or have I misunderstood anything? Is there anything else that needs to be set up before this module works at all?
Thank you very much in advance,
Marcus
Looking for new maintainer
After not checking on this for a while, I'm surprised I'm still the maintainer here. I am, unfortuntately, unable to maintain or develop the discounts module. Anyone who wants to take it over, feel free, and do what must be done.
No Property?
I have the exact same problem as Marcus. Their is nothing to choose from in 'Property' when adding a condition or action?
Order modify and Discounts
I am having two problems with the discounts contrib and the admin order edit screen:
1- It does not delete the lines by clicking in the (x) button (i think that this is a general issue, as it doesn't allow me to delete shipping lines or taxes)
2- When you save a order from the admin screen (store/orders/XX/edit), the discounts get lost, it always points 0, because it gets the data from the cart, and if you edit a order from the administrator account, you dont have the cart.
In the uc_discounts_apply_discounts function, this call:
$cart = uc_cart_get_contents();should be substituted for some queries that get the current order and not the cart.
I am working in a fix for #2 right now, i have no idea of how to solve #1, any suggestion?
Re: Discounts
Why not create Workflow-ng conditions and actions as well as an event? This will prevent the having to write separate code to do what Workflow-ng (Which is required install for Ubercart) can do. You can then focus on creating the actions and conditions. I've delved a little into Workflow-ng anc I can help in any way needed.
Some corrections
I've made some corrections to uc_discounts module and uc_discounts_product module.
uc_discounts:
Now the order modification by admin doesn't put 0 to discounts, that was produced because this function was used:
$cart = uc_cart_get_contents();
And if you are admin, there is no cart to modify.
I am attaching the module modified, the details are these:
line 405 (uc_discounts_order):
$apply_discounts = uc_discounts_apply_discounts($arg1->products); // array of products that substitutes the cartline 433 (uc_discounts_apply_discounts):
function uc_discounts_apply_discounts($products = NULL) { // function declaration modifiedline 440 (uc_discounts_apply_discounts):
//If the function is called from other places, cart is loaded, if not, current products are usedif (!isset($products)) {
$cart = uc_cart_get_contents();
}
else {
$cart = $products;
}
uc_discounts_product:
It was mandatory to introduce the number of products that will be affected by discount. Now if you put 0, all the products in the cart that accomplish the condition will be affected by discount. If you want 0 products affected, simply deactivate the discount.
I am attaching the module modified, the details are these:
line 197 (uc_discounts_product_apply):
$qty = $product->qty; //the quantity is stored for later use.
line 222 (uc_discounts_product_apply);
if ($action->qty != 0) { //use the quantity stored if the quantity of the action is 0$qty = $action->qty;
}
$discount = $product_price * ($discount_percent * $qty);
Feel free of comment and correct this code!
Workflow-ng and Taxonomy
Hi
I think that greenSkin has totally the point, this module should be adapted to workflow-ng for condition, actions and events, as the taxes module does. I offer my help too, if needed.
Btw, until this is defined, I am working in a taxonomy-based condition because i need it now, i will publish it when finished.
edit order bug
Thanks for fixing the 'edit order' bud, it was very annoying.
May I ask who has the power to remove the current maintainer of the module, since there is such interest in developing/using discounts in ubercart. Using workflow-ng and actions is a must IMO, so the guys that wrote about it should take the future of this module in their own hands.
Re: edit order bug
Anyone interested in maintaining should feel welcome to simply start a new contrib for it. Once it picks up steam, I can tweak this one to direct users to the new one or something. You should use the contrib's issue tracker for issues to prevent the monster-thread or maybe even consider making it a project on Drupal.org.
Re: edit order bug
I just need someone to specifically say they want to maintain this module. If marshal doesn't show up to defend his claim, I can just change it to whoever.
More corrections and taxonomy support
Hi
I've developed a little taxonomy module, which provides basic discounts based on categories. I have tested to my local site and it seems to work ok, please tell me if you find any issue.
And I post a few more corrections on the discounts module:
On uc_checkout_pane_discounts, the discount amount is checked, if it is 0, the line is not shown
This has been added at the end of uc_discounts_apply_discounts, I think that this fixes the "End processing" feature.
if ($discount->do_end_processing) {break;
And I've commented these lines in uc_discounts_product_apply function of uc_discounts_product module, I am not really sure of what they do and are fatal when two or more discounts are applied.
// remove affected items from cart/*foreach ($product_found as $cart_index => $product_count) {
$cart[$cart_index]->qty -= $product_count;
}*/
I am uploading the whole module.
Referencing the maintainer issue, I can provide some bug fixes like I am doing now, but I really don't have the time for doing the huge work required, which would consist in migrating the entire module to workflow-ng.
Feedback is appreciated!
Re: Discounts
Thanks to all who worked on this module. I got it working wonderfully in my sandbox. Unfortunatly it doesn't work online for me.
Any idea why it doesnt't work on the live site, while in the near identical sandbox it does? I don't find the difference that hinders it from working. I added the discount the same way and set it up the same way. The discount-Pane in Checkout-settings is enabled too. I don't get no pointers as to where the problem could be. Any thoughts greatly appreciated!
Tax
Hello!
I installed the Discount module. It's great! But I'have two problems:
Subtotal: $120.00
Discounts: -$12.00 (120 * 0.12)
Taxes: $30.00 (120 * 0.25)!!!
Order total: $138.00
It should be right:
Subtotal: $120.00
Discounts: -$12.00 (120 * 0.12)
Taxes: $27.00 ((120-12) * 0.25)
Order total: $135.00
I hope, the development to live on.
Re: Tax
I just want to point out the original maintainer's post again:
http://www.ubercart.org/contrib/143#comment-14742
Until someone takes over or devises a new discount contribution, these problems will probably not be solved.
Right, thanks Ryan. Just
Right, thanks Ryan.
Just want to add that this module must be dependant on some kind of server setting that i can't figure out. I narrowed it down to that. I copied all files from my livesite down to a local XAMPP-sandbox and dumped the database and use it for the sandbox. Now i have a TWIN copy locally. The only difference is that the XAMPP sandbox has no server-restrictions and all functions installed. The discounts are not shown in checkout online, but are working super in the twin-sandbox.
How do i figure out what's missing in the live server.
Re: Right, thanks Ryan.
Maybe if you copy and paste the status report (admin/logs/status) from your live server, someone will be able to tell you where is the problem.
Here it is: Drupal:
Here it is:
Drupal: 5.3
Filesystem: writable ("public" Download-Method)
databaseschema: uptodate
config file: safe
MySQL-database: 5.0.32
PHP: 4.4.4-8+etch4
Unicode library: PHP mbstring-Erweiterung
Webserver: Apache
Site is: http://www.hopsa-themaheft.de/
I have no severe errors in watchdog with this site.
Re: Here it is: Drupal:
I never tried it on PHP 4.x, is this the same version on your sandbox?
Re: Re: Here it is: Drupal:
Where it works locally is:
MySQL-Database: 5.0.51
PHP 5.2.5
Unicode-Library: PHP mbstring-Erweiterung
Webserver: Apache/2.2.6 (Win32) DAV/2 mod_ssl/2.2.6 OpenSSL/0.9.8g mod_autoindex_color PHP/5.2.5
Re: Re: Re: Here it is: Drupal:
Obviously the problem is in the PHP version 4.x - I never ran ubercart on 4.x
Re: Re: Re: Re: Here it is: Drupal:
Thank you acdtrp for pointing me to this. Can anyone confirm that discount won't run with PHP4?
Re: Re: Re: Re: Re: Here it is: Drupal:
THANK YOU acdtrp. Confirmed! Discount as of the last version above does not work on PHP4.
I was able to use Xampp's phpswitch. Switching to php4 - no discount shown in checkout. Switch to php5 - discount shows in checkout. I am such a noob - sorry for the many postings, dear forum. But so reliefed to have found the answer.
Can't delete discounts
Hi guys,
There seems to be a problem with the removal of discounts. Probably data is POSTed to the wrong location or incorect data is being posted because the action (uc_discounts_discount_delete_form_submit) is not triggered. I'm sure u dev guys know what the problem is, this being an older issue and all..
I installed the latest version of the module (the one released on March 25th) on drupal 5.7 w/ php 5.
This module is brilliant! 10x!
Re: Discounts
Nice module. I've installed it on my site, but and set up a test discount, but it doesn't seem to be applying to orders. I'll keep playing with it, as it's probably something I've done.
It would be really useful if you could set up discounts based on taxonomy terms, which doesn't seem to be possible at the moment. I would would like to discount all products from a particular manufacturer.
Thanks for this, hopefully I can make it do what I want.
James
Quote:It would be really
It would be really useful if you could set up discounts based on taxonomy terms, which doesn't seem to be possible at the moment. I would would like to discount all products from a particular manufacturer.
James, what I wound up doing is creating 'classes' of products, and applying discounts based on those. Each 'class' in this case, is a manufacturer. Classes in Ubercart are different node types, so you have to re-think your presentation based on node types rather than taxonomy for the Brand. It's working for me, and I thought I would offer you an alternative way to approach this problem.
Take a look to my last message
I've developed a little addon for taxonomy discounts
http://www.ubercart.org/contrib/143#comment-15488
Can anyone please help?
Hey,
Am I missing something or does the discount removal not work? I installed the latest version of the module (the one released on March 25th) and i can not delete discounts.
Re: Discounts
I've been playing around for hours now, but it doesn't seem to work. What does work: Giving discounts for specific products. I though want to be more flexible. So, I wanted to add a discount for a whole product class, but it doesn't do it...
Attached are my settings for the discount. Any Idea, what this could be????
We'd pay 50€ to someone
We'd pay 50€ to someone who fixes the discount module for it to work in php 4.4.4
http://www.ubercart.org/contrib/143#comment-15575
Contact: Stephan Möbius, stephan.moebius@koelnerverlagsagentur.de
Change the action
Hi
The action for discounts on product types should be this:
Discount product type price from order
And makes a discount in percent or amount of the products affected by the condition of product type.
The action of your screen shot is for discount for total order.
Regards
had the same issue
To have something to choose there you have to enable all submodules. I hope this helps.
Discount Product Price from Order Issue.
I am trying to set up a percentage discount that will apply to item X if the quantity of X purchased is > 100.
It doesn't work to take the percentage off of the entire order because if other items are included they will also be discounted.
It also doesn't seem to work to discount the product price. The issue is that, if I set the quantity (to discount) at 100 it only discounts the first 100 items (i need it to give the same discount if 150 items are purchased) and if I set the quantity higher it gives a discount as if that number were purchased.
Am I missing something obvious?
thanks
Sounds doable
I am trying to set up a percentage discount that will apply to item X if the quantity of X purchased is > 100.
Doable
It doesn't work to take the percentage off of the entire order because if other items are included they will also be discounted.
Do you want to take the percentage off of the entire order or not? Your sentence the way i understand it is self-contradicting to me.
It also doesn't seem to work to discount the product price
Works here.
The issue is that, if I set the quantity (to discount) at 100 it only discounts the first 100 items (i need it to give the same discount if 150 items are purchased)
Use the workflow and set it >=100 instead of =100.
I can't help in detail but at least from what i read from you it all seems doable to me with the last version of the discount module above. Spent some more time with it - I am sure you'll figure out a way.
Thanks and an issue worth noting
Thanks Stephan, I hadn't thought to use operators in the actions area. Works perfectly.
There is an issue that might matter to someone at some point. The quantity box on the "Discount Product Price" page allows only 4 characters.
jason
why cannot i add conditions
for some reason, i can add actions, but when i add conditions, nothing gets recorded/added. can you tell me why?
conditions cannot be added
not sure if my last message get posted. sorry if i am redundant. i was able to add actions. but when i add new conditions, it does nothing. can you tell me why? thanks.
Re: conditions cannot be added
What do you mean?, the conditions are not really added or they get added but not working?
Problem with Product_type and Shopping cart.
Hi all. Thanks to everyone who has contributed to this module (and to Ubercart in general: Its Awesome!)
Ok, here goes: I have a problem with discounts when using 'Product Type' as a condition. It may be related to the fact that the 'product' is a sub category (term) of the available option in the select Product Type list, but thats just a guess.
Top level: "Conference Registration" -> "Conference Name" -> "Location" (All sub terms of 'Catalog')
The problem... in this case, I've added three conditions. A minimum 'Order Total'. "member" as the 'User Role' and "Conference Registration" as the 'Product Type'.
The 'Action' is to add a discount to the Order Total.
Side note: I have the module set to add the discount immediately (rather than during checkout as there appears to be issues with calculating the correct tax (GST) when doing it that way).
The above options appear to work perfectly at first... The item is discounted by the correct amount (when a user with the correct role permissions is logged in) but, when i add the item to the shopping cart, it reverts back to the full price and ignores the discount. I have tried all sorts of settings, changing the order of things etc. but nothing seems to help.
I can get around this by using 'Product' instead of 'Product Type' but we will be selling tickets for 11 locations... and then there are things like "Early Bird Rates" and bulk discounts, etc... so it is very time consuming to add a new discount for each 'product'... in each location...
Other than this little 'bug'... I like what the module can do so far and only wish I had the programming skills to fix and improve on this.... I will be working with this for the next couple of months and hope to have a more 'solid' discount module by the end of it.
Any ideas, suggestions appreciated.
PS. This may help someone else. It is critical to get the order of the conditions right. In the example above, I had to 'weight' the conditions so it looked for 'Order Total', 'User Role' and 'Product' in that order. If i forgot to 'weight' any of the items, the discount for that product would not work....
more details please & correction to a couple of bugs
Hi
The product type discount is minded to be a very basic module. I am not sure of what is happening to you, but I've corrected a couple of bugs I've found. Try this version (I've tested on RC2)
I've also corrected a bug that I was experiencing in main discounts module, there was no way of deleting discounts, now I can, has this happened to anyone else?
PS: Yes, weight is mandatory to indicate the order of the discounts to apply.
10x for the update, pcambra!
pcambra: I've also corrected a bug that I was experiencing in main discounts module, there was no way of deleting discounts, now I can, has this happened to anyone else?
I have been experiencing this bug also... (a couple of other users have reported this bug too on this thread).
Re: 10x for the update, pcambra!
Any chance there's an easy fix to get this module running in PHP4.4? Perhaps it's just a few lines of code that make it incompatible.
The person who fixes it will earn 50€. http://www.ubercart.org/forum/bounties/4135/50€_fixing_discount_module
Multi Product issue
Thanks for the update pcambra. Everything is working great for me but Multi Product discounts. I just can't get them to apply. I did notice that when I try to select items in the Conditions group they don't actually get applied. Here is what I get (item remains blank in the condition column):
ConditionsGroup Weight Property Op Item Value Actions
1 0 Multi Product <= 50 edit delete
Actions
Property Weight Item Qty Amount Actions
Discount 0 a:2:{i:0;i:83;i:1;i:25;} 50 25% edit delete
Discounts and PayPal issue
Hi. I am having an issue with Discounts module and PayPal.
When user goes to PayPal to pay for the order he gets full (not discounted) price to pay.
Would appreciate any help to solve this issue.
I use Ubercart alpha8.
Re: Discounts and PayPal issue
Probably won't be much help for ya in Alpha 8. You can try making sure that you're submitting the order to PayPal as a single line item in your PayPal Website Payments Standard settings. That's the only thing I can think of.
Re: Multi Product issue
@Heaiser: Same issue here. I figured out that conditions actually save the items. So they are not handled properly. I have not the time to track down all bugs now, but I found a way how to get it somehow working:
The condition I replaced by "Taxonomy", setting Op to "!=" and the value I left on "0", so the required condition is always triggered.
The action I handled like you did except using percentage for the amount. Only drawback is if you want to edit the action, the array of products is not applied to the multiple select-box. Can't be hard to fix, but I still didn't find it.
Hope this helps. IMHO it is a shame that this basically brilliant module has no maintainer. But we should at least put efforts together to make a base from it on which Ryan's UC2 plans can build.
Best regards,
Al
A bug I came across
Thanks for the recent updates and bug corrections. On the Discount Settings, the option that allows you to view the discounted price "When a product is added to the cart" is not working. It could be just my system. But I updated my Discount Module with your updates and everything else seems to be working for me but that.
Some corrrections for better styling
<php/**
* Implementation of hook_nodeapi().
*/
function uc_discounts_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
if (variable_get('uc_discounts_product_discount_price', 0) && $op=='view' && in_array($node->type, array_keys(uc_product_node_info()))) {
$product = node_load(array('nid' => $node->nid));
$discount_price = uc_discounts_product_discount_price($product);
$node->content['display_price']['#value'] = '<div class="display_price discount_price">'. uc_currency_format($discount_price) .'</div>';
if (variable_get('uc_discounts_product_full_price', 0) && $discount_price != $product->sell_price) {
$node->content['sell_price']['#value'] = '<div class="sell_price">'. uc_currency_format($discount_price) .' <div class="discount">('. t('discounted from') .' '. uc_currency_format($product->sell_price) .')</div></div>';
}
else {
$node->content['sell_price']['#value'] = '<div class="sell_price discount_price">'. uc_currency_format($discount_price) .'</div>';
}
}
}
?>
I just add a class to discounted price for better styling. If somebody want to hightlight it for example. Now it can be done with css.
Roles and No Actions
Am I missing something, when I attempt to apply a discount based off a users role, I can apply the condition, but there are no options for the roles.
Is there a way to create this?
Re: Discounts
Anyone have a working version of this thing? There've been recent threads about it, but the versions listed on this page simply don't work- Fields don't populate, things can't be deleted, etc. Massive, critical problems.
-Jeff
The version by pcambra
The version by pcambra should work for you. There are some issues, reading this thread will sure pay off for you. Out of curiosity I just tried a role discount and discounts are applied for the selected role. Good luck.
discount version pcambra & taxes
Hi pcambra,
First, thanks for putting all the chunks of code and patches together in one folder!
For me, I'm only interested in giving a volume discount on specific products (modules: uc_discount and companion module product).
I've read the threads and realize there are problems with applying taxes. Some solutions are suggested, is there one I can implement in my case (only volume discount + taxes?).
'Cause I still experience problems applying volume discounts and taxes to the same product.
Any suggestion, patch or anything is welcome!
I don't mind messing with the tax module of it gets me where I want to be.
Thanks in advance!
New User Condition Module
Hi Everyone,
First I would like to thank everyone who has contributed to this module. Second, I thought I would contribute an additional "Condition" module. I needed the ability to set discounts based on particular users. Most of this code was taken from the uc_discounts_role module. This is my first completed module for Ubercart and Drupal so somebody with experience please look over my code. Also, I could not find information regarding how to contribute modules anywhere on ubercart.org, I think partially because they are moving all modules to d.o, so please include this with the uc_discounts module. Hope someone else get's to benefit from this contrib.
Cheers,
Jon Antoine
www.antoinesolutions.com
Re: New User Condition Module
What is the status of this module? AntoineSolutions has submitted a patch at http://drupal.org/node/275404 for the Ubercart Ajax Attribute Calculations module to support uc_discounts, but I'm wary to do that for a module that appears to be abandoned. Since the original creator has asked for somebody else to take over....is there anyone else willing to maintain this module, compile these various zip files and patches, and put it on drupal.org?
Some Tips & Tricks
I’ve spent a lot of time trying to get this module to work.
I’ve written up my experiences as a mini FAQ, so I hope it will save other users some time:
Mini-FAQ
Note: This mini-FAQ focuses on the quantity discount, as this is the only option I have tested out.
Does this work with Ubercart 1.0?
Yes
Does this work with PHP 4?
No. You need PHP 5 for this to work. It will install under PHP 4, but it wont function correctly (for example, you wont be able to delete discounts). A bounty is being offered to correct this
Which version should I install?
The latest version is posted by pcambra You can find it here.
However, when I installed it, it only seemed to half-install. For example, on the modules page (yoursite.com/admin/build/modules), there were only 3 plug-ins listed under “Ubercart – discounts”, instead of 7. The settings tab on the discount page (yoursite.com/admin/store/discounts) was also missing.
I overcame this problem by:
a) uninstalling the module,
b) deleting it from the server,
c) installing an older version of the module,
d) uninstalling the older version
e) deleting the older version from the server
f) reinstalling pcambra’s version
g) running the update script (yoursite.com/update.php)
How do I get the quantity discount to work?
The quantity discount (e.g. 20% off when you order two or more of 1 product) seems to be a bit buggy. Here are the settings that worked for me:
a) Ensure the Product option is installed (yoursite.com/admin/build/modules).
b) Under discount settings (yoursite.com/admin/store/discounts/settings) ensure “At checkout/to the order” is checked and the two tick boxes for the last two options are ticked.
c) When you create your discount, ensure the quantity field for the “CONDITION” option has a value, while the quantity field for the “ACTION” is left blank.
d) It seems you have to create a separate discount for quantity condition/action pair for each product on your website.
What are the pros & cons of the module?
Once installed, the module works excellently (although, so far I have only tried quantity discounts). The only real downside is that you have to create a quantity discount condition/action pair for each product. This is very time consuming and it would be much better if you could set a global value (e.g. receive a 20% discount when you order two or more of any 1 product).
simple discount on product and working with views
Hi all!
The discount module has several really good options, but I couldn't create the simplest one (maybe it is).
I would like to make a discount on product items. Show it on the node side: list price, discount price.
workflow:
1. make a discount condition
2. assign the condition to a product
Abilities:
1. Show on product full-page mode and teaser that this is a product with discount.
2. make views by view module on nodes, that have the defined discount.
How I understood, the modul makes discounts through ordering. Is it possible to make the above described discount type with the uc_discount modul?
How can we make the module working together views?
Suggestions are welcome!
Thanks!
Daniel
Hi all To Al: I am sorry, I
Hi all
To Al:
I am sorry, I can't work on that multi-product issue now, any help / modifications are welcome! The options comparison is a little confusing :S
To braah:
Yes, there is a issue with taxes, I don't know how the relation between these two modules, as I said to Al, any help /suggestion is welcome!
To littly_kitty:
Thank you so much for the FAQ, It is very useful. And I am working in a simplified way to establish a discount based on a single product (probably from each product page). For getting a 20% for a bunch of products, i will suggest to use the taxonomy discount addon and assing a category to each product you want discounted.
To andan:
I am showing "by theme" the "real" price of discounted products striked and the discounted price using this custom function, hope that it helps. But there is no integration with views:
function get_real_price($nid) {$node = node_load($nid);
$sql = "SELECT uda.amount
FROM uc_discounts ud
JOIN uc_discounts_conditions udc ON (ud.id = udc.discount_id)
JOIN uc_discounts_actions uda ON (ud.id = uda.discount_id)
WHERE udc.property = 'product'
AND uda.property = 'product_from_order'
AND from_unixtime(ud.end_time) > now()
AND uda.item_id = %d";
$result = db_query($sql, $node->nid);
$amount = db_result($result);
if (substr($amount, -1) == '%') {
$discount_percent = substr($amount, 0, -1) / 100;
if ($discount_percent > 1) {
$discount_percent = 0;
}
$price = $node->sell_price - ($node->sell_price*$discount_percent);
}
else {
$price = $node->sell_price - $amount;
}
if ($node->sell_price == $price) {
return $price;
}
else {
return array('original' => $node->sell_price, 'discount' => $price);
}
}
And as conclusion, I am helping with this, but there is no mantainer. This module is pretty useful, but IMHO it should be rewrite from scratch using workflow.
i will suggest to use the
i will suggest to use the taxonomy discount addon and assing a category to each product you want discounted.
@ pcambra : Thanks for the reply.
I have tried discount for product classes and that works well. However,the concept of product classes is a bit too "bloated" for my site (which is only very simple).
I had a play with taxonomy discount and it doesn't work as well:
1) There is no option in the ACTION for entering a quantity (e.g. how many products the user must order before the discount is applied).
2) If I create a discount for any taxonomy categories that have products in them, those product pages (and any pages that refer to them) are displayed as blank white screens.
I really would like to get Taxonmy discount working.
Any ideas?
I notice that under the CONDITION option, the Comparison Operator drop down menu only lists "!=" & "=". As all the other discount modules have 'less than' and 'greater than' options for this field, does this indicate that the taxonomy discount add-on might not have installed properly?
Re: i will suggest to use the
The taxonomy discount was thought as a little addon and it does not support quantity, that is why there is not less than, greater and quantity options. It discounts an amount or % based only in the taxonomy
Condition should be "Taxonomy" and action "Discount product type price from order", i have no blank pages at all, could you provide an example?
uc_discounts_product_class.module
Hi pcambra,
Great module, great work.
Just adding my contribution so far to its development.
In the uc_discounts_product_class.module when creating the product class select box, the following routine:
$product_types = module_invoke_all('product_types');
$node_types = module_invoke_all('node_info');
foreach ($product_types as $id) {
$classes[$id] = check_plain($node_types[$id]['name']);
}
should replace:
$result = db_query("SELECT pcid,name FROM {uc_product_classes} ORDER BY pcid");
while ($row = db_fetch_object($result)) {
$classes[$row->pcid] = check_plain($row->name);
}
because that gets both the default 'product' and any other products assigned by ubercart modules and obtained through the 'product_types' hook.
product discount module: observations
Pcambra, thanks for the reply
I experimented a bit with the product discount module and noticed the following (strange) behavior:
1) the background:
I needed to implement 3 discount prices at a product level. So each product needed to have 4 different prices, depending on the volume bought. This is exactly what the discount product module does.
2) Different ways to get there:
2.1 First I tried to give each product 3 different discounts that don't accumulate. For this, i need the minimum and maximum number of products and the total discount.
This will give: product X priced 30$, when you buy 5 => 20$/piece, when you 10 => 15$/piece, when you buy 25 => 10$/piece
The (strange) behavior:
2.2 I changed to grouping of the conditions, so each 2 conditions are in the same group with different weights.
The (strange) behavior:
2.3 I tried to give each product 3 different discounts that accumulate. For this, i need the minimum and maximum number of products and the relative discount amount.
The (strange) behavior:
I'm mentioning this for people interested in using this module. For now, using this last method, nothing bad happens. I like to thanks all developpers who contributes to it. If my explanation wasn't clear (which I can imagine), just ask me and I'll elaborate a bit more on it.
User's country discount module
Hello, guys
It seems that I'm going to join to the "Discount-module-helpers" club
I've created another "Condition" module. It can make discounts for users from specific countries. The country data are fetched from the users's IP adress. This module depends on another Drupal module called ip2nation.
While creating this module, I've stumbled on several limitation going from the Discount module. First of all, it's a "item_id" field in the DataBase. It is varchar(255). And this amount is not enouth to store large amounts of data. So, simple "ALTER" resolved the problem:
ALTER TABLE `uc_discounts_conditions` CHANGE `item_id` `item_id` TEXTAnother change was into the code. I've discovered that the Discount module don't gives the condition data to it's submodules. It's very bad, because modules with list of data, such as "Multiple Product" or my module, can't initialize their data on editing. So, I changed this too:
--- uc_discounts.module Wed Jul 9 1:28:12 2008+++ uc_discounts.module Mon Jul 7 15:22:9 2008
@@ -1232,7 +1232,7 @@
// item field is not required
if (isset($condition_info[$condition_property]['item_field_callback'])) {
$item_field_callback = $condition_info[$condition_property]['item_field_callback'];
- $item_field = $item_field_callback();
+ $item_field = $item_field_callback($condition);
}
else {
$item_field = array(
These changes are not breaking other modules and I hope that they will be applied to future versions of Discount module.
And, at last, the module itself — in attachment.
P.S. After enabling ip2nation, get the latest ip database from their server. It's very old at the drupal.org
---
Drupal in Russia
Re: Re: i will suggest to use the
Thanks for your reply, pcambra.
Condition should be "Taxonomy" and action "Discount product type price from order", i have no blank pages at all, could you provide an example?
The blank pages only appear if you have " Discount product type price from order" as an action, which makes sense, as I guess that is an invalid option.
The taxonomy discount was thought as a little addon and it does not support quantity, that is why there is not less than, greater and quantity options. It discounts an amount or % based only in the taxonomy
I am a little confused on this. If the discount isn't triggered by quantity, then what does the customer have to do to make a discount appear?
^_^
Hi! I still don't know how
Hi!
I still don't know how to get those blank pages, I have some discounts with taxonomy and "Discount product type price from order" as an action and i dont get them.
I am a little confused on this. If the discount isn't triggered by quantity, then what does the customer have to do to make a discount appear?
The discount is triggered buying products for the taxonomy given in the Taxonomy Condition. If you define a discount based in the category "Red" as a Taxonomy Condition, all the products categorized as "Red" will be discounted, but "Blue" or "Green" ones won't.
Re: Hi! I still don't know how
Thanks for your continued help, pcambra.
So, to double check, is there anyway to make quantity based discounts using the taxonomy add-on (or is the product class add-on the only way to do this)?
Thanks,
Taxonomy and Blank Pages
Like one or two others, I was getting blank pages when using the taxonomy discounts module. I had a look in my PHP error log and found the error was occurring in the following line:
drupal_set_message('producto- '.dprint_r($product->title,TRUE));
The dprint_r function is in the Devel module, so if you have this module enabled, you won't get this problem. Commmenting the line fixes it.
Discounts in product listings
Discounts are now working great for me now, but just one little thing...
The discounted price is shown when I go to a product page, but on product listings only the full price is shown. Is there any way this could be corrected?
product type discount debugging
Note: cross-posted in issue tracker for Discount
Since there isn't a maintainer, I'm posting this for general info/use.
Environment:
Drupal 5.8
Ubercart 1.2
Discount version: pcambra's version
Test: For users of a certain role, discount all products of a certain class
How I did it:
Created a role "member" and added my user to the role
Created a product class "Seeds"
Created a product of class "seeds" called "test seeds". Price set at 100.
Created a discount called "memberdiscount" as follows:
CONDITIONS:
Userrole = member
Producttype >= 1. Type Seeds
ACTION:
Discount all products of a type (seeds) from order, qty=1, amount=10%
Behaviour:
10% Discount appears when viewing product
When product is added to cart, Full price is used.
When cart is checked out, full price is used, with no discount details of any kind shown
Debugging:
When viewing the product node:
uc_discounts_product_discount_price creates a "pseudo shopping cart" of a single item, the current node. The product details for this include the product's type (ie class). This pseudo shoppping cart is passed into uc_discounts_product_class_check, which correctly returns that the conditions are satisfied.
When adding product to cart:
uc_discounts_product_discount_price is called, but this time the product is not a full node, and the product type information is not available. This causes the uc_discounts_product_class_check to fail, so the discount isn't applied.
+1 for someone who is familiar with this code to take over maintenance. pcambra are you listening?
I'll provide a small bounty ($100) for the new maintainer once he/she takes over, establishes a single codestream, and fixes this particular bug.
problem fixed
I have fixed this. I've posted a description of the changes I made to the item in the ISSUE queue.
http://www.ubercart.org/issue/5791/discount_product_type_works_when_view...
Please note I have withdrawn the $100 bounty for the bugfix, but will offer a $50 bounty if a maintainer comes onstream in the next few weeks.
Maintainer
I'm really looking forward to someone seriously taking this 'module' on as an official Drupal module and fixing all the bugs and issues. I'd love to do it but have little time and knowledge of Drupal language.
I think some of the requests here are very valid, particularly richygecko's suggestion to apply discounts to Attributes. I also think this module should become a part of Ubercart core as I'd reckon it would be a much used feature.
Living in hope...
Discount based on total quantity of products purchased
Hello,
I am implementing a wine shop and I would like to offer a discount based on the number of bottles purchased. If the customer purchases 12 bottles of wine I would like to give a 10% discount. It does not matter if they purchase 12 bottles of the same wine or 12 different bottles (products) of wine. It seems that the module only gives discounts based on $qty of $product at the moment and not $qty of all $products of a certain type. Is anyone using this module to accomplish this? If not how difficult would modifying the current module for this functionality be?
Thanks for the help,
Patrick
Discounts for attributes
I've just had a quick look and attributes don't seem to be attached to the node object. How would one go about getting the attributes for a product within nodeapi so that discounts could also be set on those attributes that have price differences?
EDIT: Maybe I should just use a query. Checking uc_attributes.module for helpful functions.
Re: Discounts for attributes
There is some dedicated function to retrieve the attributes when you know the node, I think you have to deal with them in a custom additionnal code to manage attributes discount.
I wonder if an attribute management module could be written without make others submodules (taxonomy, role based discount) incompatible ?
Re: Re: Discounts for attributes
Sounds like the right way to go. Only dipped my toes in with this one as the project I most likely need this for is not yet started. I will be looking into this soon though so any scoping of the problem by people who know this would be very helpful.
Re: Re: Re: Discounts for attributes
Is it able to say user puts 1 or more of product A in the cart, and the total exceeds $99. I want to give them a free Product B. is there a way to do this?
Product discounts not being applied.
I've been playing with this module for a little while but cannot figure out why it isn't applying product discounts.
For my test case I'd like to discount the product "PC Watchdog" by £5 when 10-24 are purchased. The discount should be applied when the product is added to the cart.
Whatever settings I use, nothing seems to change. I've attached screenshots of my settings, am I missing something simple? (I'm using PHP 5 btw)
Coupon Module playing up at last hurdle.
Hi guys,
We've now installed the latest Coupon Module provided by Zmove. On first inspection it's exactly what we need for group buys on our website. You can now base coupon codes on individual products. This means we can start a group buy with say a 15% discount, customers can come onto the site, add the coupon, get the discount and proceed to payment. This is where the problem starts.
With the example below we have added the item, gone to checkout without apply the coupon code, this is the price:
Order total preview:
Subtotal: £7.62
VAT: £1.33 (17.5%)
Order total: £8.95
We now enter the coupon code which gives a £1.00 discount, we click "get coupon" and the discount is applied, the site updates the total:
Order total preview:
Subtotal: £7.62
TTLANYARDGB: -£1.00
Subtotal excluding taxes: £6.62
VAT: £1.16
Order total: £7.78
As you can see that is correct, with the old coupon it based the VAT on the original total but now at this stage in checkout the price is correct and the VAT is also correct. But when you click review order it's goes back to the old problem:
Coupon discount: TTLANYARDGB: -£1.00
Subtotal: £7.62
Subtotal excluding taxes: £6.62
VAT: £1.33
Total: £7.95
Paying by: PayPal
As you can see it's now based the VAT on the original total and not the discounted total (VAT is £1.33 but should be £1.16). If you press back, re-enter the code and review order it updates it to the correct amount but we can't tell customers to do this. In basic it's taking the wrong VAT amounts.
Then if you click submit order you are taken to paypal where again it messes up. This is the total from Paypal:
Toy Tuning Lanyard/Keychain
Item Number TOY-TTL-002
Item total: £7.62
Sales tax: £1.16
Total: £8.78 GBP
As you can now see the paypal total is another problem. It hasn't applied the discount (-£1.00) but has then based the VAT on the discounted total. If look at the bolded numbers you should be able to see what is happening. It's so nearly there yet so far away!
If anyone can make any recommendations then please let us know. We've been trying to get this to work for over 3 months now and if we can't get it to work we will revert to the old way and manually collect payments. Group buys via the website would save us hours and hours of work. We really thought it was fixed now but after reviewing the order and checkout this is not the case.
Many thanks for your time.
Toby
Re: Discounts
This is a very useful and important module. Thanks to everyone who put work into this module / sub modules! This is a great addition to UC...
This evening I spent several hours going over the different code in each sub module. I see some inconsistencies between each module. As far as we can tell, uc_discounts_product.module, is the one sub module that is working, across the board, as it should. I see how useful this module is and I hope the following can help us get this module up to par.
(1) A few misspellings ($conditions->xyz should be $condition->xyz) in a couple of the sub modules
(2) Calculation inconsistencies. Each sub module should be calculating using the same lines of code and naming convention. (IE $product_count vs $product->qty). If that is the case, I am beginning to think we should have an API for the sub modules or a set of functions in uc_discounts.module that each sub module can push the calculations through.
(3) Behavior; each sub module should provide similar behavior (ie: cart block needs to show price change if uc_discount settings indicates). From what I can tell, only submodule uc_discounts_product.module does this. (I tested uc_discounts_product.module, uc_discounts_multi_product.module, uc_discounts_product_class.module, and uc_discounts_role.module - all on the condition of a user being a certain role).
(4) Lack of documentation; I think a README for each sub module is needed with a few common examples. Also, sub modules need $id and version info.
(5) Each poster, we need to tell what version we are using, and use the $id line in the .module file so we can all help each other more efficiently. If you know how to create .diff files or patches that would be helpful (http://drupal.org/patch/create).
I am willing to help out with coding for the sub modules and building README files with examples. Does anyone want to step up and assess the above? I would really like to see some coding standards (2 & 3) in place (so any one of us can pickup a sub module and debug/re-code it.
===
Elvis McNeely
Blogging about Drupal: http://www.elvisblogs.org/drupal
Re: Coupon Module playing up at last hurdle.
Has anyone found a fix to Toby's problem? I'm having the same issue with tax calculation on the order review page when using a product discount. (I'm not using PayPal so don't encounter the second problem)
I haven't applied any of the uc_taxes patches discussed in this thread as uc_taxes now has a checkbox for applying taxes to discounts...
Taxonomy with quantity
I've mixed up product and taxonomy discount module so you can select a condition on product quantity if a taxonomy term is matched. I coded this yesteday afternoon and barely work, if someone want to test and let me know...
<?php// $Id: uc_discounts_productm.module,v 1.2 2008-03-31 06:58:11 pcambra Exp $
/*******************************************************************************
* Hook Functions (Ubercart)
******************************************************************************/
function uc_discounts_productm_discounts_condition() {
$conditions[] = array(
'property' => 'Productm',
'description' => t('Taxonomy qty'),
'compare_type' => 'integer',
'check_callback' => 'uc_discounts_productm_check',
'count_callback' => 'uc_discounts_productm_count',
'item_name_callback' => 'uc_discounts_productm_item_name',
'item_field_callback' => 'uc_discounts_productm_item_field',
'value_field_callback' => 'uc_discounts_productm_value_field',
);
return $conditions;
}
function uc_discounts_productm_discounts_action() {
$actions[] = array(
'property' => 'product_from_order',
'description' => t('Discount product Taxonomy price from order'),
'has_qty_field' => TRUE,
'item_field_callback' => 'uc_discounts_productm_item_field', //recycle
'item_name_callback' => 'uc_discounts_productm_item_name', //recycle
'apply_callback' => 'uc_discounts_productm_apply',
);
return $actions;
}
/*******************************************************************************
* Callback Functions, Forms, and Tables
******************************************************************************/
function uc_discounts_productm_check($condition, $total_price, $cart) {
$product_count = 0;
foreach ($cart as $product) {
$terms = taxonomy_node_get_terms($product->nid);
//drupal_set_message(t("checking condition(%c) item_id(%i) against product(%n) %t",array('%c' => $condition->id,'%n' => $product->nid, '%t' => $product->title,'%i' => $condition->item_id)));
foreach ($terms as $term) {
//print " term: ".$term->tid." itemid: ".$condition->item_id." ";
if ($term->tid == $condition->item_id) {
$product_count += $product->qty;
//drupal_set_message(t("testing condition(!c) item(!i) value(!v) !o product(!n) qty(!q)",array('!c' => $condition->id,
// '!i' => $condition->item_id,
// '!v' => $condition->value,
// '!o' => $condition->op,
// '!n' => $product->nid,
// '!q' => $product_count)));
break;
}
}
}
//print "prodotti trovati: ".$product_count;
if ($product_count == 0) {
return FALSE;
}
elseif ($condition->op == '=' && $product_count >= $condition->value) { return TRUE; }
elseif ($condition->op == '!=' && $product_count != $condition->value) { return TRUE; }
elseif ($condition->op == '>=' && $product_count >= $condition->value) { return TRUE; }
elseif ($condition->op == '>' && $product_count > $condition->value) { return TRUE; }
elseif ($condition->op == '<=' && $product_count <= $condition->value) { return TRUE; }
elseif ($condition->op == '<' && $product_count < $condition->value) { return TRUE; }
else { return FALSE; }
}
function uc_discounts_productm_count($condition, $cart) {
$product_count = 0;
foreach ($cart as $product) {
$terms = taxonomy_node_get_terms($product->nid);
//drupal_set_message(t("checking condition(%c) item_id(%i) against product(%n) %t",array('%c' => $condition->id,'%n' => $product->nid, '%t' => $product->title,'%i' => $condition->item_id)));
foreach ($terms as $term) {
//print " term: ".$term->tid." itemid: ".$condition->item_id." ";
if ($term->tid == $condition->item_id) {
$product_count += $product->qty;
//drupal_set_message(t("testing condition(!c) item(!i) value(!v) !o product(!n) qty(!q)",array('!c' => $condition->id,
// '!i' => $condition->item_id,
// '!v' => $condition->value,
// '!o' => $condition->op,
// '!n' => $product->nid,
// '!q' => $product_count)));
break;
}
}
}
//print " prodotti trovati in productcount: ".$product_count;
return $product_count;
}
/**
* Given a product id (nid), return the product name
*/
function uc_discounts_productm_item_name($product_id) {
//$result = db_query('SELECT title FROM {node} WHERE nid=%d', $product_id);
//$product_name = check_plain(db_result($result));
return $product_name;
}
/**
* Generate the condition item field
*/
function uc_discounts_productm_item_field() {
// load list of products from the database
// no function in uc_products to do this. This may need refining later
$taxonomy = array();
//SELECT d.tid, d.name FROM `drupal_term_data` d LEFT JOIN drupal_vocabulary_node_types t ON d.vid = t.vid WHERE t.type="product"
$result = db_query("SELECT d.tid, d.name FROM {term_data} d LEFT JOIN {vocabulary_node_types} t ON d.vid = t.vid WHERE t.type='product' ORDER BY d.name");
while ($row = db_fetch_object($result)) {
$taxonomy[$row->tid] = check_plain($row->name);
}
if (empty($taxonomy)) {
$field = array(
'#type' => 'item',
'#title' => t('Category'),
'#description' => t('No category available'),
);
}
else {
$field = array(
'#type' => 'select',
'#title' => t('Category'),
'#options' => $taxonomy,
);
}
return $field;
}
/**
* Generate the condition value field
*/
function uc_discounts_productm_value_field() {
$field = array(
'#type' => 'textfield',
'#title' => t('Quantity'),
'#maxlength' => 12,
'#size' => 6,
'#required' => TRUE,
);
return $field;
}
function uc_discounts_productm_apply($op, $action, $total_price, &$cart) {
// get conditions to make sure products can't be used more than once for
// a discount
//drupal_set_message("uc_discounts_productm_apply: $op $action $total_price ". print_r($cart));
$sql = "SELECT * FROM {uc_discounts_conditions} WHERE discount_id=%d ";
// removing the following lines per kiruva [http://www.ubercart.org/contrib/143#comment-8814]
// $sql .= "AND property='product' ";
// $sql .= "AND item_id='%s' ";
$sql .= "ORDER BY condition_group, weight";
$result = db_query($sql, $action->discount_id, $action->item_id);
//ob_start(); print_r($action);
//drupal_set_message(" hit uc_discounts_productm_apply: ");
//drupal_set_message(ob_get_contents()); ob_end_clean();
//drupal_set_message(t("[$sql]",array('%d'=> $action->discount_id,'%s' => $action->item_id)));
$condition_list = array();
while ($row = db_fetch_object($result)) {
$condition_list[$row->id] = $row;
}
if (empty($condition_list)) {
return 0;
}
$discount = 0;
$discount_amount = 0;
foreach ($condition_list as $condition) {
if ($condition->property == 'Productm') {
foreach ($cart as $product) {
if ($condition->discount_id == $action->discount_id) {
$terms = taxonomy_node_get_terms($product->nid);
$qty = $product->qty;
foreach ($terms as $term) {
if ($term->tid == $condition->item_id) {
//print " trovato ";
//se amount è espresso in percentuale calcola la percentuale
if (substr($action->amount, -1) == '%') {
$discount_percent = substr($action->amount, 0, -1) / 100;
if ($discount_percent < 0) {
$discount_percent = 0;
}
if ($action->qty != 0) {
$qty = $action->qty;
}
$discount += $product->price * ($discount_percent * $qty);
} else {
if (substr($action->amount, 0, 1) == '$' OR substr($action->amount, 0, 1) == '€') {
$discount_amount = substr($action->amount, 1);
} else {
$discount_amount = $action->amount;
}
if ($discount_amount > $product->price) {
// do not allow discounting greater than the product price
$discount_amount = $product->price;
}
$discount += $discount_amount * $qty;
}
break;
}
}
}
}
}
}
return $discount;
}
Re: alpha7c updates
spiderman, many thanks for the diff file to make this compatible with alpha7c. It works fine.
D6 port of the discount module
Hi,
I ported this module to Drupal 6 and Ubercart 2.x version.
I added no features ATM except some additional conditions and actions posted here like the user condition discount.
It's a first snapshot, it seems to works pretty good, but I need more people to test it and give me feedback.
Thanks
zmove
French translation
Hello, this is our french translation for the latest version compatible with Ubercart 1.4. Feel free to use it.
Role Based Discount missing actions
If you are successfully using role based discounts could you please send me or post the version of uc_discounts you are using? I need to use a role / taxonomy based discount but I only seem to get the taxonomy actions when I try to configure my actions...and if i turn off the taxonomy portion I have to actions at all to apply.
Thank you!
Re: Role Based Discount missing actions
"Role" is just a condition. As conditions and actions are by design independent, you can combine whatever you need by any of the submodules.
Re: D6 port of the discount module
I have not tried this D6 version but the D5 version works well. I'm keen to see this on drupal.org so we can ensure the long term health of this project. Is there anyone who would like to help out with maintaining this on drupal.org and is the original author interested or just happy for someone else to take it on? I am interested in helping out with maintaining it on drupal.org.
Re: Role Based Discount missing actions
Al,
Thank you for the clarification. However, if the roles module doesn't have any actions and that's the only module you are using for discounts...there are no actions present to select from, correct?
And, when I did try using taxonomy and role...ie give all VIP members a 10% discount if the products is tagged "Regular Price"...it simply did not work...
I'd like to think I'm just configuring this incorrectly...but when i wrote a uc_discounts_role_discounts_action() function and provided an "apply_callback" function...it started to work...
I guess I'll go back and try to debug without modifying the role module...
Re: Role Based Discount missing actions
Ok, I think I've got this...as my wife would tell you...I can be a bit slow. I've turned on the "Order Total", "Role", and "Taxonomy Discount" modules and am able to use the conditions from Role and Taxonomy and the action from Order Total. Thanks again.
byelle
Discounts and Taxes
Note to anyone trying to get Taxes and Discount to play nice together. The default settings proved buggy in my testing in that some times the tax would calculate on pre discount values and some times on post discount values. Under Store Administration > Discounts > Settings you can change the discount to apply when the product is added to the cart. While this doesn't have the same visual impact of "look how much you saved" on the order confirmation page...it seems to play nicer with the tax module.
discount delete feature
HI All!
i found why discounts were not deleting on delete operation.
<?php function uc_discounts_discount_delete_form($discount_id) {- if ($discount == 0) {
+ if ($discount_id == 0) {
drupal_goto('admin/store/discounts');
}
$discount = uc_discounts_load_discount($discount_id);if (!
$discount) {drupal_goto('admin/store/discounts');
}
drupal_set_title(t('Delete !name', array('!name' => $discount->name)));....
....
....
....
}
?>
cheers,
Pinky
Re: Re: D6 port of the discount module
+1 for getting this hosted on drupal.org.
I'd be able to help with maintaining, as it's something I'm going to need pretty soon for a client
Is the attachment to comment #146 the latest and best version of the code?
where do you place this nice function
Just what I needed. Where do you cram in the below function?
Regards Wolan
where do you place this nice function
@pcambra _ Just what I needed. Where do you place (in what module?) the below function?
Regards Wolan
function get_real_price($nid) {$node = node_load($nid);
$sql = "SELECT uda.amount
FROM uc_discounts ud
JOIN uc_discounts_conditions udc ON (ud.id = udc.discount_id)
JOIN uc_discounts_actions uda ON (ud.id = uda.discount_id)
WHERE udc.property = 'product'
AND uda.property = 'product_from_order'
AND from_unixtime(ud.end_time) > now()
AND uda.item_id = %d";
$result = db_query($sql, $node->nid);
$amount = db_result($result);
if (substr($amount, -1) == '%') {
$discount_percent = substr($amount, 0, -1) / 100;
if ($discount_percent > 1) {
$discount_percent = 0;
}
$price = $node->sell_price - ($node->sell_price*$discount_percent);
}
else {
$price = $node->sell_price - $amount;
}
if ($node->sell_price == $price) {
return $price;
}
else {
return array('original' => $node->sell_price, 'discount' => $price);
}
}
Re: where do you place this nice function
I've placed in a custom module and I use it for some theme functions, you can place it where you put all the custom functions or utilities...
If you don't have a module for this, you can always put this in the theme function you need it, but is ugly I think.
Btw, I am using a new function:
function get_real_price($nid) {$node = node_load($nid);
$sql = "SELECT uda.amount
FROM uc_discounts ud
JOIN uc_discounts_conditions udc ON (ud.id = udc.discount_id)
JOIN uc_discounts_actions uda ON (ud.id = uda.discount_id)
WHERE udc.property = 'product'
AND uda.property = 'product_from_order'
AND from_unixtime(ud.end_time) > now()
AND ((op LIKE '%=%' AND value = 1) OR (op LIKE '%>%' AND value = 0))
AND ud.is_active = 1
AND uda.item_id = %d";
$result = db_query($sql, $node->nid);
$amount = db_result($result);
if (substr($amount, -1) == '%') {
$discount_percent = substr($amount, 0, -1) / 100;
if ($discount_percent > 1) {
$discount_percent = 0;
}
$price = $node->sell_price - ($node->sell_price*$discount_percent);
}
else {
$price = $node->sell_price - $amount;
}
if ($node->sell_price == $price) {
return $price;
}
else {
return array('original' => $node->sell_price, 'discount' => $price);
}
}
UC Discounts now hosted on drupal.org
The version by pcambra has been uploaded to cvs.drupal.org so we can ensure the long term health of this project. If anyone wishes to help co-maintain this module then please post an issue in the queue. Current maintainers are psynaptic and joachim, pcambra and antoinesolutions have also shown interested so we should have a pretty strong group of developers to help stabilise and improve this fantastic contribution.
Huge thanks to Marshal for creating the module and to all those who have helped make this contribution what it is. If you have contributed to this module's development and feel you should have a mention in the README.txt then please let me know and I will be more than happy to add it.
We would like everyone with outstanding issues to post in the module's issue queue where we can more easily deal with them.
Re: UC Discounts now hosted on drupal.org
Thank you so much, guys. I'm going to disable the posting of comments on this thread since it's been an unwieldy beast for some time now. Rich, if you don't mind I'm going to make you the owner of this page here so you can update it in the future if you want. PM me if you need anything else.