diff --git a/app/controllers/spree_cm_commissioner/admin/products_controller_decorator.rb b/app/controllers/spree_cm_commissioner/admin/products_controller_decorator.rb index 37b5aa025..8b4b85628 100644 --- a/app/controllers/spree_cm_commissioner/admin/products_controller_decorator.rb +++ b/app/controllers/spree_cm_commissioner/admin/products_controller_decorator.rb @@ -1,10 +1,21 @@ module SpreeCmCommissioner module Admin module ProductsControllerDecorator + include SpreeCmCommissioner::Admin::ProductTypeHelper + def self.prepended(base) # spree update user sign_in_count base.around_action :set_writing_role, only: %i[index] end + + # overrided + def permitted_resource_params + product_type_value = calculate_product_type_value(params[:product]) + + params.require(:product).permit(:name, :sku, :prototype_id, :price, :shipping_category_id, + :vendor_id, :subscribable, :need_confirmation + ).merge(product_type: product_type_value) + end end end end diff --git a/app/helpers/spree_cm_commissioner/admin/product_type_helper.rb b/app/helpers/spree_cm_commissioner/admin/product_type_helper.rb new file mode 100644 index 000000000..8a6d593dd --- /dev/null +++ b/app/helpers/spree_cm_commissioner/admin/product_type_helper.rb @@ -0,0 +1,15 @@ +module SpreeCmCommissioner + module Admin + module ProductTypeHelper + def calculate_product_type_value(params) + product_type_params = params.slice(*SpreeCmCommissioner::ProductTypeBitwise::BIT_SEGMENT.keys) + + return nil unless product_type_params.values.any? + + product_type_params.values.each_with_index.sum do |value, index| + value.to_i * (2**index) + end + end + end + end +end diff --git a/app/models/concerns/spree_cm_commissioner/product_type_bitwise.rb b/app/models/concerns/spree_cm_commissioner/product_type_bitwise.rb new file mode 100644 index 000000000..b02be90ce --- /dev/null +++ b/app/models/concerns/spree_cm_commissioner/product_type_bitwise.rb @@ -0,0 +1,27 @@ +module SpreeCmCommissioner + module ProductTypeBitwise + extend ActiveSupport::Concern + + BIT_SEGMENT = { + accommodation: 0b1, + ecommerce: 0b10, + service: 0b100 + }.freeze + + BIT_SEGMENT.each do |segment, bit_value| + define_method "#{segment}?" do + segment_enabled?(bit_value) + end + end + + def segments + BIT_SEGMENT.filter_map do |segment_value, bit_value| + segment_value if segment_enabled?(bit_value) + end + end + + def segment_enabled?(bit_value) + segment & bit_value != 0 + end + end +end diff --git a/app/overrides/spree/admin/products/new/include_kyc_checkbox.html.erb.deface b/app/overrides/spree/admin/products/new/include_kyc_checkbox.html.erb.deface deleted file mode 100644 index b8a399a64..000000000 --- a/app/overrides/spree/admin/products/new/include_kyc_checkbox.html.erb.deface +++ /dev/null @@ -1,10 +0,0 @@ - - -