A lightweight CLI utility designed to pull product and category data from BigCommerce stores and push that data back up to an elasticsearch instance.
Running this utility will:
- Query BigCommerce for categories
- Check returned categories for
is_visible
- Attempt to delete any hidden categories from elasticsearch (if they exist)
- POST the remaining categories to elasticsearch, updating them if changed
- Query BigCommerce for brands
- POST brands to elasticsearch, updating them if changed
- Query BigCommerce for products
- Check returned products for
is_visible
- Map categories and brands to products
- Attempt to delete any hidden products from elasticsearch (if they exist)
- POST the remaining products to elasticsearch, updating them if changed
- Output all steps and processes colorfully to the terminal
Optional flags include:
Flag | Example | Effect |
---|---|---|
init | bigc2elastic --init |
CLI to set necessary ENV variables |
drop | bigc2elastic --drop |
Drops existing documents first (reset) |
products-only | bigc2elastic --products-only |
Syncs products only |
no-categories | bigc2elastic --no-categories |
Skips category sync |
no-brands | bigc2elastic --no-brands |
Skips brand sync |
If ENV variables are missing or not configured, bigc2elastic runs bigc2elastic --init
whether or not the --init
flag is included.
Running the CLI with the --products-only
flag still queries BigCommerce for
categories and brands to decorate product documents with their category and
brand names, but it will not drop or update category or brand documents within
elasticsearch.
Optionally, just the brand documents or just the category documents may be
omitted with the appropriate flags (ie: --no-categories
, --no-brands
).
Running the CLI with the --drop
flag will drop all existing documents from
elasticsearch before beginning the updates (effectively starting clean).
Flags may be combined if necessary (ie: bigc2elastic --drop --no-categories
).
Field | Type | Product | Category | Brand |
---|---|---|---|---|
brand | <string> |
✓ | ✗ | ✗ |
bucket | <string> |
'product' |
'category' |
'brand' |
calculated_price | <number> |
✓ | ✗ | ✗ |
categories | [<string>,...] |
✓ | ✗ | ✗ |
date_created | <string> |
✓ | ✗ | ✗ |
date_modified | <string> |
✓ | ✗ | ✗ |
description | <string> |
✓ | ✓ | ✗ |
id | <string> |
bc2eP<id> |
bc2eC<id> |
bc2eB<id> |
mpn | <string> |
✓ | ✗ | ✗ |
name | <string> |
✓ | ✓ | ✓ |
page_title | <string> |
✓ | ✓ | ✓ |
price | <number> |
✓ | ✗ | ✗ |
search_keywords | <string> |
✓ | ✓ | ✓ |
sort_order | <number> |
✓ | ✓ | ✗ |
total_sold | <number> |
✓ | ✗ | ✗ |
upc | <string> |
✓ | ✗ | ✗ |
view_count | <number> |
✓ | ✓ | ✗ |
url | <string> |
✓ | ✓ | ✓ |
- First install nvm with
curl https://raw.githubusercontent.com/creationix/nvm/master/install.sh | bash
on Debian-based systems, update your environment settings withsource ~/.profile
, and install node withnvm install latest
(alternatively, check out https://nodejs.org/en/download/ for other installation options). - Install globally via npm with
npm install -g @goodnight_ian/bigc2elastic
. - Setup ENV variables by running
bigc2elastic --init
. - Run the utility with
bigc2elastic
.
Alternatively, if you want to pull the entire package down for development or other specific use-cases:
- First install nvm with
curl https://raw.githubusercontent.com/creationix/nvm/master/install.sh | bash
on Debian-based systems, update your environment settings withsource ~/.profile
, and install node withnvm install latest
(alternatively, check out https://nodejs.org/en/download/ for other installation options). - Pull the repository down to your local machine by cloning the repository.
- By installing git and running:
cd ~ && git clone https://github.com/iangoodnight/bigc2elastic.git
- Or using cUrl with:
curl -L https://github.com/iangoodnight/bigc2elastic/archive/master.zip > \ bigc2elastic.tar.gz && tar -zxvf bigc2elastic.tar.gz
- Install dependencies with
cd bigc2elastic/ && npm install
for the entire package, or withcd bigc2elastic/ && npm install --production
to install the package without development dependencies. - Set your secret keys using
.env.example
and filling in the missing values and rename the resulting file from.env.example
to.env
withmv .env.example .env
.- Or, run
./index --init
to set the ENV through the CLI.
- Or, run
- If you have installed the entire package (with devDependencies) you can test
your installation with
npm test
. - If everything looks right, you can run the application with
npm start
.
- Setup your crontab with the command:
crontab -e
- Crontab uses the syntax
m h dom mon dow command
referring tominute
,hour
,day of month
,month
, andday of week
respectively with*
actiing as a wildcard for 'any'. Occasionally, the relative paths called from node programs don't play nice with cronjobs, so we are going to start our by changing directories to the root of bigc2elastic. So, if we wanted to run our script once a week our crontab entry might look like:0 5 * * 1 cd /home/<user>/bigc2elastic/ && ./index.js
By default, the output from cronjobs goes to /var/mail/
, but
you can override this by redirecting the output as part of the command. So the
crontab entry:
0 5 * * 1 cd /home/<user>/bigc2elastic/ && ./index.js > ../run.log
Runs the program and saves the output from that last job to the file
/opt/bigc2elastic/run.log
for review.