We have a completing checkout process rule event, but it may have sense to implement a "Display checkout" event as well.

Use case:
Say you want to validate the amount of products (or amount of money) that a user can buy in the cart->checkout transition and display a warning message.
If you do that in a validate function of cart, if the user changes the quantity, the order gets saved later than the validation.

It may be useful to add a rules event when the checkout is displayed to handle this kind of situations, maybe in the checkout_router function.

What do you think?

CommentFileSizeAuthor
#5 1233508-checkout_display_rules-5.patch4.48 KBpcambra

Comments

rszrama’s picture

Yeah, basically this would be plugging into commerce_checkout_router(). We already have a hook for this, so it wouldn't be hard to define a similar event and change the invocation to rules_invoke_all(). I'm not sure what to name the event, though, because it is not just a single "can the user access checkout" check, but a check on each step of the form. The arguments it takes are both an order and a checkout page. Thus it would need to be something like "Before displaying a checkout page".

essbee’s picture

This is exactly the functionality I'm looking for.
When a user goes to checkout I want to check to see if they have at least 6 items in their cart, or that the cart value is greater than $300.
If they do not satisfy the criteria they should be redirected back to the cart.
I can't see a way to achieve that at present, and this I'm guessing would solve it perfectly.

As an aside is there a way to achieve this at present in the checkout process? Obviously avoiding getting to the checkout process would be preferred, but even a solution early on in the checkout would be better than nothing.

bbjay’s picture

Here is the way that I accomplished this:

1. Create a new rule using "Select available payment methods for an order" for your event.
2. Add the condition "Data comparison" and set the data to compare as "commerce-order:commerce-order-total:amount". Your operator value should be set to "is lower than" or whatever you need and then enter the number that you need it to be in cents. In other words, for $100, enter 10000 as the data value.
3. Add the action "Page redirect" and set the value of this to "cart" or wherever you would like your user to be redirected to and make sure that Force redirect is checked.
4. Add a second Action element of "Show a message on the site" and set your message value to something like "Your order total must meet the minimum requirement of $100 to proceed through the checkout process."
I set my message type to "Warning" and left the Repeat message checkbox checked, but this is a matter of preference.

I hope this helps anyone looking for an easy solution to check Order minimum or maximum.

scottcarlton’s picture

This was exactly what I was looking for. Thanks for posting!

pcambra’s picture

Status: Active » Needs review
StatusFileSize
new4.48 KB

Ok, here's an initial version of this.

It would be very cool to be able to change checkout page properties from rules, like the next button title or even the next page dinamically (if you're this kind of user, skip payment, etc.), but I couldn't make it work as I'd say that "Data set" actions are only thought for entities and we'd need to convert checkout pages to entities, which may happen eventually?

essbee’s picture

Thanks bbjay, this works great... almost.
For some reason the rules is evaluating and redirecting fine, but the message is not being displayed to the user.
Juts to confirm that I had the action configured correctly, I tied it to another event (on add to cart), and the redirect and message works fine.
Anyone have any idea why the message wouldnt be displayed when firing from the Select Payment Method event?

TyrelDenison’s picture

I am having the exact same issue with the message not displaying. I have been wrestling this for some time now with no luck.

bbjay’s picture

I'm glad you posted this, because I went to check if mine was working still and it is not anymore. Something must have changed recently in one of the updates to cause the message to not display on the cart page. I also have a minimum quantity set on certain types of items that uses the "add to cart" event and the display message works fine on this. Can anyone update us about anything that may have recently changed to cause this to not work anymore?

bbjay’s picture

I opened a new issue since this may now be a bug and not a feature request. #1376564: "Show a message on the site" stopped working with event "Select available payment methods for an order"

vasike’s picture

Status: Needs review » Needs work

The last submitted patch, 1233508-checkout_display_rules-5.patch, failed testing.

MarcElbichon’s picture

firfin’s picture

Issue summary: View changes
Status: Needs work » Closed (won't fix)

I am not sure what to mark this. I think this won't be happening, because it is already solved by Commerce Rules Extra module. But then I might be wrong on this. I think a lot of searches still end up on this page, so it should me clear what the recommended solution is imho.
So what's it gonna be Closed (won't fix? works as designed? fixed?)

rszrama’s picture

Works for me. : )