Sie sind auf Seite 1von 2

Scheduled Serverless Lambda

for products sync between


Zauru and WooCommerce
I need a serverless AWS lambda function that runs hourly and does the following:

Connect to an airtable (the credentials must be stored in an env variable) with this columns
and get all the DATA about the :

• woocommerce_url (text URL)

• woocommerce_key (text)

• woocommerce_secret (text)

• zauru_email (text email format)

• zauru_token (text)

• zauru_url (text URL)

• default_woocommerce_parent_category_for_categories (integer number) OPTIONAL

• default_woocommerce_parent_category_for_vendors (integer number) OPTIONAL

• default_woocommerce_parent_category_for_tags (integer number) OPTIONAL

• run_schedule (integer number) 1 = HOURLY, 2 = DAILY (8 AM), 3 = DAILY (3 AM), 4 =


WEEKLY (SUNDAY 9PM), 5 = WEEKLY (MONDAY 7AM), 6 = MONTHLY (1st 6AM)

example: https://egghead.io/lessons/node-js-connect-node-js-to-an-airtable-database

1. For each airtable line do:

1.1. if the airtable.run_schedule matches the current time hour

FETCH ZAURU INFO


1.1.2. Fetch the Zauru items and categories (one fetch), navigate the categories and save
each {“name”: category, “parent”:
airtable.default_woocommerce_parent_category_for_categories} in an z_categories_array,
in each categories navigate in the items and save the {“name”: item.vendor, “parent”:
default_woocommerce_parent_category_for_vendors} in the same z_categories_array, also
in the items, navigate in the tags array and save the {“name”: item.tags[X], “parent”:
default_woocommerce_parent_category_for_tags} in the same z_categories_array.

1.1.3 Continue navigating thru all the items that are inside of each category and store the
items object (in a woo commerce style) in an z_items_array.

1.1.4 Clean up the z_categories_array by removing duplicates and removing the elements of
z_categories_array that the “name” element is null

FETCH WOO COMMERCE INFO

1.1.5 Fetch all the WooCommerce categories /products/categories, remove all attributes of
each object and only keep: id, name and parent, and store them in wc_categories_array.

1.1.6 Fetch all WooCommerce products /products, remove all attributes of each object and
only keep: id, name, regular_price, description, sku, manage_stock, stock_quantity, weight,
categories, and images. And store them in wc_items_array.

IDENTIFY WHICH CATEGORIES TO CREATE/UPDATE/DELETE <— complicated!

1.1.7 Use alasql to load the z_categories_array and wc_categories_array as different tables
and LEFT OUTER JOIN them by “name” to identify what operation to do in another column
(create/update/delete/nothing).

BATCH UPDATE THE CATEGORIES

1.1.8 Batch update products/categories/batch based on the identified operation to do and


do the necessary calls (100 objects each call)

FETCH WOO COMMERCE UPDATED CATEGORIES

1.1.9 Fetch all the WooCommerce categories /products/categories, remove all attributes of
each object and only keep: id and name. and store them in wc_updated_categories_array.

IDENTIFY WHICH ITEMS TO CREATE/UPDATE/DELETE <— complicated!

1.1.10 Use alasql to load the z_items_array and wc_items_array as different tables and LEFT
JOIN them by “sku”/“code” to identify what operation to do in another column (create/update/
delete/nothing). See our last isProductUpdated method for reference (but verifying
wc_updated_categories).

BATCH UPDATE THE PRODUCTS

1.1.11 Prepare the Product Object for the objects to create/update/delete.

1.1.12 Batch update products/categories/batch based on the identified operation to do and


do the necessary calls (100 objects each call)

REFERENCES:

1. Fetch a JSON from Zauru (z) via this API https://docs.zauru.com/e-commerce/solicitar-los-


items-disponibles

2. Fetch WooCommerce (wc) data using the REST API v3 https://woocommerce.github.io/


woocommerce-rest-api-docs/?javascript#introduction via this library https://github.com/
woocommerce/woocommerce-rest-api-js-lib

3. Use as reference our project that does this in a not efficient way https://github.com/intuitiva/
woo-commerce-zauru-sync-products (it does like 3 API calls for EACH product, it updates 50
products in 15 minutes….)

Das könnte Ihnen auch gefallen