You are here

function mailchimp_ecommerce_delete_cart in Mailchimp E-Commerce 7

Deletes a cart in the current Mailchimp store.

Parameters

string $cart_id: The cart ID.

4 calls to mailchimp_ecommerce_delete_cart()
mailchimp_ecommerce_commerce_commerce_checkout_complete in modules/mailchimp_ecommerce_commerce/mailchimp_ecommerce_commerce.module
Implements hook_commerce_checkout_complete().
mailchimp_ecommerce_commerce_commerce_order_delete in modules/mailchimp_ecommerce_commerce/mailchimp_ecommerce_commerce.module
Implements hook_commerce_order_delete().
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 532
Mailchimp eCommerce core functionality.

Code

function mailchimp_ecommerce_delete_cart($cart_id) {
  try {
    $store_id = mailchimp_ecommerce_get_store_id();
    if (empty($store_id)) {
      throw new Exception('Cannot delete a cart without a store ID.');
    }
    if (mailchimp_ecommerce_use_queue()) {
      mailchimp_ecommerce_create_queue_item([
        'op' => 'deleteCart',
        'cart_id' => $cart_id,
        'store_id' => $store_id,
      ]);
    }
    else {

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

      // Cart doesn't exist; no need to log an error.
    }
    else {
      mailchimp_ecommerce_log_error_message('Unable to delete a cart: ' . $e
        ->getMessage());
      mailchimp_ecommerce_show_error($e
        ->getMessage());
    }
  }
}