function mailchimp_ecommerce_add_cart in Mailchimp E-Commerce 7
Adds a new cart to the current Mailchimp store.
Parameters
string $cart_id: The cart ID.
array $customer: Associative array of customer information.
- id (string): A unique identifier for the customer.
array $cart: Associative array of cart 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...
4 calls to mailchimp_ecommerce_add_cart()
- 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_ubercart_batch_add_orders in modules/
mailchimp_ecommerce_ubercart/ mailchimp_ecommerce_ubercart.module - Batch callback used to add orders to Mailchimp.
- mailchimp_ecommerce_ubercart_uc_order in modules/
mailchimp_ecommerce_ubercart/ mailchimp_ecommerce_ubercart.module - Implements hook_uc_order().
- _mailchimp_ecommerce_commerce_send_cart in modules/
mailchimp_ecommerce_commerce/ mailchimp_ecommerce_commerce.module - Private function to send cart data to Mailchimp.
File
- ./
mailchimp_ecommerce.module, line 416 - Mailchimp eCommerce core functionality.
Code
function mailchimp_ecommerce_add_cart($cart_id, array $customer, array $cart) {
try {
$store_id = mailchimp_ecommerce_get_store_id();
if (empty($store_id)) {
throw new Exception('Cannot add a cart without a store ID.');
}
// Do nothing with no email.
if (!$customer['email_address']) {
return;
}
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)) {
$cart['campaign_id'] = $campaign_id;
$cart['landing_site'] = isset($_SESSION['mc_landing_site']) ? $_SESSION['mc_landing_site'] : '';
}
if (mailchimp_ecommerce_use_queue()) {
mailchimp_ecommerce_create_queue_item([
'op' => 'addCart',
'cart_id' => $cart_id,
'store_id' => $store_id,
'customer' => $customer,
'cart' => $cart,
]);
}
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;
$mc_ecommerce
->addCart($store_id, $cart_id, $customer, $cart);
}
} catch (Exception $e) {
mailchimp_ecommerce_log_error_message('Unable to add a cart: ' . $e
->getMessage());
mailchimp_ecommerce_show_error($e
->getMessage());
}
}