Skip to content

Commit

Permalink
Adapt variants auto complete to spree v2 code with shipments
Browse files Browse the repository at this point in the history
  • Loading branch information
luisramos0 committed Feb 4, 2019
1 parent 698ba46 commit d598831
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ angular.module("admin.utils").directive "variantAutocomplete", ($timeout) ->
distributor_id: scope.distributor_id
order_cycle_id: scope.order_cycle_id
results: (data, page) ->
window.variants = data # this is how spree auto complete JS code picks up variants
results: data
formatResult: (variant) ->
if variant["images"][0] != undefined && variant["images"][0].image != undefined
Expand Down
37 changes: 19 additions & 18 deletions app/views/spree/admin/variants/_autocomplete.js.erb
Original file line number Diff line number Diff line change
Expand Up @@ -46,26 +46,27 @@
<th class="actions"></th>
</thead>
<tbody>
{{#each variant.stock_items}}
<tr>
<td>{{this.stock_location_name}}</td>
{{#if this.available}}
<td>
{{this.count_on_hand}}
{{#if this.backorderable}} (backorders allowed) {{/if}}
</td>
<tr>
<td>{{variant.stock_location_name}}</td>
{{#if variant.[in_stock?]}}
{{#if variant.on_demand}}
<td>Spree.t(:on_demand)</td>
{{else}}
<td>
<input class="quantity" id="stock_item_quantity" data-stock-location-id="{{this.stock_location_id}}" type="number" min="1" value="1">
{{variant.count_on_hand}}
</td>
<td class="actions">
<button class="add_variant no-text icon-plus icon_link with-tip" data-stock-location-id="{{this.stock_location_id}}" title="Add" data-action="add"></button>
</td>
{{else}}
<td><%= Spree.t(:out_of_stock) %></td>
<td>0</td>
{{/if}}
</tr>
{{/each}}
{{/if}}
<td>
<input class="quantity" id="stock_item_quantity" data-stock-location-id="{{variant.stock_location_id}}" type="number" min="1" value="1">
</td>
<td class="actions">
<button class="add_variant no-text icon-plus icon_link with-tip" data-stock-location-id="{{variant.stock_location_id}}" title="Add" data-action="add"></button>
</td>
{{else}}
<td><%= Spree.t(:out_of_stock) %></td>
<td>0</td>
{{/if}}
</tr>
</tbody>
</fieldset>
</script>
10 changes: 9 additions & 1 deletion app/views/spree/admin/variants/search.rabl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# overriding spree/core/app/views/spree/admin/variants/search.rabl
#
collection @variants
attributes :sku, :options_text, :count_on_hand, :id, :cost_price
attributes :sku, :options_text, :in_stock?, :on_demand, :count_on_hand, :id, :cost_price

node(:name) do |v|
# TODO: when products must have a unit, full_name will always be present
Expand All @@ -22,6 +22,14 @@ node(:producer_name) do |v|
v.product.supplier.name
end

node(:stock_location_id) do |v|
v.stock_items.first.stock_location.id
end

node(:stock_location_name) do |v|
v.stock_items.first.stock_location.name
end

child(:images => :images) do
attributes :mini_url
end
Expand Down

0 comments on commit d598831

Please sign in to comment.