diff --git a/app/assets/javascripts/admin/bulk_product_update.js.coffee b/app/assets/javascripts/admin/bulk_product_update.js.coffee index 7df51e7711..d32977b8c0 100644 --- a/app/assets/javascripts/admin/bulk_product_update.js.coffee +++ b/app/assets/javascripts/admin/bulk_product_update.js.coffee @@ -126,8 +126,11 @@ angular.module("ofn.admin").controller "AdminProductEditCtrl", ($scope, $timeout DisplayProperties.setShowVariants 0, showVariants $scope.addVariant = (product) -> + # Set new variant category to same as last product variant category to keep compactibility with deleted variant callback to set new variant category + newVariantId = $scope.nextVariantId(); + newVariantCategoryId = product.variants[product.variants.length - 1]?.category_id product.variants.push - id: $scope.nextVariantId() + id: newVariantId unit_value: null unit_description: null on_demand: false @@ -136,8 +139,9 @@ angular.module("ofn.admin").controller "AdminProductEditCtrl", ($scope, $timeout on_hand: null price: null tax_category_id: null - category_id: null + category_id: newVariantCategoryId DisplayProperties.setShowVariants product.id, true + DirtyProducts.addVariantProperty(product.id, newVariantId, 'category_id', newVariantCategoryId) $scope.nextVariantId = -> diff --git a/app/models/spree/variant.rb b/app/models/spree/variant.rb index 00340f49d7..5950886104 100644 --- a/app/models/spree/variant.rb +++ b/app/models/spree/variant.rb @@ -87,7 +87,6 @@ module Spree before_validation :ensure_unit_value before_validation :update_weight_from_unit_value, if: ->(v) { v.product.present? } before_validation :convert_variant_weight_to_decimal - before_validation :assign_related_taxon, if: ->(v) { v.primary_taxon.blank? } before_save :assign_units, if: ->(variant) { variant.new_record? || variant.changed_attributes.keys.intersection(NAME_FIELDS).any? @@ -217,10 +216,6 @@ module Spree private - def assign_related_taxon - self.primary_taxon ||= product.variants.last&.primary_taxon - end - def check_currency return unless currency.nil? diff --git a/app/views/admin/products_v3/_variant_row.html.haml b/app/views/admin/products_v3/_variant_row.html.haml index a1244e1d47..5fc7777cb6 100644 --- a/app/views/admin/products_v3/_variant_row.html.haml +++ b/app/views/admin/products_v3/_variant_row.html.haml @@ -37,20 +37,24 @@ = f.label :on_demand do = f.check_box :on_demand, 'data-action': 'change->toggle-control#disableIfPresent change->popout#closeIfChecked' = t(:on_demand) -%td.col-producer.naked_inputs +%td.col-producer.field.naked_inputs = render(SearchableDropdownComponent.new(form: f, name: :supplier_id, aria_label: t('.producer_field_name'), options: producer_options, selected_option: variant.supplier_id, - placeholder_value: t('admin.products_v3.filters.search_for_producers'))) + include_blank: t('admin.products_v3.filters.select_producer'), + placeholder_value: t('admin.products_v3.filters.select_producer'))) + = error_message_on variant, :supplier %td.col-category.field.naked_inputs = render(SearchableDropdownComponent.new(form: f, name: :primary_taxon_id, options: category_options, selected_option: variant.primary_taxon_id, aria_label: t('.category_field_name'), - placeholder_value: t('admin.products_v3.filters.search_for_categories'))) + include_blank: t('admin.products_v3.filters.select_category'), + placeholder_value: t('admin.products_v3.filters.select_category'))) + = error_message_on variant, :primary_taxon %td.col-tax_category.field.naked_inputs = render(SearchableDropdownComponent.new(form: f, name: :tax_category_id, diff --git a/config/locales/en.yml b/config/locales/en.yml index d0764b7a91..2528e78bc9 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -868,8 +868,10 @@ en: filters: search_products: Search for products search_for_producers: Search for producers + select_producer: Select producer all_producers: All producers search_for_categories: Search for categories + select_category: Select category all_categories: All categories producers: label: Producers diff --git a/spec/system/admin/products_v3/update_spec.rb b/spec/system/admin/products_v3/update_spec.rb index 0b184f4353..33232f7a93 100644 --- a/spec/system/admin/products_v3/update_spec.rb +++ b/spec/system/admin/products_v3/update_spec.rb @@ -20,6 +20,7 @@ RSpec.describe 'As an enterprise user, I can update my products' do let(:tax_categories_search_selector) { 'input[placeholder="Search for tax categories"]' } describe "updating" do + let!(:taxon) { create(:taxon) } let!(:variant_a1) { product_a.variants.first.tap{ |v| v.update! display_name: "Medium box", sku: "APL-01", price: 5.25, on_hand: 5, @@ -349,6 +350,9 @@ RSpec.describe 'As an enterprise user, I can update my products' do click_on "On Hand" # activate popout fill_in "On Hand", with: "3" + + select producer.name, from: 'Producer' + select taxon.name, from: 'Category' end expect { @@ -541,6 +545,9 @@ RSpec.describe 'As an enterprise user, I can update my products' do click_on "Unit" # activate popout fill_in "Unit value", with: "200" + + select producer.name, from: 'Producer' + select taxon.name, from: 'Category' end expect {