From ce12ba88bcbab9f143caadaff78a7451857a9866 Mon Sep 17 00:00:00 2001 From: Nagesh Dixit Date: Thu, 7 Mar 2024 00:56:36 -0500 Subject: [PATCH] Added README --- README.md | 34 ++++++++++++++++--- connect.yaml | 2 +- .../src/controllers/event.controller.ts | 8 +++-- 3 files changed, 36 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 8dc7a66..9461ffc 100644 --- a/README.md +++ b/README.md @@ -4,11 +4,37 @@
A demo application to get started and learn about commercetools Connect

-This is a simple service app to add a free line item when the cart total is more than 50. The SKU and quantity is decided by the client. +A connector app to be used in self-learning training module. It contains a service app that allows distributing a sample product with limited configurable quanyity and an event app that will add a new product to a category supplied in the configurations. It also contains a job that removes products from the category after 30 days. -## Instructions +## Deployment instructions -Deploy this application into any project by providing the API Client and the sample product's SKU as well as the quantity. +Deploy this demo Connector into any project to learn and experience how commercetools Connect makes integrations quick and easy. This Connector contains three applications each of a different type. -## Deployment instructions +### free-sample-product-service + +It allows you to configure a sample product that you want to add to a cart that has the minimum total value. You can provide the SKU and the total quantity to be offered free. + +Configurations: + +1. Sample product's SKU +2. Offered free quantity +3. Minimum cart value +4. API credentials + +### new-product-event-app + +This event type app runs whenever a product is published and adds it to a category if the product was created less than a month ago. + +Configurations: + +1. Category key for new arrivals +2. API credentials + +### new-category-cleanup-job-app + +This job runs every day and removes the products from the new arrivals category if older than a month. + +Configurations: +1. Category key for new arrivals +2. API credentials diff --git a/connect.yaml b/connect.yaml index ad88462..9c0e21d 100644 --- a/connect.yaml +++ b/connect.yaml @@ -63,7 +63,7 @@ deployAs: applicationType: job endpoint: /new-category-cleanup-job-app properties: - schedule: "*/5 * * * *" + schedule: "0 1 * * *" configuration: standardConfiguration: - key: CTP_REGION diff --git a/new-product-event-app/src/controllers/event.controller.ts b/new-product-event-app/src/controllers/event.controller.ts index 816800e..99f8bef 100644 --- a/new-product-event-app/src/controllers/event.controller.ts +++ b/new-product-event-app/src/controllers/event.controller.ts @@ -56,21 +56,23 @@ export const post = async (request: Request, response: Response) => { try { let apiRoot = createApiRoot(); const categoryKey:string = readConfiguration().categoryKey; - + const categoryId: string = await createApiRoot() .categories() .withKey({key: categoryKey}) .get().execute().then(({body}) => body.id); - + await apiRoot .productProjections() .withId({ ID: productId }) .get() .execute() .then(({body}) => { + const createdAt = new Date(body.createdAt); const today = new Date(); const fromDate = new Date(new Date().setDate(today.getDate() - 30)); + if((createdAt >= fromDate) && (body.categories?.find(category => category.id === categoryId) == undefined)) { apiRoot.products() @@ -91,7 +93,7 @@ export const post = async (request: Request, response: Response) => { } else { - logger.info("Product is already in the category"); + logger.info("Product is already in the category or not new"); } }) }