solidus
solidus copied to clipboard
Problem with performance of updating line items in cart
Background: User has a lot of line items in shopping cart with different quantity. He didn't do anythings for long time. In meantimes the price or the quantity of some product was changed by customer support. He returned to the shopping cart. The system refreshes all items from shopping cart. - Here we have problem with performance of refreshing.
Code:
line_items.each do |line_item|
variant = line_item.variant
order.contents.add(variant, 0, { price: variant.price }) if line_item.price != variant.price
stock_quantity = variant.stock_items.first.count_on_hand
if stock_quantity.zero?
order.contents.remove_line_item(line_item)
elsif line_item.quantity > stock_quantity
difference = line_item.quantity - stock_quantity
order.contents.remove(variant, difference)
end
end
We have situations when refreshing of cart totals 3 minutes ... Any ideas how we can resolve it ?
Solidus Version: 2.11.2
@d-obuchowski thanks for reporting, where does the code that you posted live? Is it something into Solidus or something that you have customized in your application?
@d-obuchowski thanks for reporting, where does the code that you posted live? Is it something into Solidus or something that you have customized in your application?
It is custom code.
Not sure, but shouldn't order.recalculate
do the trick?
I found that the problem is connected mainly with this line: Spree::PromotionHandler::Cart.new(order).activate
- it is very time consuming line ;/
@d-obuchowski FYI check also this discussion, I think it may be related to your issues.