Skip to content

Commit

Permalink
Ignore carts with failed payments in cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Matt-Yorkley committed Jan 27, 2021
1 parent 4773c19 commit 99d192e
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/tasks/data/remove_transient_data.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@ def call
private

def clear_old_cart_data!
old_carts = Spree::Order.where("state = 'cart' AND updated_at < ?", SHORT_RETENTION)
# Carts with failed payments are ignored, as they contain potentially useful data
old_carts = Spree::Order.joins(:payments).where(
"spree_orders.state = 'cart' AND spree_payments.id IS NULL AND spree_orders.updated_at < ?",
SHORT_RETENTION
)
old_cart_line_items = Spree::LineItem.where(order_id: old_carts)
old_cart_adjustments = Spree::Adjustment.where(order_id: old_carts)

Expand Down

0 comments on commit 99d192e

Please sign in to comment.