Find subscriptions in schedule to recalculate nil estimate price

This commit is contained in:
georgethoppil
2022-05-17 20:56:27 -04:00
parent 86a3f91ca2
commit a37f54e4b3

View File

@@ -96,14 +96,15 @@ module Admin
def update_nil_subscription_line_items_price_estimate(order_cycle)
order_cycle.schedules.each do |schedule|
subscription = Subscription.find_by(schedule_id: schedule.id)
shop = Enterprise.managed_by(spree_current_user).find_by(id: subscription.shop_id)
subscription.subscription_line_items.nil_price_estimate.each do |line_item|
variant = OrderManagement::Subscriptions::VariantsList
.eligible_variants(shop).find_by(id: line_item.variant_id)
fee_calculator = OpenFoodNetwork::EnterpriseFeeCalculator.new(shop, order_cycle)
price = variant.price + fee_calculator.indexed_fees_for(variant)
line_item.update_column(:price_estimate, price)
Subscription.where(schedule_id: schedule.id).each do |subscription|
shop = Enterprise.managed_by(spree_current_user).find_by(id: subscription.shop_id)
subscription.subscription_line_items.nil_price_estimate.each do |line_item|
variant = OrderManagement::Subscriptions::
VariantsList.eligible_variants(shop).find_by(id: line_item.variant_id)
fee_calculator = OpenFoodNetwork::EnterpriseFeeCalculator.new(shop, order_cycle)
price = variant.price + fee_calculator.indexed_fees_for(variant)
line_item.update_column(:price_estimate, price)
end
end
end
end