As of now, Couch has no native stock management system, but you could scaffold your own using clonable templates and either Couch’s PayPal integration
or other third-party payment provider webhooks.
If you’re using Couch’s PayPal integration, you can persist inventory adjustments within <cms:paypal_processor> upon a successful payment. You could also use a third party payment provider like SnipCart
or Stripe Checkout
, but you’d need to set up your own webhooks to listen for payment confirmation. <cms:content_type ‘application/json’ />
and Couch arrays
will come in handy if you go down that route.
A simple way to adjust inventory via PayPal IPN might go like this:PayPal processor page:
- Code: Select all
<cms:pages masterpage=‘products.php’ id=pp_item_number>
_masterpage = ‘products.php’
_mode = ‘edit’
_page_id = k_page_id
inventory = “<cms:sub inventory pp_quantity />”
// successful inventory adjustment, notification, log file, etc.
// successful payment receipt, send customer email, log file, etc.
<cms:else_if k_paypal_error />
// handle PayPal error, send email notification, log file, etc.
As far as displaying the product inventory, assuming each product has its own record, you could apply logic like the following (minimal for brevity’s sake):
- Code: Select all
<cms:show k_page_title /> (<cms:show inventory /> remaining)
Now... technically this runs the risk of two or more people checking out with the same item around the same, and then paying for it and running the inventory below 0 (since the logic for decreasing the inventory happens after the payment confirmation, which could take place several minutes after the customer leave Couch to pay via PayPal), which may or may not be a problem for your application.
To mitigate this, you could use Stripe Elements
to begin a payment intent right there on the page, run some logic to check inventory, and - if good - process the payment and persist inventory changes all in one go (no webhooks, PayPal IPNs, payment status limbo, etc). You could do this within a <cms:php> tag. Otherwise, you’d need to keep track of “shelves”, “active cart sessions”, sweeping “abandoned carts” back onto the shelves, etc - a lot of work, but maybe useful in some circumstances.
The nice thing is Couch is flexible enough to handle any of these options; you just need to decide which one best fits your needs.
Hope that helps.