Stock handling
The Shop-Extension provides a simple stock logic for products.
First of all, you need to activate the stock-fields in your product by configuring the product-type. Afterwards you'll find a field named In stock and a field Stock amount in all products of the related product-type.
If you enable the field In stock, the logic for decreasing the stock-amount is enabled. The field Stock amount defines how many of this product can still be ordered.
Stock handling in basket-checkouts
If you're using the regular basket and checkout, the stock-amount will be checked in first instance in basket-view. If the user tries to order an amount, which isn't available anymore, the basket-view automatically reduces to the maximium available amount.
During finishing the checkout the DecreaseStockAmountsEventListener will be executed. It checks first if the product is a digital-product - digital-products will be skipped, because they don't have a stock-amount. Afterwards it checks if the setting In stock is enabled - if true, the event-listener will decrease the stock-amount on the product.
Stock handling in Stripe subscriptions
The stock handling in Stripe subscriptions works a bit differently. This works only, if you've assigned your Stripe price-id within a product.
Usecase: You create regular products with assigned Stripe price-id and enables the subsciption-buttons, and disables the basket-button. This way you can use your products as subscription-items.
The logic itself uses the StripeSubscriptionCreatedEvent and catch this in the StripeSubscriptionCreatedDecreaseStockAmountsEventListener. This event uses the Stripe subscription-object to identify all subscription-items. The subscription-items contains the price-id and the quantity to decrease.
On a new subscription it iterates through all subscription-items, tries to find a related Product record and if this records has an enabled In stock field it decrease the subscriptipn-item quantity.