Why Shopify ERP Syncs Silently Write compareAtPrice = "0" (and How to Stop $0 Checkouts in 3 Seconds)
If you maintain a Shopify store connected to an ERP, PIM, Matrixify schedule, or wholesaler inventory feed, you have probably seen one of these two silent failures at least once: A product's compareAtPrice gets overwri
If you maintain a Shopify store connected to an ERP, PIM, Matrixify schedule, or wholesaler inventory feed, you have probably seen one of these two silent failures at least once:
- A product's
compareAtPricegets overwritten to"0.00"(or becomes equal to / lower thanprice), breaking strike-through sale badges, automated collections, and Google Merchant Centersale_pricevalidation. - Worse, a supplier feed outputs
"N/A","Out of Stock", or an unescaped comma in a price column, gets coerced to0.00, and a $400 product goes live for free at 3 AM.
Most teams try to fix this only at the spreadsheet layer. That catches manual imports, but it does nothing when an automated connector writes directly to the Admin GraphQL API overnight.
Here is what actually causes these two failure modes under the hood — and the server-side pattern we built to stop them automatically.
1. The "0.00" vs null Trap in compareAtPrice
In Shopify's Admin GraphQL API (productVariantsBulkUpdate), compareAtPrice: null clears the compare-at field. Sending compareAtPrice: "0" or "0.00" does not always behave like null across downstream consumers.
A real-world example surfaced in Microsoft's own Dynamics 365 Business Central Shopify connector (microsoft/BCApps PR #8125): when an item had no active sale price, bulk variant sync logic serialized compareAtPrice as "0" instead of omitting/nulling it.
Downstream damage happens in three places immediately:
-
Automated collections break quietly: A collection rule like
Compare at price is emptychecks fornull, not"0.00". Products silently drop out of collection rules without throwing an import error. -
Inverted strike-through pricing: When a connector writes a stale
compare_at_pricelower than or equal to the currentprice(for example, selling price$324.99withcompare_at_price: $184.95or$312.76vs$312.76), Google Merchant Center flagsprice/sale_pricemismatches on Shopping feeds. -
Last-Writer-Wins (LWW) collisions: Shopify does not provide row-level write locks across apps. If your ERP updates inventory + pricing on a 15-minute cron, while a marketing app or CSV import edits
compareAtPrice, whichever request lands last wins — often reverting manual price fixes minutes later.
2. How to Pinpoint Which App Overwrote a Price
Before adding a guard, confirm which integration is actually writing bad payloads using the Admin GraphQL API (2026-10):
query InspectVariantPricing($id: ID!) {
product(id: $id) {
id
title
status
updatedAt
variants(first: 25) {
nodes {
id
sku
price
compareAtPrice
updatedAt
}
}
}
}
Match variant.updatedAt timestamps against:
- Scheduled ERP / NetSuite / Business Central / Cin7 sync logs
- Matrixify recurring import jobs
- Shopify Flow workflows touching variants or metafields
If price drops to 0.00 or compareAtPrice flips back within 5–60 minutes of a manual fix, you have a multi-writer LWW race, not a one-off typo.
3. Building a 3-Second Server-Side Webhook Kill-Switch
Pre-import CSV validators are still essential for human uploads, but for automated feeds you need a server-side guardrail subscribed to Shopify's products/update webhook.
Three engineering details separate a reliable guard from one that causes an outage:
A. Verify HMAC-SHA256 Against Raw Bytes First
Never parse JSON and re-serialize before computing the signature. Verify X-Shopify-Hmac-Sha256 against the raw UTF-8 request body with crypto.timingSafeEqual.
B. Separate P0 (Unpublish) from P1 (Field Cleanup)
-
P0 (
price <= 0, NaN, or single-update drop > 30%): Immediately mutate productstatustoDRAFTand tagcatalog-blocked. Do not guess the "correct" price automatically unless you have an authoritative ledger; pulling the listing to Draft stops $0 checkouts in ~3 seconds while keeping the product intact for one-click republishing. -
P1 (
compareAtPrice > 0 && compareAtPrice <= price): Never unpublish a healthy product over a broken compare-at field. ClearcompareAtPricetonullviaproductVariantsBulkUpdateand emit an alert so the team fixes the upstream ERP mapping.
C. Add a Loop Guard to Prevent Webhook Ping-Pong
Whenever your service mutates a product to DRAFT or clears compareAtPrice, Shopify fires a fresh products/update webhook right back at your endpoint.
Without loop protection, your service re-evaluates its own write, burns GraphQL bucket points, or fights an ERP retry loop. Store a short-lived expected-state fingerprint (60s TTL) keyed by (shopDomain, productId, actionHash):
import crypto from "node:crypto";
const loopGuardCache = new Map(); // Replace with Redis in multi-instance setups
const LOOP_TTL_MS = 60_000;
export function verifyShopifyHmac(rawBodyBuffer, hmacHeader, webhookSecret) {
if (!hmacHeader || !webhookSecret) return false;
const digest = crypto
.createHmac("sha256", webhookSecret)
.update(rawBodyBuffer)
.digest("base64");
const a = Buffer.from(digest, "utf8");
const b = Buffer.from(hmacHeader, "utf8");
return a.length === b.length && crypto.timingSafeEqual(a, b);
}
export function rememberOwnWrite(shop, productId, status, variantFingerprint) {
const key = `${shop}:${productId}:${status}:${variantFingerprint}`;
loopGuardCache.set(key, Date.now() + LOOP_TTL_MS);
}
export function isOwnWebhookEcho(shop, productId, status, variantFingerprint) {
const key = `${shop}:${productId}:${status}:${variantFingerprint}`;
const expiresAt = loopGuardCache.get(key);
if (!expiresAt) return false;
if (Date.now() > expiresAt) {
loopGuardCache.delete(key);
return false;
}
return true;
}
export function inspectVariants(variants) {
const p0Zero = [];
const p1Inverted = [];
for (const v of variants || []) {
const price = Number.parseFloat(v.price);
const compareAt =
v.compare_at_price === null || v.compare_at_price === ""
? null
: Number.parseFloat(v.compare_at_price);
if (!Number.isFinite(price) || price <= 0) {
p0Zero.push({ id: v.id, sku: v.sku || "", price: v.price });
} else if (compareAt !== null && Number.isFinite(compareAt) && compareAt > 0 && compareAt <= price) {
p1Inverted.push({ id: v.id, sku: v.sku || "", price: v.price, compareAt: v.compare_at_price });
}
}
return { p0Zero, p1Inverted };
}
4. Don't Forget Shopify's 2026-11-20 Custom App IP Allowlist Rule
If you self-host this webhook worker as a Partner Custom App for one or more client stores, check your egress IP architecture now:
- Starting November 20, 2026, Shopify began enforcing IP Allowlists on external Custom Apps.
- Existing installations hit the hard cutoff on January 1, 2027 — after which Admin API calls originating from un-allowlisted dynamic IPs (like standard serverless lambdas without a NAT Gateway) will fail with
403. - Route outbound Shopify Admin API calls through a dedicated static IPv4
/32(for example, a small VPS behind Caddy or a NAT Gateway with an Elastic IP) and request onlyread_productsandwrite_productsso you stay at Level 0 Protected Customer Data.
Open-Source Preflight vs. Managed 24/7 Kill-Switch
We split our own tooling into two layers depending on where the failure enters:
-
Before import (free, open-source MIT): shopify-csv-preflight-lite runs 100% locally in your browser to flag
$0rows, inverted compare-at prices, duplicate SKUs, and broken image URLs before you upload a CSV. - After import (24/7 server-side): CatalogCleanse Auto-Shield runs the HMAC-verified 3.05s webhook kill-switch + Loop Guard + dedicated static IPv4 allowlist with a 48-hour read-only Dry-Run before turning on live blocking.
If you're debugging a weird ERP price reversion or preparing custom apps for the January 1 IP allowlist deadline, drop the symptoms in the comments — happy to compare notes.
Originally published by Dev.to WebDev. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.