Open rintisch opened 1 month ago
I've just stumbled across this behavior. If a order is submitted, the stock is changed immediatly, no matter if and how the external payment provider is processed. This leads to discrepancies in the inventory.
Yeah but I think extcode's arguments are reasonable: https://github.com/extcode/cart/pull/572#issuecomment-2395420440
You should adapt your payment provider. Or do you have other plans in the meanwhile @extcode ?
There are various ways to solve the problem.
I would not swap the order, because otherwise customer A and customer B could buy the same product in competition because the payment process for one of them has not yet been completed. For stores in which the cart extension is used, this is probably an edge case and probably occurs rarely or not at all. For your own implementation, you could possibly also remove one EventListener from one event and insert it again in a later event. With cart-products 5.x for TYPO3 v12, however, this is probably no longer so easy because an explicit event is passed here and no longer the interface. The only option is to remove one EventListener and re-insert your own (copy and adapt) in the later event. There is also a “solution” with composer-patches to avoid the custom EventListener.
I will have a look at this for a payment provider in the near future.
I just realized the following: https://github.com/extcode/cart/blob/cb2a245c1e8fe18c7c0159e17db98d8b30c4cff5/Classes/Domain/Model/Cart.php#L29
The Extcode\Cart\Domain\Model\Cart
(which is at the moment not stored by default but can be stored by a paymentProvider) has a property wasOrdered
which is false by default. Can't this be used by a paymentProvider extension?
That sounds not that difficult?
Bug Report
Current Behavior According to the docs https://docs.typo3.org/p/extcode/cart/main/en-us/Developer/Events/Index.html#confval-extcode-cart-event-order-paymentevent the
PaymentEvent
should trigger theStockEvent
on success. But in the code theStockEvent
comes after thePaymentEvent
: https://github.com/extcode/cart/blob/560a455b1f926be44092dff39350611e2e083d9d/Classes/Controller/Cart/OrderController.php#L223-L233Due to this it can happen that the stock is changed although the purchase failed.
Expected behavior/output Those two Events have to switch position.
Environment