← back to Fineartamerica Price Sync
lib/pricing.js
29 lines
// Retail pricing rule for Fine Art America fulfilled products on the DW Shopify
// store. Steve-selected 2026-07-16 (AskUserQuestion): the DW wallcovering
// formula — retail = cost / 0.65 / 0.85 (~1.81x the FAA fulfillment cost).
//
// "cost" here = the FAA price for the exact configuration encoded in the variant
// SKU (see lib/faa-cost.js). This guarantees Shopify retail sits safely above
// fulfillment cost so an order can never lose money the way the pre-fix prices
// did (e.g. 7"x8" framed selling at $42.22 against a ~$74 FAA cost).
const DISCOUNT_A = 0.65;
const DISCOUNT_B = 0.85;
function retailFromCost(cost, { round = 'cent' } = {}) {
if (cost == null || isNaN(cost) || cost <= 0) return null;
let r = cost / DISCOUNT_A / DISCOUNT_B;
if (round === 'dollar') r = Math.ceil(r); // round UP to whole dollar
else if (round === '.99') r = Math.ceil(r) - 0.01; // charm price
else r = Math.round(r * 100) / 100; // 2-decimal
return r;
}
// Margin sanity: fraction of retail that is gross profit after FAA cost.
function grossMargin(cost, retail) {
if (!retail) return null;
return (retail - cost) / retail;
}
module.exports = { retailFromCost, grossMargin, DISCOUNT_A, DISCOUNT_B };