Skip to content

Commit

Permalink
Allow specifying quantity
Browse files Browse the repository at this point in the history
  • Loading branch information
mamhoff committed Nov 7, 2023
1 parent 1588b7f commit 86e5ec8
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ module Actions
class CreateDiscountedItem < PromotionAction
include Automation
preference :variant_id, :integer
preference :quantity, :integer, default: 1

def perform(order)
line_item = find_item(order) || create_item(order)
Expand All @@ -23,7 +24,7 @@ def find_item(order)
end

def create_item(order)
order.line_items.create!(quantity: 1, variant: variant, managed_by_order_action: self)
order.line_items.create!(quantity: preferred_quantity, variant: variant, managed_by_order_action: self)
end

def variant
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
<div class="field">
<%= form.label :preferred_variant_id %>
<%= form.text_field :preferred_variant_id, class: "variant_autocomplete fullwidth" %>
<%= form.label :preferred_quantity %>
<%= form.number_field :preferred_quantity, class: "fullwidth" %>
</div>
<% end %>

Expand Down

0 comments on commit 86e5ec8

Please sign in to comment.