Skip to content

Instantly share code, notes, and snippets.

@svaj
svaj / index.js
Last active March 12, 2020 04:06
product sync-actions external image example
import { createSyncProducts } from '@commercetools/sync-actions'
import {cloneDeep} from 'lodash'
const syncProducts = createSyncProducts()
const before = {
"id": "4e7ccbb5-0d06-48a8-8ff1-2b17b4bee189",
"version": 1,
@svaj
svaj / commercetools.js
Last active March 16, 2020 16:54
Ensure keys and skus are set for syncing
import { createClient } from '@commercetools/sdk-client';
import { createAuthMiddlewareForClientCredentialsFlow } from '@commercetools/sdk-middleware-auth';
import { createHttpMiddleware } from '@commercetools/sdk-middleware-http';
import { createQueueMiddleware } from '@commercetools/sdk-middleware-queue';
import { createRequestBuilder } from '@commercetools/api-request-builder';
import fetch from 'node-fetch';
import HttpsProxyAgent from 'https-proxy-agent';
export const fetchPatched = (url, options = {}) => {
import { createClient } from '@commercetools/sdk-client';
import { createCorrelationIdMiddleware } from '@commercetools/sdk-middleware-correlation-id';
import { createAuthMiddlewareForClientCredentialsFlow } from '@commercetools/sdk-middleware-auth';
import { createHttpMiddleware } from '@commercetools/sdk-middleware-http';
import { createQueueMiddleware } from '@commercetools/sdk-middleware-queue';
import { createRequestBuilder } from '@commercetools/api-request-builder';
import { createUserAgentMiddleware } from '@commercetools/sdk-middleware-user-agent';
import uuid from 'uuid/v4';
import fetch from 'node-fetch';
import HttpsProxyAgent from 'https-proxy-agent';
In commercetools' solution enablement department we aim to help our customers and partners implement the best solutions with commercetools' apis. This means a lot of interacting with our apis. Very often we'll end up needing to fetch and present product data in a meaningful fashion for our customers.
Please write an application that will display a list of many products filterable by (your choice) categories, or, some manner of search ( think text and filters/facets). If you have time, also include a product detail view that fetches and shows information about a single product given its id (or sku, or slug if you want)
You should find all documentation on commercetools' api endpoints at docs.commercetools.com, You will probably be making use of the product projections endpoint.
In the email asking about this exercise, you should get some credentials for accessing a project that should have sample product data already loaded.
Feel free to use any libraries available to complete this exercise. Keep in mind
@svaj
svaj / env_setup.sh
Created August 7, 2018 16:15
Bash fun to setup variables from a prefixed environment variables
#! /bin/bash
set -e
# Below will find env vars prefixed with ${CI_ENVIRONMENT} and set env vars without the prefix to the prefixed value
# e.g. if ${development_CTP_CLIENT_SECRET} is defined, define $CTP_CLIENT_SECRET with the value from ${development_CTP_CLIENT_SECRET}
while read -r line
do
non_prefixed=${line#"${CI_ENVIRONMENT}_"}
declare -x $non_prefixed=${!line}