mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
Save shipping category selection to new variant when creating a new product
This commit is contained in:
@@ -69,7 +69,8 @@ module Spree
|
||||
|
||||
# Transient attributes used temporarily when creating a new product,
|
||||
# these values are persisted on the product's variant
|
||||
attr_accessor :price, :display_as, :unit_value, :unit_description, :tax_category_id
|
||||
attr_accessor :price, :display_as, :unit_value, :unit_description, :tax_category_id,
|
||||
:shipping_category_id
|
||||
|
||||
after_create :ensure_standard_variant
|
||||
after_save :update_units
|
||||
@@ -290,6 +291,7 @@ module Spree
|
||||
variant.unit_value = unit_value
|
||||
variant.unit_description = unit_description
|
||||
variant.tax_category_id = tax_category_id
|
||||
variant.shipping_category_id = shipping_category_id
|
||||
variants << variant
|
||||
end
|
||||
|
||||
|
||||
@@ -207,6 +207,7 @@ module Spree
|
||||
|
||||
context "saving a new product" do
|
||||
let!(:product){ Spree::Product.new }
|
||||
let!(:shipping_category){ create(:shipping_category) }
|
||||
|
||||
before do
|
||||
create(:stock_location)
|
||||
@@ -217,7 +218,7 @@ module Spree
|
||||
product.variant_unit_scale = 1000
|
||||
product.unit_value = 1
|
||||
product.price = 4.27
|
||||
product.shipping_category = create(:shipping_category)
|
||||
product.shipping_category_id = shipping_category.id
|
||||
product.save!
|
||||
end
|
||||
|
||||
@@ -225,6 +226,7 @@ module Spree
|
||||
expect(product.variants.reload.length).to eq 1
|
||||
standard_variant = product.variants.reload.first
|
||||
expect(standard_variant.price).to eq 4.27
|
||||
expect(standard_variant.shipping_category).to eq shipping_category
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user