You are here

function mailchimp_ecommerce_get_cart in Mailchimp E-Commerce 7

Gets a cart from the current Mailchimp store.

Parameters

string $cart_id: The cart ID.

Return value

object|null The cart.

1 call to mailchimp_ecommerce_get_cart()
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 725
Mailchimp eCommerce core functionality.

Code

function mailchimp_ecommerce_get_cart($cart_id) {
  try {
    $store_id = mailchimp_ecommerce_get_store_id();
    if (empty($store_id)) {
      throw new Exception('Cannot get a cart without a store ID.');
    }

    /* @var \Mailchimp\MailchimpEcommerce $mc_ecommerce */
    $mc_ecommerce = mailchimp_get_api_object('MailchimpEcommerce');
    $order = $mc_ecommerce
      ->getCart($store_id, $cart_id);
    return $order;
  } catch (Exception $e) {
    if ($e
      ->getCode() == 404) {

      // Order doesn't exist in the store; no need to log an error.
    }
    else {
      mailchimp_ecommerce_log_error_message('Unable to get cart: ' . $e
        ->getMessage());
      mailchimp_ecommerce_show_error($e
        ->getMessage());
    }
  }
  return NULL;
}