mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-12 23:27:48 +00:00
Merge pull request #2733 from kristinalim/fix-subscription_should_not_require_future_oc
Reduce restrictions for adding a variant to a subscription
This commit is contained in:
@@ -33,6 +33,10 @@ module OpenFoodNetwork
|
||||
Spree::Variant.where(is_master: false).ransack(search_params.merge(m: 'or')).result
|
||||
end
|
||||
|
||||
def distributor
|
||||
Enterprise.find params[:distributor_id]
|
||||
end
|
||||
|
||||
def scope_to_schedule
|
||||
@variants = @variants.in_schedule(params[:schedule_id])
|
||||
end
|
||||
@@ -42,12 +46,29 @@ module OpenFoodNetwork
|
||||
end
|
||||
|
||||
def scope_to_distributor
|
||||
distributor = Enterprise.find params[:distributor_id]
|
||||
if params[:eligible_for_subscriptions]
|
||||
scope_to_eligible_for_subscriptions_in_distributor
|
||||
else
|
||||
scope_to_available_for_orders_in_distributor
|
||||
end
|
||||
end
|
||||
|
||||
def scope_to_available_for_orders_in_distributor
|
||||
@variants = @variants.in_distributor(distributor)
|
||||
scope_variants_to_distributor(@variants, distributor)
|
||||
end
|
||||
|
||||
def scope_to_eligible_for_subscriptions_in_distributor
|
||||
eligible_variants_scope = SubscriptionVariantsService.eligible_variants(distributor)
|
||||
@variants = @variants.merge(eligible_variants_scope)
|
||||
scope_variants_to_distributor(@variants, distributor)
|
||||
end
|
||||
|
||||
def scope_variants_to_distributor(variants, distributor)
|
||||
scoper = OpenFoodNetwork::ScopeVariantToHub.new(distributor)
|
||||
# Perform scoping after all filtering is done.
|
||||
# Filtering could be a problem on scoped variants.
|
||||
@variants.each { |v| scoper.scope(v) }
|
||||
variants.each { |v| scoper.scope(v) }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user