Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions api/app/controllers/spree/api/line_items_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@ def create
@line_item = @order.contents.add(
variant,
params[:line_item][:quantity] || 1,
{
stock_location_quantities: params[:line_item][:stock_location_quantities]
}.merge({ options: line_item_params[:options].to_h })
order_contents_add_options
)

if @line_item.errors.empty?
Expand Down Expand Up @@ -42,6 +40,13 @@ def destroy

private

def order_contents_add_options
{
stock_location_quantities: params[:line_item][:stock_location_quantities],
options: line_item_params[:options].to_h
}
end

def load_order
@order ||= Spree::Order.includes(:line_items).find_by!(number: order_id)
authorize! :update, @order, order_token
Expand Down
6 changes: 5 additions & 1 deletion frontend/app/controllers/spree/orders_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def populate
end

begin
@line_item = @order.contents.add(variant, quantity)
@line_item = @order.contents.add(variant, quantity, order_contents_add_options)
rescue ActiveRecord::RecordInvalid => e
@order.errors.add(:base, e.record.errors.full_messages.join(", "))
end
Expand Down Expand Up @@ -104,6 +104,10 @@ def check_authorization

private

def order_contents_add_options
{}
end

def order_params
if params[:order]
params[:order].permit(*permitted_order_attributes)
Expand Down