Active
Project:
Ubercart Discounts (Alternative)
Version:
6.x-1.0-beta4
Component:
Code
Priority:
Normal
Category:
Feature request
Assigned:
Reporter:
Created:
5 Mar 2009 at 08:09 UTC
Updated:
1 Sep 2009 at 12:56 UTC
Hi. First, what a killer module! Ok, it might be good to add an ORDER BY d.weight to the get_codeless_discounts_for_product() function:
$query = "SELECT d.* FROM {uc_discounts} d
LEFT JOIN {uc_discounts_products} dp ON d.discount_id=dp.discount_id
LEFT JOIN {uc_discounts_terms} dt ON d.discount_id=dt.discount_id
WHERE d.requires_code=0
AND (%s)
AND (%s)
AND (d.has_expiration=0 OR d.expiration>%d) ORDER BY d.weight DESC";
This way, multiple discounts appear in the order assigned in the admin interface. All I added was "ORDER BY d.weight DESC."
Thanks.
Comments
Comment #1
chrisschaub commentedI should be clearer. This is so the discounts appear in the correct order when displayed in the codeless cck field type. The display order of multiple discounts should match the admin definition.
Comment #2
ryangroe commentedI definitely agree with ordering the results of get_codeless_discounts_for_product(). Do you need the results ordered descending? Because to match the admin table it would be ordered ascending.
Comment #3
chrisschaub commentedHmmm, descending makes sure it goes in order of application. It's working for me this way. Using "Can be combined with other discounts" as NO, I can weight discounts so, for example, minimum qty 100 gets evaled first, then min qty 75 etc. I have discounts with weights -4, -3, -2, -1 and the -4 shows up first on the screen and is processed first. I'd want the display order to match the order the discounts get applied. I agree that ORDER BY ASC makes more sense -- but somehow, it's getting flipped. Anyway, DESC is working with order of appication and display. Weird.
Comment #4
ryangroe commentedThe order -4, -3, -2, -1 is ascending since -4 < -3 < -2 < -1
I added the sort clause to the get_codeless_discounts_for_product function. I also added a theme function to render the codeless discount block (theme_codeless_discounts_field_get_codeless_discount_html_for_product). So if you'd like to change the way this is rendered (such as override the sort column or order) you can override the function.
For instance:
function phptemplate_codeless_discounts_field_get_codeless_discount_html_for_product($product_id)
{
$discounts = get_codeless_discounts_for_product($product_id, "weight", FALSE);
...
}
This change will be part of the new beta 5 to be released tonight.
Comment #5
ryangroe commentedPlease try beta 5 to see if this problem has been fixed.
Comment #6
chrisschaub commentedIt is fixed for the cck field display, and the display on the checkout screen honors the weight order of multiple discounts. But, the display on the review order screen does not. I see the discounts in reverse order -- not the order they are applied. The discounts should be displayed in the order applied.
Comment #7
ezra-g commentedThis is still active.