Skip to content
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

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions app/services/variant_units/variant_and_line_item_naming.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Copy link
Collaborator Author

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:

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

units
end

Expand All @@ -79,5 +80,9 @@ def option_value_name

VariantUnits::OptionValueNamer.new(self).name
end

def reset_variant_unit_name?
has_attribute?(:variant_unit_name) && has_attribute?(:variant_unit) && variant_unit != 'items'
end
end
end
2 changes: 1 addition & 1 deletion spec/models/spree/variant_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -987,11 +987,11 @@

variant.variant_unit = 'weight'
variant.variant_unit_scale = 1
variant.variant_unit_name = 'g'
Copy link
Collaborator Author

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.

variant.save!

expect(variant.variant_unit).to eq 'weight'
expect(variant.unit_presentation).to eq "1g"
expect(variant.variant_unit_name).to eq('')

variant.update(variant_unit: 'volume')

Expand Down
Loading