Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
I'd like to see events for "viewing cart" and "viewing (various) checkout pages".
My use case is I want to display a message to the user when viewing their cart, or i want to redirect them somewhere if they don't have a particular product in their cart and they try to checkout. However, I could see lots of other possible uses for such events.
Comments
Comment #1
AaronBaumanThis patch adds the following events, which are hopefully self-explanatory:
Comment #2
Strae CreditAttribution: Strae commentedSubscribe, those events are very useful to implement a custom-rule based shipping costs, for example.
I applied the patch to commerce_kickstart profile, all seem ok for now.
Comment #3
Strae CreditAttribution: Strae commentedI tryed the "When viewing checkout page "Review"", it works;
But with "When viewing Shopping Cart" the event is triggerd after the main content is rendered, so if for example I add/remove line items in this step, the "your cart" block get updated with the edits, but not the "shopping cart contents" block (that is the main content).
So i added "Before viewing Shopping Cart" event that get invoked in line 37 of commerce_cart.pages.inc and it works
(sorry if i dont provide a patch, i dont know how to make it)
Comment #4
pun_pun CreditAttribution: pun_pun commentedThank you!!! Now I can sleep calm ))
I've made a total order weight calculation, based on your events. So if you are interested - you are welcome. :)
Comment #5
rszrama CreditAttribution: rszrama commentedWhile I understand the reason behind the patch, I'm not sure I can support such a patch going into core - I'm not even sure using Rules for this sort of task (or the related "Content is being viewed" event) is a good idea.
The problem in our case is that it isn't dependable. For example, someone may be embedding the checkout form somewhere else or just using Views to create the shopping cart display (there's a recipe for that here in the queue). I do appreciate the time you've put into making this sharable, though!
For now my recommendation is to maintain a patched version of Commerce using the patch above or consider making it a separate module (or part of another module if a related one exists).
Comment #6
AaronBaumanMakes sense.
Thanks for the explanation, Ryan.
Comment #7
AaronBaumannecro-post, since i came across the need for this again.
all of this is super easy to put into a module, except for "viewing cart":
Comment #8
Andrew211 CreditAttribution: Andrew211 commentedCart page is easy too, here's da code if anyone want's it.
Let's call the module "checkout_events"
checkout_events.rules.inc
And in checkout_events.module
Comment #9
sorabh.v6Hi Guys,
I was facing the same issue as well but for the newer version this patch wasn't working, so I rerolled the patch. Attaching the latest patch and interdiff file.
Thanks guys
Comment #10
sorabh.v6Sorry, correct patch in the comment.
Thanks