Add default shipping category service and update create product form

This commit is contained in:
Dan Ingenthron
2019-09-17 23:02:19 -05:00
parent 35f89a9750
commit b4be2cc2d4
2 changed files with 14 additions and 1 deletions

View File

@@ -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

View File

@@ -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