Two buyers can order the same candle SKU at different prices. In this synthetic example, CND-CED-08 is $10.10 in Group A and $9.09 in Group B. The smaller candle appears only in B. Both buyer sheets come from these two Shopify variant rows.

URL handle,Title,SKU,Price,Compare-at price,Option1 value,MOQ,Case Pack cedar-candle,Cedar Candle,CND-CED-08,10.10,22.00,8 oz,12,6 cedar-candle,,CND-CED-04,7.25,16.00,4 oz,6,6 

Carry product metadata across variant rows

LineSheetPack normalizes each header by trimming it, lowercasing it, and turning runs of whitespace or hyphens into underscores. Modern Shopify detection uses URL handle, SKU, and Price. Legacy detection uses Variant SKU and Variant Price. The handle column and the inheritance lookup come from src/lib/linesheet/csv-parser.ts.

const handleColumn = keys.indexOf(modernShopify ? 'url_handle' : 'handle'); 
const handle = cells[handleColumn]?.trim(); const previous = shopify && handle ? products.get(handle) : undefined; const name = get('name') || previous?.name || ''; const category = get('category') || previous?.category || ''; if (shopify && handle) products.set(handle, { name, category }); 

The map carries forward the product name and category. The variant still supplies its SKU and prices. With the first option appended, the second row becomes Cedar Candle / 4 oz. Compare-at price and legacy Variant Compare At Price can populate MSRP. Check the mapped wholesale and MSRP values because Shopify exports the merchant’s own price fields. Shopify product CSV reference

Build cents from the digits and round once

Parsing dollars as a binary floating-point number introduces a rounding problem before the first price calculation. In JavaScript, 1.005 * 100 evaluates just below 100.5. This importer accepts up to two decimal digits and rejects 1.005. Once the regular expression has captured the dollar and fractional digits, the parser builds an integer.

const cents = Number(match[2].replaceAll(',', '')) * 100 + Number((match[3] ?? '').padEnd(2, '0')); 

groupPrice uses 10,000 basis points for the whole amount. The B group’s 10% discount leaves a factor of 9,000. The result for 1,010 cents is 909 cents, and the half-cent result on 725 cents rounds up to 653. A group-specific override takes precedence over the discount.

const factor = BASIS - groups[group].discountBps; // Round once, half up, using cents and whole basis points. return Math.floor((row.wholesaleCents * factor + BASIS / 2) / BASIS); 

Keep validation and buyer selection separate

The validator counts trimmed, NFC-normalized, lowercased SKUs. Adding a second cnd-ced-08 flags both matching rows. It also enforces positive integer quantities and checks whether the MOQ can be ordered in whole cases.

if (!validQuantity(row.moq) || !validQuantity(row.casePack)) { add('quantity'); } else if (row.moq < row.casePack || row.moq % row.casePack !== 0) { add('caseMismatch'); } 

An MOQ of 10 cannot be filled exactly with cases of 6. Changing it to 12 resolves the conflict. After validation, both export functions use groupRows to filter the assortment and compute the selected group’s price. The seller can see B minus A in the comparison view. Each pdf-lib Letter document draws the selected group’s rows and prices.

return rows .filter((row) => row.membership[group]) .map((row) => ({ ...row, price: groupPrice(row, groups, group) })); 

Escape text as the order form is written

CSV quoting defines a field boundary. A spreadsheet can still interpret a field as a formula, so the writer adds an apostrophe before text that matches a formula marker or a leading tab, carriage return, or line feed. It checks both ASCII and full-width markers after optional whitespace.

function textCell(value: string) { const safe = /^\s*[=+\-@=+-@\t\r\n]/u.test(value) ? "'" + value : value; return '"' + safe.replaceAll('"', '""') + '"'; } 

Quotes inside text are doubled, and every text field (SKU, product, category, lead time, and notes) is wrapped in double quotes so embedded commas or newlines stay inside that field. Validated numeric prices and quantities are written unquoted, and the CSV leaves the order quantity column blank. Spreadsheet applications can rewrite CSV escaping on save and reopen. OWASP CSV Injection guidance

To reproduce the two-row buyer split interactively, the sample fixture runs in the browser at LineSheetPack Wholesale Line Sheet Maker (with the 4 oz candle excluded from Group A and a 10% discount on Group B).

The full engineering write-up with image-only continuation rows, localized titles, and group-specific validation details is published at linesheet.shihaoeth.site.