Skip to content

Commercetools Adapter

Class Diagrams

Classes

Key Features

  1. Unified Integration:

  2. Provides a consistent and unified interface for interacting with Commercetools APIs.

  3. Streamlines workflows for key e-commerce functions like products, categories, customers, orders, and inventory.

  4. Reusable Adapters:

  5. Contains modular adapters for handling specific aspects of the Commercetools API:

    • ProductAdapter: Manages synchronization of product entities and variants.
    • CategoryAdapter: Handles category assignments and updates.
    • OrderAdapter: Processes order submissions and updates, enabling seamless e-commerce workflows.
    • CustomerAdapter: Maps user accounts, profiles, and authentication mechanisms.
  6. Comprehensive Coverage:

  7. Supports core Commercetools modules, such as:

    • Product Management: Creating, updating, and retrieving product data.
    • Order Processing: Managing order submissions, payments, and fulfillment.
    • Customer Management: Handling user profiles, authentication, and account data.
    • Inventory Management: Keeping track of stock levels for products and variants.
  8. Dynamic Integration:

  9. Built to adapt to MachC’s dynamic entities, so custom attributes or business-specific data can be seamlessly mapped to Commercetools resources.

  10. Error Handling:

  11. Provides robust mechanisms for handling API exceptions and ensures that errors encountered during integration do not disrupt the system's core processes.

How It Works

The MachC Commercetools Adapter Library acts as a mediator between the domain components of the MachC project (e.g., Product, User, Order) and the Commercetools REST API. It translates the business logic and data structures from MachC into Commercetools-compatible formats and vice versa.

Workflow Example

  1. Product Management:

  2. MachC’s Product entities are mapped to Commercetools Product Projections, syncing data such as name, description, SKU, and custom fields.

  3. Variant entities (AbstractVariant, DynamicVariant) are translated into corresponding Commercetools ProductVariant entries.

  4. Order Submission:

  5. When a SubmitOrder interactor is executed in MachC, the adapter translates the order data into a Commercetools OrderDraft, submits it to the API, and retrieves the resulting order confirmation.

  6. User Management:

  7. User profiles in MachC, such as UserId and UserProfile, are mapped to Commercetools Customers, ensuring seamless authentication and profile synchronization.

Getting Started

Installation

To include the MachC Commercetools Adapter Library in your project:

pip install machc.commercetools

Configuration

Set up required authentication credentials for Commercetools:

ctp:
    client_id: <client_id>,
    client_secret: <ctp_secret_key>,
    project_key: <project_key>,
    scope: <scope>,
    api_url: <api_url>,
    auth_url: <auth_url>

Test

Running Tests with Coverage

To run the test suite and generate a test coverage report, use the following command:

$ pytest --cov-report term --cov=machc tests/
  • --cov=machc: Specifies the module (machc) for which coverage is measured.
  • --cov-report term: Outputs the coverage report directly to the terminal.
  • tests/: Indicates the directory where your test files are located.

This command ensures that all tests are executed while providing a detailed overview of how much code is covered by your tests.

References

  1. Commercetools Python SDK
  2. Composable Commerce
  3. Merchant Center
https://www.free-Counters.org