diff --git a/app/services/default_shipping_category.rb b/app/services/default_shipping_category.rb new file mode 100644 index 0000000000..ae515fa59a --- /dev/null +++ b/app/services/default_shipping_category.rb @@ -0,0 +1,13 @@ +# Encapsulates the concept of default stock location in creation of a product or a shipping method. + +class DefaultShippingCategory + NAME = 'Default'.freeze + + def self.create! + Spree::ShippingCategory.create!(name: NAME) + end + + def self.find_or_create + Spree::ShippingCategory.find_or_create_by_name(NAME) + end +end \ No newline at end of file diff --git a/app/views/spree/admin/products/_shipping_category_form.html.haml b/app/views/spree/admin/products/_shipping_category_form.html.haml index 0f3635d698..6e8e1a5dbd 100644 --- a/app/views/spree/admin/products/_shipping_category_form.html.haml +++ b/app/views/spree/admin/products/_shipping_category_form.html.haml @@ -1,4 +1,4 @@ = f.field_container :shipping_categories do = f.label :shipping_category_id, t(:shipping_category) - = f.collection_select(:shipping_category_id, Spree::ShippingCategory.all, :id, :name, {:include_blank => false}, {:class => 'select2 fullwidth'}) + = f.collection_select(:shipping_category_id, Spree::ShippingCategory.all, :id, :name, {:include_blank => false, :selected => DefaultShippingCategory.find_or_create.id}, {:class => 'select2 fullwidth'}) = f.error_message_on :shipping_category_id