Extending Commerce Logic
The Archibald framework is designed with extensibility in mind. You can customize standard commerce behavior through File Shadowing and Custom Mappers.
File Shadowing
File shadowing is the most powerful way to extend the framework. It allows you to override core files with your own project-specific logic.
How it works
The build system prioritizes files in the following order:
src/{platform}/.../tenant/{tenant}/src/{platform}/.../src/shop/.../(Base fallback)
Example: Shadowing a Product Mapper
If you need to add a custom field to the product data that comes from SAP Commerce, you can shadow the ProjectCommerceProductMapper.
- Locate the base file:
integrations/commerce/src/product/server/classes/mappers/project-commerce-product-mapper.ts. - Create your shadow: Create a file with the same name in
templates/shop/src/shop/server/classes/. - Implement your logic:
import { CommerceProductMapper } from '@archibald/commerce/product';
export class ProjectCommerceProductMapper extends CommerceProductMapper {
public override map(rawProduct: any) {
const product = super.map(rawProduct);
// Add your custom field
return {
...product,
customBadge: rawProduct.customProperty === 'VIP' ? 'Special Offer' : null
};
}
}
Custom Providers
All commerce server modules (Cart, Product, Search, etc.) use a provider pattern. You can create a custom provider to connect to a different data source.
Example: Custom Cart Provider
import { CartProvider } from '@archibald/cart';
export class MyCustomCartProvider extends CartProvider {
public async getCart(cartId: string) {
// Implement your own fetching logic (e.g., from a different API or Database)
}
// ... implement other abstract methods
}
Then register it in your CoreServer:
new CartModule({
provider: new MyCustomCartProvider()
})