Skip to main content

CommerceCMSProvider

This is the default CMSProvider implementation included in the @archibald/commerce package. It is specifically designed to connect to a SAP Commerce (Hybris) instance using the OCC (Omni Commerce Connect) APIs.

Usage

This provider is instantiated and passed to the CMSModule during server initialization. It requires the API configuration for the SAP Commerce backend.

// In your Server's initModules method:
new CMSModule({
provider: new CommerceCMSProvider({ config: hybris.api })
})

Deep Dive

Description: The CommerceCMSProvider is a concrete, out-of-the-box implementation of the CMSProvider. It serves as a ready-made solution for projects using SAP Commerce as their CMS and is the default for the Archibald Shop template.

  • How To: Use this provider when your project's content is managed within SAP Commerce (e.g., in SmartEdit). Simply configuring the CMSModule with this provider is enough to get the entire CMS data-fetching pipeline working for SAP Commerce.

    // Correct: Typical setup in a shop template.
    const { hybris } = this.configService.get();
    await this.registerModules([
    new CMSModule({
    provider: new CommerceCMSProvider({ config: hybris.api })
    }),
    ]);
  • Best Practice: While the CommerceCMSProvider works out of the box, you can still extend it if you need to add custom functionality or override specific behaviors for your project's SAP Commerce implementation. For example, you could extend it to call a custom API for additional data and merge it into the page response.

    // Correct: Extending the default provider for custom needs.
    import { CommerceCMSProvider as BaseProvider, Page, DefaultResponse } from '@archibald/commerce/cms';

    class CustomCommerceProvider extends BaseProvider {
    public async getPage(options: any): Promise<DefaultResponse<Page | null>> {
    // Call the original getPage method
    const response = await super.getPage(options);

    // Fetch additional data from another service
    if (response.data) {
    const extraData = await this.fetchExtraData(response.data.uid);
    response.data.extraContent = extraData; // Augment the response
    }

    return response;
    }

    private async fetchExtraData(pageUid: string): Promise<any> {
    // ... logic to fetch from a custom endpoint
    }
    }