Files
openfoodnetwork/app/services/permitted_attributes/order_cycle.rb
Cillian O'Ruanaidh a53a3259a8 Connect DistributorShippingMethods to OrderCycles instead of Spree::ShippingMethods
Before if a shipping method was shared between multiple distributors it could only be disabled/enabled on that order cycle for all the distributors which have that shipping method e.g. you couldn't select that shipping method for one distributor but disable it for another.
2022-09-30 13:13:39 +01:00

44 lines
1.1 KiB
Ruby

# frozen_string_literal: true
module PermittedAttributes
class OrderCycle
def initialize(params)
@params = params
end
def call
return {} if @params[:order_cycle].blank?
@params.require(:order_cycle).permit(attributes)
end
def self.basic_attributes
[
:name, :orders_open_at, :orders_close_at, :coordinator_id,
:preferred_product_selection_from_coordinator_inventory_only,
:automatic_notifications,
{ schedule_ids: [], selected_distributor_shipping_method_ids: [], coordinator_fee_ids: [] }
]
end
private
def attributes
self.class.basic_attributes + [incoming_exchanges: permitted_exchange_attributes,
outgoing_exchanges: permitted_exchange_attributes]
end
def permitted_exchange_attributes
[
:id, :sender_id, :receiver_id, :enterprise_id, :incoming, :active,
:select_all_variants, :receival_instructions,
:pickup_time, :pickup_instructions,
:tag_list,
{ tags: [:text],
enterprise_fee_ids: [],
variants: {} }
]
end
end
end