← back to Designer Wallcoverings

pending-approval/dw-trade-tier-persist-2026-07-09/push-to-live.sh

63 lines

#!/usr/bin/env bash
# STEVE-GATED — customer-facing LIVE theme push. DRAFT ONLY until you run it.
# Ships the dw_trade tier-durability fix to LIVE theme #144076931123:
#   - snippets/dw-signin-modal.liquid          (writer → durable localStorage+cookie)
#   - layout/theme.liquid                      (NEW: {% if customer %} return-hook consumer)
#   - templates/customers/account.liquid       (fallback reader → durable store)
#   - templates/customers/register.liquid      (writer+reader → durable store)
# Backs up each current-live version first. Reversible: PUT the .bak back.
set -euo pipefail

STORE="designer-laboratory-sandbox.myshopify.com"
API="2024-10"
TID="144076931123"   # live theme 5.9.1
SRC="$HOME/Projects/Designer-Wallcoverings/shopify/dw-trade-persist-20260709"
SECRETS="$HOME/Projects/secrets-manager/.env"

TOK="$(grep -hE '^SHOPIFY_THEME_TOKEN=' "$SECRETS" | head -1 | cut -d= -f2- | tr -d '"'"'"'')"
[ -z "$TOK" ] && { echo "no theme token"; exit 1; }
echo "token …${TOK: -4} | live theme $TID"

BKDIR="$HOME/Projects/Designer-Wallcoverings/shopify/theme-backups"
mkdir -p "$BKDIR"
TS="$(date +%Y%m%d-%H%M%S)"

KEYS=(
  "snippets/dw-signin-modal.liquid"
  "layout/theme.liquid"
  "templates/customers/account.liquid"
  "templates/customers/register.liquid"
)

for KEY in "${KEYS[@]}"; do
  [ -f "$SRC/$KEY" ] || { echo "missing source: $SRC/$KEY"; exit 1; }
  SAFE="$(echo "$KEY" | tr '/' '__')"
  BK="$BKDIR/${SAFE}.LIVE-$TID.$TS.bak"
  # backup current live
  curl -s "https://$STORE/admin/api/$API/themes/$TID/assets.json?asset%5Bkey%5D=$KEY" \
    -H "X-Shopify-Access-Token: $TOK" \
    | python3 -c "import sys,json;open('$BK','w').write(json.load(sys.stdin)['asset']['value'])"
  echo "backup: $BK ($(wc -c < "$BK") bytes)"
  # PUT the new version
  python3 - "$STORE" "$API" "$TID" "$TOK" "$SRC/$KEY" "$KEY" <<'PY'
import sys, json, urllib.request
store, api, tid, tok, srcfile, key = sys.argv[1:7]
val = open(srcfile).read()
body = json.dumps({"asset": {"key": key, "value": val}}).encode()
r = urllib.request.Request(f"https://{store}/admin/api/{api}/themes/{tid}/assets.json",
                           data=body, method="PUT",
                           headers={"X-Shopify-Access-Token": tok, "Content-Type": "application/json"})
resp = urllib.request.urlopen(r)
print("PUT", key, resp.status, f"({len(val)} bytes)")
PY
  sleep 2   # gentle spacing between asset writes
done

echo ""
echo "VERIFY (logged out): open any storefront page → open the sign-in modal →"
echo "  pick Professional → sign in (Google or email). On return to the storefront"
echo "  as a logged-in customer you should be routed once to /pages/trade-only-benefits."
echo "  Pick Retail → you stay on the normal page (3-sample default)."
echo ""
echo "REVERT: for each key, PUT its .bak file in $BKDIR back onto theme $TID."