Commercetools Adapter
Class Diagrams
Key Features
-
Unified Integration:
-
Provides a consistent and unified interface for interacting with Commercetools APIs.
-
Streamlines workflows for key e-commerce functions like products, categories, customers, orders, and inventory.
-
Reusable Adapters:
-
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.
-
Comprehensive Coverage:
-
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.
-
Dynamic Integration:
-
Built to adapt to MachC’s dynamic entities, so custom attributes or business-specific data can be seamlessly mapped to Commercetools resources.
-
Error Handling:
-
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
-
Product Management:
-
MachC’s
Product
entities are mapped to Commercetools Product Projections, syncing data such as name, description, SKU, and custom fields. -
Variant entities (
AbstractVariant
,DynamicVariant
) are translated into corresponding CommercetoolsProductVariant
entries. -
Order Submission:
-
When a
SubmitOrder
interactor is executed in MachC, the adapter translates the order data into a CommercetoolsOrderDraft
, submits it to the API, and retrieves the resulting order confirmation. -
User Management:
-
User profiles in MachC, such as
UserId
andUserProfile
, 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.