Exclude carts with attempted payments from purgeIncompleteCarts #3684
-
We have a use case for our shop where we have to purge inactive carts really fast, because having an item in the cart reserves an outsourced stock. Like ~15-30 minutes. But the purge removes carts with attempted payments also, and since someone may pay per bank transfer, this cart can't be deleted. It would be great if we can have a setting to exclude carts with attempted payments from the purge. Since attempted payments includes both still-in-progress-payments and failed payments, there maybe has to be a check if the latest transaction status is just "redirect" or "pending", etc. If none of this is possible, it would be great if you could introduce an event where I can populate this query: commerce/src/services/Carts.php Lines 418 to 422 in ff3994c |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Thanks for requesting this. We added this event in 5.3.0.1. Here is an example of how to modify the query to only target carts with a zero total price. use craft\commerce\events\CartPurgeEvent;
use craft\commerce\services\Carts;
use yii\base\Event;
Event::on(
Carts::class,
Carts::EVENT_BEFORE_PURGE_INACTIVE_CARTS,
function(CartPurgeEvent $event) {
$event->inactiveCartsQuery = $event->inactiveCartsQuery->andWhere(['totalPrice' => 0]);
}
); Thanks! |
Beta Was this translation helpful? Give feedback.
Thanks for requesting this. We added this event in 5.3.0.1.
Here is an example of how to modify the query to only target carts with a zero total price.
Thanks!