Skip to content

Instantly share code, notes, and snippets.

@lsolesen
Created May 14, 2013 20:14
Show Gist options
  • Select an option

  • Save lsolesen/5579114 to your computer and use it in GitHub Desktop.

Select an option

Save lsolesen/5579114 to your computer and use it in GitHub Desktop.
function billysbilling_create_invoice_confirm($form, &$form_state, $order) {
$form['order_id'] = array('#type' => 'value', '#value' => $order->order_id);
return confirm_form($form,
t('Are you sure you want to invoice order @id?', array('@id' => $order->order_id)),
'admin/commercer/orders/' . $order->order_id . '/billysbilling',
t('This action cannot be undone.'),
t('Invoice'),
t('Cancel')
);
}
function billysbilling_create_invoice_confirm_submit($form, &$form_state) {
if ($form_state['values']['confirm']) {
$order = commerce_order_load($form_state['values']['order_id']);
$order_wrapper = entity_metadata_wrapper('commerce_order', $order);
if ($billysbilling_invoice_id = billysbilling_create_invoice($order)) {
$message = t('Successfully invoiced order @order_id as invoice id @invoice_id', array('@order_id' => $order->order_id, '@invoice_id' => $order_wrapper->billysbilling_invoice_id->value()));
}
else {
$message = t('An error occured while trying to invoice order @order_id as invoice id @invoice_id', array('@order_id' => $order->order_id, '@invoice_id' => $order_wrapper->billysbilling_invoice_id->value()));
}
watchdog('billysbilling', $message);
drupal_set_message($message);
)
$form_state['redirect'] = '<front>';
}
/**
* Page call back
*/
function billysbilling_pagecallback($order) {
$order_wrapper = entity_metadata_wrapper('commerce_order', $order);
// Order state should be higher at least checkout complete.
$not_invoicable = array('cart', 'checkout');
if (in_array($order_wrapper->state->value(), $not_invoicable)) {
return t('Order @order_id has order status "@status" and could not be invoiced.', array('@order_id' => $order->order_id, '@status' => $order_wrapper->state->value()));
}
if (!$order_wrapper->billysbilling_invoice_id->value()) {
return drupal_get_form('billysbilling_create_invoice_confirm');
/*
if ($billysbilling_invoice_id = billysbilling_create_invoice($order)) {
return t('Successfully invoiced order @order_id as invoice id @invoice_id', array('@order_id' => $order->order_id, '@invoice_id' => $order_wrapper->billysbilling_invoice_id->value()));
}
else {
return t('An error occured while trying to invoice order @order_id as invoice id @invoice_id', array('@order_id' => $order->order_id, '@invoice_id' => $order_wrapper->billysbilling_invoice_id->value()));
}
*/
}
return t('Order @order_id has been invoiced as @invoice_id', array('@order_id' => $order->order_id, '@invoice_id' => $order_wrapper->billysbilling_invoice_id->value()));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment