Definition

hook_checkoutapi(&$txn, $op, $arg3 = NULL, $arg4 = NULL)
ecommerce-5--4/docs/developer/hooks/ec_checkout.php, line 71

Description

Manipulate the checkout process, including injecting form pages.

Checkoutapi can be implemented by any module. It can be used to insert a page into the checkout process and even validate/save the form data. Another feature of the API is the ability to push data onto the final review page before final checkout. Note that the order of the form pages is controlled via http://example.com/index.php?q=admin/store/checkout

Parameters

&$txn The transaction object for an order. This keeps growing in data from screen to screen.

$op What kind of action is being performed. Possible values:

  • "init": Code which is called when the checkout is started. This can be used to set up the defaults and then skip pass any other screen.
  • "form": Inject a form page into the checkout process. Don't forget to add a submit button. If the $txn->exclude_screen is set to the name of the module, this this will be skipped in the next round of processing.
  • "save": The injected form page has been submitted. Save your data in this hook. IMPORTANT: $txn->screen must be incremented here in order to go to the next screen! $txn->screen++;
  • "validate": The customer has just finished editing the form page and is trying to submit it. This hook can be used to check or even modify the transaction object. Errors should be set with form_set_error().
  • "review": The last page of the checkout process is being viewed before the order is placed.
  • "review_validate": validation for review page. Called within the form validate hook so has same requirements.
  • "review_save": save section of the review page. Called within the form submit hook and has same requirements.
  • "post_process": This is called after the transaction has been saved into the database.
$arg3
  • Optional parameter to pass along.
$arg4
  • Optional parameter to pass along.

Return value

This varies depending on the operation.

  • The "save" and "validate" operations have no return value.
  • The "form" returns a form array to build the modules checkout screen.
  • The "review" operation should return a form array. The themeing is done by theme_hook_review_form
  • The "review_validate" operations have no return value.
  • The "review_submit" operations have no return value.
  • The "post_process" operations will return a formapi compatible url to redirect to. eg 'products' or array('product', 'page=5')

Related topics

Namesort iconDescription
HooksAllow modules to interact with the Drupal core.

Code

<?php
function hook_checkoutapi(&$txn, $op, $arg3 = NULL, $arg4 = NULL) {
  $output = '';
  switch ($op) {
    case 'form':
      // TODO: another example, old example called payment api
      break;
      
    case 'validate':
      if (empty($txn->payment_method)) {
        form_set_error('payment_method', t('Please choose a payment method.'));
      }
      break;

    case 'save':
      $txn->screen++;
      break;

    case 'review':
      // TODO: another example, old example called payment api
      break;

    case 'review_validate':
      break;

    case 'review_save':
      break;
  }
}
?>