Problem/Motivation
Currently, there's no way to allow/deny an automatic cart order refresh based on custom logic, since the cart refresh process is performance consuming, it'd be great if there was a way to turn it on/off at will.
For a project I'm currently working on, we manually trigger the refresh (after adding a product to the cart, adjusting quantities etc.), and we'd like the automatic cart refresh to only happen when landing on the checkout page (and it's currently not possible to do that).
Basically, the current custom logic will let you force a refresh on the checkout page, but won't let you "skip" it.
Proposed resolution
Introduce a hook_commerce_cart_order_can_refresh().
Remaining tasks
Propose a patch.
Comment | File | Size | Author |
---|---|---|---|
#3 | commerce_cart-introduce-cart-can-refresh-hook-3016616-3.patch | 1.77 KB | jsacksick |
|
Comments
Comment #2
jsacksick CreditAttribution: jsacksick at Centarro commentedThe attached patch introduces a hook_commerce_cart_order_can_refresh().
Modules implementing this hook should return one of the following values:
I wondered between COMMERCE_CART_REFRESH_SKIP and COMMERCE_CART_REFRESH_DENY (but I think "skip" makes more sense and skip is used in 2.x as well).
Comment #3
jsacksick CreditAttribution: jsacksick at Centarro commentedThe attached patch is using booleans instead of constants, which probably makes sense since we don't have more than 2 possible values.
Comment #4
jsacksick CreditAttribution: jsacksick at Centarro commentedComment #5
jsacksick CreditAttribution: jsacksick at Centarro commentedComment #6
jsacksick CreditAttribution: jsacksick at Centarro commentedComment #7
torgosPizzaWe've been using this patch for over a year now without any issues. Haven't had a reason to invoke the hook myself yet, but the logic looks quite good at preventing, for instance, an Administrator loading an order for reading and processing an unnecessary refresh.
Comment #9
jsacksick CreditAttribution: jsacksick at Centarro commentedCommitted, thanks for the RTBC!