craft-commerce-headless-sdk v1.0.6
Craft Commerce Headless SDK Documentation Index
This SDK is designed to simplify integration with Craft Commerce, offering specialized modules for users, carts, payments, subscriptions, and more. Whether you're building a headless e-commerce application or enhancing an existing Craft Commerce setup, this guide will help you navigate and implement the SDK effectively.
Note: Craft Commerce version 4 or higher is required for compatibility with this SDK.
Table of Contents
- Demo and Local Testing
- Craft CMS Configuration Guide
- Package Installation
- Client Module
- Users Module
- Cart Module
- Payment Sources Module
- Payment Module
- Subscriptions Module
- Suggestions for Craft CMS Improvements
Demo and Local Testing
You can see a working demo of the SDK at this link:
https://craft-commerce-headless-sdk.netlify.app/
If you want to test the SDK locally, follow these steps:
1. Clone the repository.
2. Navigate to the demo
folder.
3. Run the following commands:
npm install
npm run dev
This will start the demo locally. Before using the SDK, ensure that Craft CMS and Craft Commerce are correctly configured for headless usage. Follow the Craft CMS Configuration Guide for essential setup steps, including CORS configuration and cookie settings.
Craft CMS Configuration Guide
This section provides details on configuring Craft CMS for headless usage, including CORS setup and other necessary settings.
Package Installation
To use the Craft Commerce Headless SDK in your project, you can install it using your preferred package manager. Here are the commands for different managers:
npm
npm install craft-commerce-headless-sdk
pnpm
pnpm add craft-commerce-headless-sdk
yarn
yarn add craft-commerce-headless-sdk
After installation, you can import the SDK in your code:
import { craftCommerceHeadlessSdk } from 'craft-commerce-headless-sdk';
Client Module
The base module for API communication, handling HTTP requests with post
and get
methods.
Users Module
This module handles user account creation, profile management, and address handling. It simplifies operations like login, password resets, and managing user-related data, all essential for e-commerce platforms.
Cart Module
Manage shopping cart actions, including retrieval, updates, and checkout operations. This module supports typical e-commerce workflows in Craft Commerce.
Payment Sources Module
Create, manage, and assign payment methods to user accounts. This module supports common payment operations like adding or removing payment sources, tailored for Craft Commerce.
Payment Module
Handle payments, including support for 3D Secure and other gateway integrations. This module streamlines the process of initiating and completing payments in Craft Commerce.
Subscriptions Module
Manage subscriptions, including plan creation, cancellations, switching, and reactivation. This module simplifies recurring payment setups in Craft Commerce.
Suggestions for Craft CMS Improvements
While this SDK provides extensive functionality, there are a few additional features that would greatly enhance the integration experience if included directly in Craft CMS or Craft Commerce:
Include Available Payment Gateways in the Cart: Similar to how shipping methods are returned, having payment gateways listed directly in the cart data would streamline the checkout process and improve integration ease.
Return User-Associated Addresses: Adding a feature to retrieve addresses associated with a user, similar to the
actions/users/session-info
method for session data, would simplify managing user information in headless implementations.