Repository navigation
Conversation
|
Thanks for taking this on. It replaces the stock PR I'd planned for #141, so I've reviewed this one instead of opening a second. Core tests and typecheck pass on I tested it on a shop running EmDash 1.6 with Paystack in test mode:
Four things I think need a change before it lands:
Against the cases @alexasomba listed on #141:
Smaller ones, fine as follow-ups:
Not tested by hand: points 1 and 4, and the oversell hold, which need concurrent sales or a failed refund. I'll test the next head on the same shop and report back here. |
Plugin content.update on a revisioned products collection stages a draft and leaves the published row unchanged, so sales never lowered what checkout reads. Live on-hand now lives in stock_levels. The published stock_quantity is the merchant baseline. Decrement, refund, and cancel restock write that collection with compare-and-set when the host provides it. Co-authored-by: Timchosen Uzua <timchosen@gmail.com>
A sale that still holds an older published stamp no longer overwrites a newer baseline. Publishing a new stock number stores the reset, so toggling back cannot revive the old on-hand. Partial refunds with Restock and no line list leave stock alone; a full refund still restores. A later failed refund takes that restock back from the ledger. Draft-write failures release the checkout lock. Oversold paid orders stay on hold through a partial refund, and moving them to processing retries the remaining debit. Co-authored-by: Timchosen Uzua <timchosen@gmail.com>
05baf2f to
c356de1
Compare
|
Addressed the four blockers on
Also: draft-write failure releases the lock; oversold paid orders stay on-hold through a partial refund; moving on-hold to processing retries remaining debit (409 if still short); Core tests 455 pass, typecheck clean. Left the 0.5.0 stock-only draft warning and JSON-LD |
|
Re-tested c356de1 on the same EmDash 1.6 shop as before (Paystack test mode, the enamel mug at 24). Thanks for the quick turnaround: three of the four points are fixed by hand. Fixed
Still open: republish with no read in between Starting from published 24 with 23 on hand, publish 25 and then 24 again, with no storefront or admin read of stock in between. Live stock comes back as 23.
Suggestion: also observe on publish. EmDash 1.6 has a Two smaller points
Not re-tested by hand: the stale-baseline sale race and the failed-refund reversal. Both have new tests, and the code reads right. |
Fixes #141.
Rebased onto current main (keeps signed download links in paid receipts from #145).
Root cause
On EmDash 1.6, plugin
content.updateon a revisioned collection (products) goes throughupdateDraftAware. That writes a draft and leaves the published row unchanged. Checkout and cart readcontent.get, so paid orders never lowered live stock. Each sale also left a stock-only draft; publishing it later could roll the count backwards. Variant stock was a read-then-write onproduct_variants, so two concurrent sales could overwrite each other.EmDash 0.37 and 1.1-1.5 expose the same
content.updateshape. None of 0.37 or 1.1-1.6 provide a plugin API that writes live published fields without_rev/ publish.Fix
Live on-hand now lives in an additive
stock_levelsplugin collection (p:{productId}/v:{variantId}).stock_quantity/ variantstockQuantityis the merchant-set baseline. A row is created on first movement. Publishing a new content value resets the row, and that reset is stored so publishing 25 then 24 cannot bring back 23.content.update.updateIforcompareAndSetwhen the host provides them, and fall back toputon EmDash 0.37.GET /stock?ids=is the storefront lookup.on-hold(including through a partial refund) and does not get download grants. Moving it to processing retries the remaining debit after replenishment.Existing shops pick this up on the next sale. No migration. Stock-only drafts already staged by 0.5.0 still exist; publishing one still resets live stock to that draft's number, so those drafts should be discarded.
Behaviour by EmDash line
putfallback (last write can still race).Tests
Core suite: 455 pass.
bun run typecheckclean. Covers draft-staging (fail before, pass after), stale baseline overwrite, 25-then-24 reset, partial vs full restock, failed-refund reversal from the ledger, draft-write lock release, oversold hold, and staff retry after replenishment.