You are here

public function OrderHandler::addOrder in Mailchimp E-Commerce 8

@inheritdoc

Overrides OrderHandlerInterface::addOrder

File

src/OrderHandler.php, line 39

Class

OrderHandler
Order handler.

Namespace

Drupal\mailchimp_ecommerce

Code

public function addOrder($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;
    }

    // Get the Mailchimp campaign ID, if available.
    $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'] : '';
    }

    /* @var \Mailchimp\MailchimpEcommerce $mc_ecommerce */
    $mc_ecommerce = mailchimp_get_api_object('MailchimpEcommerce');
    $mc_ecommerce
      ->addOrder($store_id, $order_id, $customer, $order);
  } catch (\Exception $e) {
    mailchimp_ecommerce_log_error_message('Unable to add an order: ' . $e
      ->getMessage());
    drupal_set_message($e
      ->getMessage(), 'error');
  }
}