A custom field app for Agility CMS that enables content editors to browse, search, and attach CommerceTools products to their content items. Built using the Agility Apps SDK v2.
App URL: https://commercetools-app.agilitycms.com/ Documentation: https://agilitycms.com/docs/apps/commercetools
This app provides a seamless integration between Agility CMS and CommerceTools, allowing content editors to:
- Browse and search CommerceTools products directly within the Agility CMS interface
- Attach product information to content items using a custom field
- View product details including images, SKU, pricing, variants, and categories
- Access products via infinite scroll pagination for large catalogs
- Custom Product Field: Add a CommerceTools product picker field to any content definition in Agility CMS
- Product Search: Search products by name (when Product Projection Search is enabled)
- Product Browser Modal: Interactive product selection interface with infinite scroll
- Product Details Display: Rich product information display including:
- Product images
- SKU and product links to CommerceTools Merchant Center
- Pricing information
- Product variants
- Categories
- Product descriptions
Before installing this app, you need:
-
CommerceTools Account with:
- Project Key
- API Client credentials (Client ID and Client Secret)
- Region (e.g.,
us-central1.gcp,us-east-2.aws,europe-west1.gcp)
-
API Client Configuration:
- Create an API Client in CommerceTools developer settings
- Grant read-only access to product data
- Minimum required scope:
view_products:{projectKey}
-
Product Projection Search API (Optional, for search functionality):
- Enable via Merchant Center: Settings > Project settings > Storefront Search
- Without this, the app will still work but search functionality will be disabled
git clone <repository-url>
cd agility-cms-app-commercetools
npm installnpm run devThe app will run on http://localhost:3011
- Navigate to Settings > Apps in your Agility CMS instance
- Install the CommerceTools app
- Configure the following settings:
- Project Key: Your CommerceTools project key
- Client ID: Your API client ID
- Client Secret: Your API client secret
- Region: Your CommerceTools region
- Locale: Your product locale (e.g.,
en-US)
- Go to Settings > Content Definitions
- Edit a content definition
- Add a new field and select "Commerce Tools Product" as the field type
- Save your content definition
.
├── app/
│ ├── fields/
│ │ └── commercetools-product/ # Main product field component
│ │ └── page.tsx
│ ├── modals/
│ │ └── select-commercetools-product/ # Product selection modal
│ │ └── page.tsx
│ └── app-details/ # App information page
│ └── page.tsx
├── components/
│ ├── ProductListing.tsx # Product browser with infinite scroll
│ ├── ProductRow.tsx # Individual product display
│ ├── EmptySection.tsx # Empty state component
│ └── Loader.tsx # Loading indicator
├── hooks/
│ └── useProductDetails.ts # Hook for fetching product details
├── lib/
│ ├── commercetools-client.ts # CommerceTools API client setup
│ └── getProductListing.ts # Product listing fetcher
├── types/
│ └── Product.ts # Product type definitions
└── public/
└── .well-known/
└── agility-app.json # App configuration file
This app uses the Agility Apps SDK v2 (@agility/app-sdk) and implements:
- Custom Field Surface (page.tsx): The main product selection interface that appears in content items
- Modal Surface (page.tsx): The product browser modal for selecting products
Key SDK hooks used:
useAgilityAppSDK: Access app configuration and field valuesuseResizeHeight: Auto-resize the field to fit contentcontentItemMethods.setFieldValue: Update field valuesopenModal/closeModal: Show/hide the product selection modal
The app uses the CommerceTools Platform SDK (@commercetools/platform-sdk) with:
- Client Credentials Flow: Secure authentication using OAuth2
- Product Projection API: Fetches product data with variants, images, and pricing
- Product Projection Search API (optional): Enables product search functionality
See commercetools-client.ts for the client configuration.
- User clicks "Browse Products" in the custom field
- Modal opens showing the product listing
- Products are fetched from CommerceTools API with pagination
- User can search/browse and select a product
- Selected product data is serialized to JSON and stored in the field value
- Product details are displayed in the custom field interface
The app is configured via public/.well-known/agility-app.json:
{
"name": "Agility Commerce Tools App",
"version": "1.0.0",
"capabilities": {
"fields": [
{
"name": "commercetools-product",
"label": "Commerce Tools Product",
"description": "A product from your Commerce Tools account."
}
]
},
"configValues": [...]
}npm run build
npm startKey dependencies:
@agility/app-sdk: ^2.0.4 - Agility Apps SDK@agility/plenum-ui: ^1.3.42 - Agility UI components@commercetools/platform-sdk: ^8.18.0 - CommerceTools SDK@commercetools/ts-client: ^4.3.0 - CommerceTools TypeScript clientnext: 13.4.2 - Next.js frameworkreact-infinite-scroll-component: ^6.1.0 - Infinite scroll for product listingsswr: ^2.1.5 - Data fetching and caching
If product search is disabled:
- Verify Product Projection Search is enabled in CommerceTools
- Navigate to Merchant Center > Settings > Project settings > Storefront Search
- Enable the feature and wait for indexing to complete
- Verify API credentials are correct
- Check that the API client has
view_productsscope - Confirm the region matches your CommerceTools project region
- Check browser console for error messages
The app stores product data as JSON in the field value. If you see errors:
- Clear the field value and select a new product
- Verify the product exists in CommerceTools
- Check that the locale matches your product data
This project is licensed under the terms specified by Agility CMS.