From 78b1c51d59863a6676d03f57255f22b22133a297 Mon Sep 17 00:00:00 2001 From: Matt-Yorkley <9029026+Matt-Yorkley@users.noreply.github.com> Date: Mon, 20 Aug 2018 16:59:57 +0100 Subject: [PATCH] Change unit_type warning to a hard error --- app/models/product_import/entry_validator.rb | 6 +++++- config/locales/en.yml | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/app/models/product_import/entry_validator.rb b/app/models/product_import/entry_validator.rb index bfd0712d6ed..10444ce24f0 100644 --- a/app/models/product_import/entry_validator.rb +++ b/app/models/product_import/entry_validator.rb @@ -13,7 +13,6 @@ def initialize(current_user, import_time, spreadsheet_data, editable_enterprises def non_updatable_fields { category: :primary_taxon_id, - unit_type: :variant_unit_scale, variant_unit_name: :variant_unit_name, tax_category: :tax_category_id, shipping_category: :shipping_category_id @@ -178,6 +177,11 @@ def product_validation(entry) return end + if existing_product.variant_unit_scale != entry.variant_unit_scale + mark_as_invalid(entry, attribute: "unit_type", error: I18n.t('admin.product_import.model.not_updatable')) + return + end + # Otherwise, if a variant exists with matching display_name and unit_value, update it existing_product.variants.each do |existing_variant| if entry_matches_existing_variant?(entry, existing_variant) && existing_variant.deleted_at.nil? diff --git a/config/locales/en.yml b/config/locales/en.yml index cb022d09c59..820350c3f61 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -489,7 +489,7 @@ en: conditional_blank: can't be blank if unit_type is blank no_product: did not match any products in the database not_found: not found in database - not_updatable: cannot be updated on existing products + not_updatable: cannot be updated on existing products via product import blank: can't be blank products_no_permission: you do not have permission to manage products for this enterprise inventory_no_permission: you do not have permission to create inventory for this producer