Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Admin UI for shipping methods - stock locations association #3624

Merged
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
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 @@ -884,6 +886,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 @@ -1412,6 +1417,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 in.
spree/stock_location:
active: 'This determines whether stock from this location can be used when
building packages.<br/> Default: Checked'
Expand Down