You are here

class MailchimpEcommerce in Mailchimp 8

Same name in this branch
  1. 8 lib/mailchimp-api-php/src/MailchimpEcommerce.php \Mailchimp\MailchimpEcommerce
  2. 8 lib/mailchimp-api-php/tests/src/MailchimpEcommerce.php \Mailchimp\Tests\MailchimpEcommerce

Mailchimp Ecommerce library test cases.

@package Mailchimp\Tests

Hierarchy

Expanded class hierarchy of MailchimpEcommerce

File

lib/mailchimp-api-php/tests/src/MailchimpEcommerce.php, line 12

Namespace

Mailchimp\Tests
View source
class MailchimpEcommerce extends \Mailchimp\MailchimpEcommerce {

  /**
   * Storage for stores. Used in place of real Mailchimp API.
   *
   * @var array $stores
   */
  private $stores = [];

  /**
   * Storage for customers. Used in place of real Mailchimp API.
   *
   * @var array $customers
   */
  private $customers = [];

  /**
   * Storage for orders. Used in place of real Mailchimp API.
   *
   * @var array $orders
   */
  private $orders = [];

  /**
   * @inheritdoc
   */
  public function __construct($api_key = 'apikey', $api_user = 'apikey', $http_options = []) {
    $this->client = new MailchimpTestHttpClient();
  }
  public function getClient() {
    return $this->client;
  }
  public function getEndpoint() {
    return $this->endpoint;
  }

  /**
   * @inheritdoc
   */
  public function getStore($store_id, $parameters = []) {
    parent::getStore($store_id, $parameters);
    return isset($this->stores[$store_id]) ? $this->stores[$store_id] : NULL;
  }

  /**
   * @inheritdoc
   */
  public function addStore($id, $store, $parameters = [], $batch = FALSE) {
    parent::addStore($id, $store, $batch);
    $parameters = [
      'id' => $id,
    ];
    $parameters += $store;
    $this->stores[$id] = (object) $parameters;
  }

  /**
   * @inheritdoc
   */
  public function getCustomer($store_id, $customer_id, $parameters = []) {
    parent::getCustomer($store_id, $customer_id, $parameters);
    if (isset($this->customers[$store_id])) {
      return isset($this->customers[$store_id][$customer_id]) ? $this->customers[$store_id][$customer_id] : NULL;
    }
    return NULL;
  }

  /**
   * @inheritdoc
   */
  public function addCustomer($store_id, $customer, $batch = FALSE) {
    parent::addCustomer($store_id, $customer, $batch);
    if (!isset($this->customers[$store_id])) {
      $this->customers[$store_id] = [];
    }
    $this->customers[$store_id][$customer['id']] = (object) $customer;
  }

  /**
   * @inheritdoc
   */
  public function getOrder($store_id, $order_id, $parameters = []) {
    parent::getOrder($store_id, $order_id, $parameters);
    if (isset($this->orders[$store_id])) {
      return isset($this->orders[$store_id][$order_id]) ? $this->orders[$store_id][$order_id] : NULL;
    }
    return NULL;
  }

  /**
   * @inheritdoc
   */
  public function addOrder($store_id, $id, array $customer, array $order, $batch = FALSE) {
    parent::addOrder($store_id, $id, $customer, $order, $batch);
    if (empty($store_id)) {
      throw new MailchimpAPIException('Store ID cannot be empty.');
    }
    if (empty($id)) {
      throw new MailchimpAPIException('Order ID cannot be empty.');
    }
    if (empty($customer)) {
      throw new MailchimpAPIException('Customer cannot be empty.');
    }
    if (empty($order)) {
      throw new MailchimpAPIException('Order cannot be empty.');
    }
    if (!isset($order['lines']) || empty($order['lines'])) {
      throw new MailchimpAPIException('Order must contain at least one line item.');
    }
    if (!isset($this->orders[$store_id])) {
      $this->orders[$store_id] = [];
    }
    $parameters = [
      'id' => $id,
      'customer' => (object) $customer,
    ];
    $parameters += $order;
    $this->orders[$store_id][$id] = (object) $parameters;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
Mailchimp::$api_key private property The Mailchimp API key to authenticate with.
Mailchimp::$api_user private property The Mailchimp API username to authenticate with.
Mailchimp::$batch_operations private property Array of pending batch operations.
Mailchimp::$client protected property The HTTP client.
Mailchimp::$debug_error_code private property A Mailchimp API error code to return with every API response.
Mailchimp::$endpoint protected property The REST API endpoint.
Mailchimp::$version public property API version.
Mailchimp::addBatchOperation protected function Adds a pending batch operation.
Mailchimp::DEFAULT_DATA_CENTER constant
Mailchimp::ERROR_CODE_API_KEY_INVALID constant
Mailchimp::ERROR_CODE_API_KEY_MISSING constant
Mailchimp::ERROR_CODE_BAD_REQUEST constant
Mailchimp::ERROR_CODE_COMPLIANCE_RELATED constant
Mailchimp::ERROR_CODE_FORBIDDEN constant
Mailchimp::ERROR_CODE_INTERNAL_SERVER_ERROR constant
Mailchimp::ERROR_CODE_INVALID_ACTION constant
Mailchimp::ERROR_CODE_INVALID_METHOD_OVERRIDE constant
Mailchimp::ERROR_CODE_INVALID_RESOURCE constant
Mailchimp::ERROR_CODE_JSON_PARSE_ERROR constant
Mailchimp::ERROR_CODE_METHOD_NOT_ALLOWED constant
Mailchimp::ERROR_CODE_REQUESTED_FIELDS_INVALID constant
Mailchimp::ERROR_CODE_RESOURCE_NESTING_TOO_DEEP constant
Mailchimp::ERROR_CODE_RESOURCE_NOT_FOUND constant
Mailchimp::ERROR_CODE_TOO_MANY_REQUESTS constant
Mailchimp::ERROR_CODE_USER_DISABLED constant
Mailchimp::ERROR_CODE_WRONG_DATACENTER constant
Mailchimp::getAccount public function Gets Mailchimp account information for the authenticated account.
Mailchimp::getBatchOperation public function Gets the status of a batch request.
Mailchimp::getDataCenter private function Gets the ID of the data center associated with an API key.
Mailchimp::getDefaultHttpClient private function Instantiates a default HTTP client based on the local environment.
Mailchimp::processBatchOperations public function Processes all pending batch operations.
Mailchimp::request public function Makes a request to the Mailchimp API.
Mailchimp::setClient public function Sets a custom HTTP client to be used for all API requests.
Mailchimp::setDebugErrorCode public function Sets a Mailchimp error code to be returned by all requests.
Mailchimp::VERSION constant
MailchimpEcommerce::$customers private property Storage for customers. Used in place of real Mailchimp API.
MailchimpEcommerce::$orders private property Storage for orders. Used in place of real Mailchimp API.
MailchimpEcommerce::$stores private property Storage for stores. Used in place of real Mailchimp API.
MailchimpEcommerce::addCart public function Adds a new cart to a store.
MailchimpEcommerce::addCartLine public function Add a new line item to an existing cart.
MailchimpEcommerce::addCustomer public function @inheritdoc Overrides MailchimpEcommerce::addCustomer
MailchimpEcommerce::addOrder public function @inheritdoc Overrides MailchimpEcommerce::addOrder
MailchimpEcommerce::addOrderLine public function Add a new line item to an existing order.
MailchimpEcommerce::addProduct public function Add a product to a store.
MailchimpEcommerce::addProductVariant public function Add a variant to a product.
MailchimpEcommerce::addStore public function @inheritdoc Overrides MailchimpEcommerce::addStore
MailchimpEcommerce::deleteCart public function Deletes a cart.
MailchimpEcommerce::deleteCartLine public function Deletes a line item in a cart.
MailchimpEcommerce::deleteCustomer public function Deletes a customer from a store.
MailchimpEcommerce::deleteOrder public function Deletes an order.
MailchimpEcommerce::deleteProduct public function Delete a product.
MailchimpEcommerce::deleteProductVariant public function Delete a specific variant of a specific product.
MailchimpEcommerce::deleteStore public function Deletes a Mailchimp store.
MailchimpEcommerce::getCart public function Get information about a specific cart.
MailchimpEcommerce::getCartLine public function Get information about a specific cart line item.
MailchimpEcommerce::getCartLines public function Get information about a cart's line items.
MailchimpEcommerce::getCarts public function Get information about a store’s carts.
MailchimpEcommerce::getClient public function
MailchimpEcommerce::getCustomer public function @inheritdoc Overrides MailchimpEcommerce::getCustomer
MailchimpEcommerce::getCustomers public function Get information about a store's customers.
MailchimpEcommerce::getEndpoint public function
MailchimpEcommerce::getOrder public function @inheritdoc Overrides MailchimpEcommerce::getOrder
MailchimpEcommerce::getOrderLine public function Get information about a specific order line item.
MailchimpEcommerce::getOrderLines public function Get information about an order's line items.
MailchimpEcommerce::getOrders public function Get information about a store's orders.
MailchimpEcommerce::getProduct public function Get information about a specific product.
MailchimpEcommerce::getProducts public function Get information about all products for a store.
MailchimpEcommerce::getProductVariant public function Get information about a specific variant of a specific product.
MailchimpEcommerce::getProductVariants public function Get information on all variants of a specific product.
MailchimpEcommerce::getStore public function @inheritdoc Overrides MailchimpEcommerce::getStore
MailchimpEcommerce::getStores public function Gets information about all stores in the account.
MailchimpEcommerce::updateCart public function Updates a specific cart.
MailchimpEcommerce::updateCartLine public function Updates an existing line item in a cart.
MailchimpEcommerce::updateCustomer public function Update a customer.
MailchimpEcommerce::updateOrder public function Update a specific order.
MailchimpEcommerce::updateProduct public function Update a product in a store.
MailchimpEcommerce::updateProductVariant public function Update a specific variant of a specific product.
MailchimpEcommerce::updateStore public function Updates a store.
MailchimpEcommerce::__construct public function @inheritdoc Overrides Mailchimp::__construct