While setting up a site that sells both digital and physical products for a client, I discovered that I had a need for the ability to hide or show a pane that collects shipping information (I implemented hook_commerce_customer_profile_type_info() to declare a "shipping information" profile type) during checkout. Essentially, if the customer is buying only digital products, we don't want to collect a shipping address.
Unfortunately, as far as I know, there's currently no way to use rules to control the visibility of a checkout pane. Failing that, is there a hook that can be implemented to show or hide the pane based on a condition?
Either way, it might be handy to have a Rule event for "Selecting panes to be shown", with default rules for each of the panes. Then, if custom conditions are needed, they could just be added to the rules.
Comments
Comment #1
rszrama commentedLooking at the code, it appears that even though you can alter out panes from the form w/ hook_form_alter(), there's no way to change the submit handlers invoked upon form submission. That's a shame... the only thing you'd be able to do is use hook_commerce_checkout_pane_alter() and disable a pane based on the cart order... if you're doing this, make sure your implementation of the hook restricts itself to checkout URLs so it doesn't interfere with administration.
I'm not sure we need to make pane visibility Rules powered, but at the very least it should function as advertised when altered. To whit, we should probably be keeping in the form array a list of checkout pane submit callbacks to call (so they can be altered as necessary) instead of just getting them directly from the pane objects themselves like we are now:
Comment #2
claudiuenache commentedDid you mean hook_commerce_checkout_pane_info_alter instead of hook_commerce_checkout_pane_alter() ?
Comment #3
Drupa1ish commentedSee sample code http://drupal.org/node/1228342
Comment #4
Everett Zufelt commented@rszrama
I'm assuming that you meant hook_commerce_checkout_pane_info_alter() as I canoot find a hook_commerce_checkout_pane_alter().
Does anyone know if it is possible to get the cart / order contents )$commerce_line_items) from within hook_commerce_checkout_pane_info_alter()? The information doesn't seem to be available in the object passed into the function.
Comment #5
Everett Zufelt commentedFigured it out, from anywhere you can get the current user's $order with:
Thanks to #drupal-commerce :)
Comment #6
rszrama commentedhehe Awesome. And yeah, my bad - it's hook_commerce_checkout_pane_info_alter(). : O
Comment #7
kevinquillen commentedDoes this work to control checkout pane workflow from code on a per user basis, as per #5 using the cart loader function?
For example, I want to disable panes that don't need to exist for certain product types. Currently, I have two a generic Product (physical items) and a Registration (Commerce Registration + Registration). For physical items, we'd like to collect Billing Info, Shipping Info, and Payment information. If its an event registration, we want to scoot them directly to checkout and bypass the middle parts (including payment, that comes later).
I already have code that prevents mixing item types in a cart, but looking to put the pieces together on the pane workflow.
Comment #8
kevinquillen commentedWas able to affect the checkout workflow like so:
http://drupal.org/node/1733562#comment-6353766
But I am not sure how feasible this is (or stable?). I noticed I could not remove or disabled the 'Checkout' or 'Review' step- I only need one. Having both in my case is redundant, but I can't seem to get them to go away.
Comment #9
Everett Zufelt commentedTake a look at http://drupalcontrib.org/api/drupal/contributions!commerce!modules!check... it may help.
Comment #10
MarcElbichon commentedSee http://drupal.org/project/commerce_rules_extra
Comment #11
mrfelton commentedI need something similar for #1873502: Should not be able to apply userpoints as a discount when paying by userpoints where we need to dynamically show/hide checkout panes based on the selected payment processor. An approach based on hook_commerce_checkout_pane_info_alter alone will most likely not work, since payment processors can be changed without a page refresh. For this, we would need to be able to show/hide a checkout pane as part of the ajax event for changing the active payent processor.
Comment #12
nodecode commentedThe solution in #10 fantastic and flexible. Regarding the original issue raised here, that module clearly solves it.
Comment #13
torgospizzaI second the Commerce Rules Extra module - it works great for our needs: removing the Shipping address pane (from a single checkout page) when a cart only contains digital items.
However, I'd much prefer these additional rules be added into the core Commerce suite. Please consider it! :)
EDIT: It looks like there's actually a bug in the module, at the moment, that disables the checkout pane globally as opposed to the current user. I'm not sure if this is the best solution - I feel like this needs to be better supported in Commerce first, unless I've missed something.
Comment #14
star-szr@torgosPizza - Please see http://drupal.org/node/156119, since there is no patch to review setting back to 'active'.
Comment #15
kevinquillen commentedI'd agree with #13 - user based conditions on pane/page checkout states would work better on a more dynamic store. IE one that sells event tickets, digital goods, and physical goods, and stores that have services that don't require upfront payment. Each one of those scenarios has a different workflow.
Comment #16
MarcElbichon commented@torgosPizza. Can you explain bug by adding an issue in Commerce Rules Extra ?
Thanks in advance
Comment #17
nodecode commented@torgosPizza @MarcElbichon
Using Commerce Rules Extra I also didn't see the pane disabled "globally" either. The panes were only disabled for the current user in my testing. IMHO all is well with that solution.
Comment #18
torgospizzaAgree, after further testing it does seem to be just per the current user. IMO this is a fine solution. (Maybe not perfect but it surely works for now.)
Comment #19
spacebox commentedHad the same issue. Panes were disabled/enabled according to rules but sometimes they got disabled globally. I'm currently testing http://drupal.org/node/1949780 (included in latest dev).
Comment #20
MarcElbichon commented@spacebox
Can you open an issue in Commerce Rules Extra with a detailled example ?
Comment #21
luksakI had to find a solution to this very quickly. I came up with this kinda hacky solution:
I have the payment method is on the same page. This causes the payment form not being validated properly. Why could this be? Can the form values be retrieved better?
Comment #22
bojanz commentedWe should be using less Rules, not more. In any case, too late for 1.x