Skip to content

Commit

Permalink
Add admin UI for shipping methods - stock loc association
Browse files Browse the repository at this point in the history
Introduce the admin UI to be able to associate a shipping method to
specific stock locations.
This makes editable also `Spree::ShippingMethod#available_to_all` from
admin, being directly related to stock location association behaviour.
  • Loading branch information
cedum committed May 29, 2020
1 parent 064f6e3 commit f94d107
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 0 deletions.
1 change: 1 addition & 0 deletions backend/app/assets/javascripts/spree/backend.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,4 @@
//= require spree/backend/user_picker
//= require spree/backend/variant_autocomplete
//= require spree/backend/zone
//= require spree/backend/shipping_methods/stock_locations_picker
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
Spree.ready(function() {
var $stockLocationsSelect = $('#shipping_method_stock_location_ids'),
$availableToAllCheckbox = $('#shipping_method_available_to_all');

if ($stockLocationsSelect.length === 0 || $availableToAllCheckbox.length === 0) {
return;
}

function toggleLocationSelectVisibility() {
$stockLocationsSelect.toggleClass('hidden', $availableToAllCheckbox[0].checked);
}

$availableToAllCheckbox.on('click', function() {
toggleLocationSelectVisibility();
});

toggleLocationSelectVisibility();
})
18 changes: 18 additions & 0 deletions backend/app/views/spree/admin/shipping_methods/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,24 @@
<%= error_message_on :shipping_method, :tracking_url %>
<% end %>
</div>

<div class="col-5 label-block">
<%= f.field_container :stock_locations do %>
<label>
<%= f.check_box(:available_to_all) %>
<%= Spree::ShippingMethod.human_attribute_name :available_to_all %>
<%= f.field_hint :available_to_all %>
<%= error_message_on :shipping_method, :available_to_all %>
</label>
<%= f.collection_select :stock_location_ids,
Spree::StockLocation.order_default, :id, :name,
{},
class: 'fullwidth select2',
multiple: true,
placeholder: t('spree.admin.shipping_methods.form.stock_locations_placeholder') %>
<%= error_message_on :shipping_method, :stock_locations %>
<% end %>
</div>
</div>

<%= f.field_container :available_to_users, class: %w(checkbox) do %>
Expand Down
8 changes: 8 additions & 0 deletions core/config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,8 @@ en:
name: Name
service_level: Service Level
tracking_url: Tracking URL
stock_locations: Stock Locations
available_to_all: Available to all stock locations
spree/shipping_rate:
amount: Amount
label: Label
Expand Down Expand Up @@ -883,6 +885,9 @@ en:
expired: Expired
inactive: Inactive
not_started: Not started
shipping_methods:
form:
stock_locations_placeholder: 'Choose stock locations'
stock_locations:
form:
address: Address
Expand Down Expand Up @@ -1411,6 +1416,9 @@ en:
If no value is specified, the promotion will be immediately available.
promo_code_will_be_disabled: Selecting this option, promo codes will be disabled for this promotion
because all its rules / actions will be applied automatically to all orders.
spree/shipping_method:
available_to_all: Uncheck to select specific stock locations this
shipping method will be available.
spree/stock_location:
active: 'This determines whether stock from this location can be used when
building packages.<br/> Default: Checked'
Expand Down

0 comments on commit f94d107

Please sign in to comment.