You are here

public function CartHandler::getCart in Mailchimp E-Commerce 8

@inheritdoc

Overrides CartHandlerInterface::getCart

1 call to CartHandler::getCart()
CartHandler::cartExists in src/CartHandler.php
@inheritdoc

File

src/CartHandler.php, line 60

Class

CartHandler
Cart handler.

Namespace

Drupal\mailchimp_ecommerce

Code

public function getCart($cart_id) {
  $cart = NULL;
  try {
    $store_id = $this->helper
      ->getStoreId();
    if (empty($store_id)) {
      throw new \Exception('Cannot get the requested cart without a store ID.');
    }
    try {
      $cart = $this->mcEcommerce
        ->getCart($store_id, $cart_id);
    } catch (\Exception $e) {
      if ($e
        ->getCode() == 404) {

        // Cart doesn't exist.
      }
      else {

        // An actual error occurred; pass on the exception.
        throw new \Exception($e
          ->getMessage(), $e
          ->getCode(), $e);
      }
    }
  } catch (\Exception $e) {

    //mailchimp_ecommerce_log_error_message('Unable to get the requested cart: ' . $e->getMessage());
    $this->messenger
      ->addError($e
      ->getMessage());
  }
  return $cart;
}