The situation; Trying to include the checkout process in a modal window. User clicks “add to cart” -link and a modal window (or alternatively an ajax load into a div in the same window) is used to show the checkout form. Right now, i’m not clear with the "Drupal way" of how to work properly with commerce and ctools.
Ctools and its API is the current choice to go with. I'm all willing to consider alternatives for Ctools. So far, i’ve been unable to include the checkout form in the ctools modal. The ctools code works fine with forms such as user register, login etc.
Basically our checkout configuration includes just 2 checkboxes in the Checkout pane. Checkbox -fields are included in the checkout with “Commerce Order Fieldgroup Panes” -module. So there is basically just one step for the user to go thru the checkout process.
Depending on the user data and submitted checkbox values, we do a redirect or internal payment handling with a third party payment gateway with which i’ve been building a custom payment module which is working fine with Commerce.
So back to the modal.
I’ve built a callback function according to the tutorials and ctools ajax samples.. i’ve tried several combinations to include and render the checkout form in a modal with no success. I’m wondering if the problem lies within commerce checkout process or ctools functions unable to gather/render the specified checkout form. Or probably just that the commerce / checkout API is not used correctly with ctools functions. I don’t yet know commerce at the Deep level so the internal checkout procedure is still a bit in the dark.
I will not include all the code combinations here now, just want to point out the considered alternatives/directions:
-programmatically include the checkout form with ctools:
<?php
$checkoutform = ctools_modal_form_wrapper('commerce_checkout_form_checkout', $form_state);
print ajax_render($checkoutform);
?>
The form id is caught from the default checkout page form using form_alter. the ctools_modal_form_wrapper -function does not return a valid checkout form array. Suspecting that ctools does not support commerce checkout form out of box. I’m considering that the $form_state needs to be filled with some extra data before the function call could return the full checkout array? Or maybe we need to get the checkout form array using some other method?
Or
-Programmatically include the enabled checkout panes, which would(?) include the rendered checkout form:
<?php
$panes_array = commerce_checkout_panes($conditions = array('enabled' => TRUE), FALSE);
?>
Or
-Create the order and checkout page programmatically in the callback function and get the form:
<?php
drupal_get_form('commerce_checkout_form_' . $checkout_page['page_id'], $order, $checkout_page);
?>
This form call is copied from commerce_checkout.pages.inc. With this it is possible to get a form array that looks like it might have the needed data to continue.. I’ve tried to render the array with ajax_render(), ctools_modal_render(), ctools_modal_form_render() ..resulting in either 200 Http ajax error or a blank form (no visible html or fields) or just the ajax loader gif looping in the modal.
Or
-Use a custom form to build the checkboxes and handle forward the submission data to Commerce:
..so we would not need to include the actual “commerce_checkout_form_checkout” if it happens that ctools refuses to function with it..
Or
Programmatically include the checkout pages (with panes/form included?):
using commerce_checkout_pages() -function and a render function. Of course we could try to open the default checkout url in a modal but this would include the whole DOM in the modal, which we don’t want.
Thank you! -Jussi