Skip to content

Commit

Permalink
Added README
Browse files Browse the repository at this point in the history
  • Loading branch information
nagesh-dixit committed Mar 7, 2024
1 parent 1cb9a05 commit ce12ba8
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 8 deletions.
34 changes: 30 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,37 @@
</a></br>
<b>A demo application to get started and learn about commercetools Connect</b>
</p>
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
2 changes: 1 addition & 1 deletion connect.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ deployAs:
applicationType: job
endpoint: /new-category-cleanup-job-app
properties:
schedule: "*/5 * * * *"
schedule: "0 1 * * *"
configuration:
standardConfiguration:
- key: CTP_REGION
Expand Down
8 changes: 5 additions & 3 deletions new-product-event-app/src/controllers/event.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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");
}
})
}
Expand Down

0 comments on commit ce12ba8

Please sign in to comment.