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

chrisschaub’s picture

I 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.

ryangroe’s picture

I 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.

chrisschaub’s picture

Hmmm, 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.

ryangroe’s picture

The 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.

ryangroe’s picture

Assigned: Unassigned » ryangroe
Status: Active » Needs review

Please try beta 5 to see if this problem has been fixed.

chrisschaub’s picture

It 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.

ezra-g’s picture

Status: Needs review » Active

This is still active.