-
-
Notifications
You must be signed in to change notification settings - Fork 729
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changing a variant unit scale from items to weight/volume does not remove variant unit name #13027
Changing a variant unit scale from items to weight/volume does not remove variant unit name #13027
Conversation
c8269a8
to
3e031ab
Compare
@@ -987,11 +987,11 @@ | |||
|
|||
variant.variant_unit = 'weight' | |||
variant.variant_unit_scale = 1 | |||
variant.variant_unit_name = 'g' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we need to remove this step as per the logic described in the issue that only variants with unit equal items
have the value for variant_unit_name
, otherwise it should be empty.
@@ -65,6 +65,7 @@ def update_units | |||
def unit_value_attributes | |||
units = { unit_presentation: option_value_name } | |||
units.merge!(variant_unit:) if has_attribute?(:variant_unit) | |||
units.merge!(variant_unit_name: '') if reset_variant_unit_name? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updating with the emtpy string as per Line#123 of the spec:
openfoodnetwork/spec/system/admin/products_spec.rb
Lines 95 to 131 in 7302c2d
it "assigning important attributes" do | |
expect(find_field('product_shipping_category_id').text).to eq(shipping_category.name) | |
select 'New supplier', from: 'product_supplier_id' | |
fill_in 'product_name', with: 'A new product !!!' | |
select "Weight (kg)", from: 'product_variant_unit_with_scale' | |
fill_in 'product_unit_value', with: 5 | |
select taxon.name, from: "product_primary_taxon_id" | |
fill_in 'product_price', with: '19.99' | |
fill_in 'product_on_hand', with: 5 | |
select 'Test Tax Category', from: 'product_tax_category_id' | |
fill_in_trix_editor 'product_description', with: 'A description...' | |
click_button 'Create' | |
expect(current_path).to eq spree.admin_products_path | |
expect(flash_message).to eq('Product "A new product !!!" has been successfully created!') | |
product = Spree::Product.find_by(name: 'A new product !!!') | |
variant = product.variants.first | |
expect(product.description).to eq("<div>A description...</div>") | |
expect(product.group_buy).to be_falsey | |
expect(variant.variant_unit).to eq('weight') | |
expect(variant.variant_unit_scale).to eq(1000) | |
expect(variant.unit_value).to eq(5000) | |
expect(variant.unit_description).to eq("") | |
expect(variant.variant_unit_name).to eq("") | |
expect(variant.primary_taxon_id).to eq(taxon.id) | |
expect(variant.price.to_s).to eq('19.99') | |
expect(variant.on_hand).to eq(5) | |
expect(variant.tax_category_id).to eq(tax_category.id) | |
expect(variant.shipping_category).to eq(shipping_category) | |
expect(variant.unit_presentation).to eq("5kg") | |
expect(variant.supplier).to eq(supplier) | |
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice one 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great solution 👍
Hey @chahmedejaz , Thanks for fixing this. Before testing we can indeed verify in the DB, that editing the units from Items to Volume (or Weight) does not remove After this PR, this clears this attribute: Creating an items variant works as before. I think its a good idea to test product import before merging, I'll continue at a later stage. |
@filipefurtad0 I'm stilling staging FR this afternoon, but I should be done when you are back online |
Ok @chahmedejaz, Now tested product import of an variant which was changed from unit_type = item to weight. After clearing the Merging, thanks! |
What? Why?
items
What should we test?
Release notes
Changelog Category (reviewers may add a label for the release notes):