Working in the coupons thing, see #1413126: Commerce coupons roadmap I've used hook_commerce_cart_line_item_refresh to check variations in the coupon line items and refresh their quantities: See http://drupalcode.org/sandbox/pcambra/1454380.git/blob/refs/heads/master...

I think that we should consider to add to both hook_commerce_cart_line_item_refresh and hook_commerce_cart_order_refresh rules support as events the same way as calculating sell prices do.

Any thoughts?

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

pcambra’s picture

Status: Active » Needs review
FileSize
1.16 KB

I think this is really important to allow non-product elements to alter stuff that is in active/cart orders.

Straightforward example: If you have a percentage coupon and use "calculate sell price of the product" event as it was doing now, in the cart everything is going to be fine, but when you go back to your shop/catalog, you're going to see all prices changed by the coupon percentage rate which is really weird.

This is a must really for commerce coupons module.

Patch (really simple) attached, hope this gets some caring and love :)

pcambra’s picture

Oops, that's an old testing patch, here's a new one

rszrama’s picture

So the rough idea here is that we'd be adding a way through Rules to "delay" the application of a price adjustment to the shopping cart refresh instead of having the adjustment appear on the product page? If so, I like the idea, because I often thought, too, that it would be funny to see product prices change across all pages when you have other types of discount rules on a site based on the total cart price or quantity. We just need to figure out how to message this and indicate it in the UI, as it wouldn't be readily apparent that you'd use one set of "pricing rules" for general discounts vs. another random event only accessible through the primary rules interface for discounts that should only be applied in the cart.

In fact, you may not even need the new event to make this happen. You can simply check to see if the line item has an ID. If it has an ID, then you know it's in the cart. If it doesn't, then you know it's coming from the page. With that in mind, I wonder if it wouldn't be better to just document that and avoid the split in events / UIs. : ?

(I realized after I wrote that first paragraph that the method described in the second paragraph is how we do this in the "Unset the price of disabled products in the cart" default rule.)

pcambra’s picture

For the coupons use case, in particular for the percentage approach of coupons, if the % is discounted on "calculate sell price" event, products are discounted all through the site, so it's kind of "too early" to show a discount whereas if we had rules on the line item refresh event, we could avoid this issue, that is avoided too with rules that check for the line item id, not sure of your preference, though. I can't really visualize how this would behave for non-product coupons as they may not be affected for the sell price event.

There's a second issue on this subject, kind of offtopic here, that is in the cart, the price is displayed discounted with the percentage coupon amount, and feels a little weird for the subtotal calculation, this happens both with line item refresh and calculate sell price as the line items have line item id (it's behaving same as the taxes do), for now I'm recommending the commerce price by components to hide the coupon component.

Chris Matthews’s picture

Issue summary: View changes
Status: Needs review » Needs work
Issue tags: +Needs reroll

The 7 year old patch in #2 does not apply to the latest commerce 7.x-1.x-dev and (if still relevant) needs to be rerolled.

Checking patch modules/cart/commerce_cart.api.php...
Hunk #1 succeeded at 124 (offset 14 lines).
Hunk #2 succeeded at 146 (offset 14 lines).
Checking patch modules/cart/commerce_cart.module...
error: while searching for:
    }

    // Allow other modules alter line items on a shopping cart refresh.
    module_invoke_all('commerce_cart_line_item_refresh', $cloned_line_item, $order_wrapper);

    // Delete this line item if it no longer has a valid price.
    $current_line_item_wrapper = entity_metadata_wrapper('commerce_line_item', $cloned_line_item);

error: patch failed: modules/cart/commerce_cart.module:828
error: modules/cart/commerce_cart.module: patch does not apply
Checking patch modules/cart/commerce_cart.rules.inc...