Download & Extend

Allow administrators to embed contrib checkout panes in the Express Checkout review pane

Project:Commerce PayPal
Version:7.x-2.x-dev
Component:PayPal EC
Category:task
Priority:normal
Assigned:Unassigned
Status:closed (fixed)

Issue Summary

From #1864842-7: Add support for PayPal Express Checkout and related to #1882494: Refresh Express Checkout orders after retrieving customer profile info from PayPal:

Additionally, in commerce_paypal_ec.checkout_pane.inc you'll see the @todo notes indicating that we need to give administrators the ability to enable checkout panes on the special Express Checkout review pane. This will let us show the Shipping services pane on this page, for example, even if in the normal checkout workflow it appears on an earlier page.

Not sure I need to elaborate much here, but to reiterate, we need to add settings to the Express Checkout review checkout pane that let administrators embed other checkout panes inside this checkout pane. The idea is that we have our own checkout page and pane accessible only by Express Checkout orders, using the checkout router to access it when necessary. When customers do land here, it's because we need them to review their order before we submit our DoPayment API request, and if, for example, we have Shipping on the site, then they need to choose a shipping service before we know how much to charge.

The setting for this can just be a checkboxes element of checkout panes to include in the pane - but we should actually leave out the core Commerce checkout panes: cart_contents, commerce_payment, commerce_payment_redirect, checkout_review, checkout_completion_message, and the customer profile panes. All those things have been entered at PayPal, and we don't need to request duplicate information.

If a contrib checkout pane is marked for inclusion, it's going to have to be returned as part of the checkout pane form and then validated / submitted in the Express Checkout review pane's submit handler. There should be a @todo placeholder for this in the code as well.

Comments

#1

Here is a try to allow administrators to embed contrib checkout panes in the Express Checkout review pane
But I don't know why the _validate and _submit functions of the checkout pane are never called. To temporarily bypass this problem, I've moved these two functions in the .module file.

Also because validate and submit function are waiting their information at the root of the $form and $form_state['values'] I've created fakes $form and $form_state to not dirty the real variables.

    $pane_form = $form;
    $pane_form[$pane_id] = $pane_form['paypal_ec_review'][$pane_id]['data'];
    $pane_form_state = $form_state;
    $pane_form_state['values'][$pane_id] = $form_state['values']['paypal_ec_review'][$pane_id]['data'];
AttachmentSize
commerce_paypal-embed_contrib_checkout_panes_in_the_Express_Checkout_review_pane-1882502-1.patch 10.01 KB

#2

Status:active» needs review

#3

Assigned to:JulienD» Anonymous
Status:needs review» fixed

Great patch - thanks for working through it. I realized when I saw in your patch that I had explicitly set #validate and #submit handlers on the "Pay now" button what was wrong with the functions being invoked properly. The thing is since this Express Checkout review page does not use the normal checkout form submit buttons, the checkout pane validate / submit handlers and such aren't going to be automatically invoked as they would on other pages. We specify them explicitly for the "Pay now" button so it can validate and submit properly when clicked.

Since the handlers reside in an include file, we have to specify in $form_state['build_info']['files'] that the .checkout_pane.inc file should be included when the form is rebuilt. If you grep core Commerce for build_info you can see the various places we're using it in core. Turns out setting the key to "file" is unnecessary, as the files array in build_info works much like validate / submit handler arrays.

I renamed variables in here for consistency with other parts of Commerce (a checkout pane is always $checkout_pane and its ID is $pane_id) but also for clarity - instead of just using $checkout_pane for the embedded checkout panes I used $embedded_checkout_pane. Same for $pane_id => $embedded_pane_id. In the validate handler, I also got rid of the data array and used simpler $form_copy and $form_state_copy arrays that included the necessary form elements and values in the root of those arrays as expected by the checkout pane validate / submit handlers.

Finally, I did some testing with the shipping service checkout pane, and everything worked great! Multiple products, discounts, shipping, taxes, etc. all went through successfully. I then tested with a forced form error on the shipping service checkout pane, and that worked fine, too. I'm assuming that means we don't need your @todo any more about catching errors, so I've removed that.

This feature was the last remaining major feature of our integration. Glad we got it committed. : )

Commit: http://drupalcode.org/project/commerce_paypal.git/commitdiff/335df49

#4

Great !

This is exactly what I was looking for, I tried to find some examples but did not succeed. In fact I was looking for something in the $form not in $form_state. Thanks for the explanation Ryan !

+  $form_state['build_info']['files']['pane'] = drupal_get_path('module', 'commerce_paypal_ec') . '/includes/commerce_paypal_ec.checkout_pane.inc';

#5

Status:fixed» closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

nobody click here