Cart
@archibald/commerce/cart implements the @archibald/cart contract against the SAP Commerce cart OCC API: an adapter and schema set for the client, a provider for the server, and a prebuilt factory that ties them together.
How to use
Server
Register the CartModule with the commerce provider:
// src/{platform}/server/module/server.tsx
import { CartModule } from '@archibald/cart';
import { CommerceCartProvider } from '@archibald/commerce/cart';
new CartModule({
provider: new CommerceCartProvider({ config: () => this.configService.get('hybris.api') })
});
Client
The shortcut is the prebuilt factory — CommerceCart is a CartFactory created from the commerce definition (adapter + schema already paired):
// src/{platform}/client/api/creators/cart.ts
import { CommerceCart } from '@archibald/commerce/cart';
import { api } from 'shop/client/api';
export default CommerceCart.createClient({ api });
Build your own CartFactory from CommerceCartAdapter and CommerceCartSchema instead when you extend the schema with project fields — see Cart setup.
API reference
| Export | Side | What it is |
|---|---|---|
CommerceCart | client | Prebuilt CartFactory (createClient({ api })) from commerceDefinition |
CommerceCartAdapter | client | CartAdapter implementation shaping cart calls for the OCC API |
CommerceCartSchema, CartEntrySchema, DeliveryModeSchema, … | client | zod schemas + inferred types for the OCC cart shape (entries, vouchers, delivery, payment) |
| Cart hooks & context | client | Re-exported cart hooks bound to the commerce schema |
CommerceCartProvider | server | CartModule provider translating cart operations into OCC v2 calls |
Configuration
Reads hybris.api (host, base site, OCC paths) from the environment config through the config callback given to the provider.
Further documentation
- Cart guide — the headless cart architecture.
- Cart setup · CartFactory