function mailchimp_ecommerce_add_order in Mailchimp E-Commerce 7
Adds a new order to the current Mailchimp store.
Parameters
string $order_id: The order ID.
array $customer: Associative array of customer information.
- id (string): A unique identifier for the customer.
array $order: Associative array of order information.
- currency_code (string): The three-letter ISO 4217 currency code.
- order_total (float): The total for the order.
- lines (array): An array of the order's line items.
See also
http://developer.mailchimp.com/documentation/mailchimp/reference/ecommer...
6 calls to mailchimp_ecommerce_add_order()
- MailchimpEcommerceTestCase::testAddOrder in tests/
mailchimp_ecommerce.test - Tests adding an order to Mailchimp.
- MailchimpEcommerceTestCase::testAddOrderNoLineItems in tests/
mailchimp_ecommerce.test - Tests adding an order to Mailchimp with no line items.
- mailchimp_ecommerce_commerce_batch_add_orders in modules/
mailchimp_ecommerce_commerce/ mailchimp_ecommerce_commerce.module - Batch callback used to add orders to MailChimp.
- mailchimp_ecommerce_commerce_commerce_checkout_complete in modules/
mailchimp_ecommerce_commerce/ mailchimp_ecommerce_commerce.module - Implements hook_commerce_checkout_complete().
- mailchimp_ecommerce_ubercart_batch_add_orders in modules/
mailchimp_ecommerce_ubercart/ mailchimp_ecommerce_ubercart.module - Batch callback used to add orders to Mailchimp.
File
- ./
mailchimp_ecommerce.module, line 766 - Mailchimp eCommerce core functionality.
Code
function mailchimp_ecommerce_add_order($order_id, array $customer, array $order) {
try {
$store_id = mailchimp_ecommerce_get_store_id();
if (empty($store_id)) {
throw new Exception('Cannot add an order without a store ID.');
}
if (!mailchimp_ecommerce_validate_customer($customer)) {
// A user not existing in the store's Mailchimp list/audience is not an error, so
// don't throw an exception.
return;
}
$campaign_id = mailchimp_ecommerce_get_campaign_id();
if (!empty($campaign_id)) {
$order['campaign_id'] = $campaign_id;
$order['landing_site'] = isset($_SESSION['mc_landing_site']) ? $_SESSION['mc_landing_site'] : '';
}
if (mailchimp_ecommerce_use_queue()) {
mailchimp_ecommerce_create_queue_item([
'op' => 'addOrder',
'store_id' => $store_id,
'order_id' => $order_id,
'customer' => $customer,
'order' => $order,
]);
}
else {
$list_id = mailchimp_ecommerce_get_list_id();
/* @var \Mailchimp\MailchimpEcommerce $mc_ecommerce */
$mc_ecommerce = mailchimp_get_api_object('MailchimpEcommerce');
// Pull member information to get member status.
$memberinfo = mailchimp_get_memberinfo($list_id, $customer['email_address'], TRUE);
$customer['opt_in_status'] = isset($memberinfo->status) && $memberinfo->status == 'subscribed' ? TRUE : FALSE;
// Increment customer totals
$remote_customer = mailchimp_ecommerce_get_customer($customer['id']);
// Customer doesn't exist in the store.
if (!$remote_customer) {
return;
}
$customer['orders_count'] = $remote_customer->orders_count + 1;
$customer['total_spent'] = $remote_customer->total_spent + $order['order_total'];
$mc_ecommerce
->addOrder($store_id, $order_id, $customer, $order);
}
} catch (Exception $e) {
mailchimp_ecommerce_log_error_message('Unable to add an order: ' . $e
->getMessage());
mailchimp_ecommerce_show_error($e
->getMessage());
}
}