Last active
October 1, 2019 11:20
-
-
Save gerrgg/95fd9268e506772233b9c8d28982007b to your computer and use it in GitHub Desktop.
Downloads the portwest stock on hand CSV, compares items matching on sku and updates accordingly.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Gregory Bastianelli | |
# http://gerrg.com/resume | |
# 30-09-2019 | |
# Could pass a number of flags to quickly loop through and update any field (db column) | |
# download file | |
FILENAME='./sohUS.csv' | |
curl -o "${FILENAME}" http://www.portwest.us/downloads/sohUS.csv | |
# read per line | |
while IFS=\n read -r row | |
do | |
# split row on , | |
IFS=, read -r -a data <<< "$row" | |
sku="${data[1]}" | |
price=$(bc <<< "scale=2;${data[3]}*1.4") | |
# get variation_id by sku | |
variation_id=$(~/.wp-cli.phar db query "SELECT post_id FROM $(~/.wp-cli.phar db prefix)postmeta WHERE meta_key='_sku' AND meta_value='${sku}' LIMIT 1" --skip-column-names --batch) | |
# get post_parent id from variation_id | |
parent_id=$(~/.wp-cli.phar db query "SELECT post_parent FROM $(~/.wp-cli.phar db prefix)posts WHERE ID='${variation_id}' LIMIT 1" --skip-column-names --batch) | |
update | |
if [ -n "$variation_id" ]; then | |
printf "Updating ${variation_id} regular_price to ${price} \n"; | |
$(~/.wp-cli.phar wc product_variation update ${parent_id} ${variation_id} --regular_price=${price} --user=1 --quiet) | |
fi | |
done < "$FILENAME" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment