From f396f6bebd9e664d28b91aa70f94364c7d991603 Mon Sep 17 00:00:00 2001 From: luisramos0 Date: Sun, 27 Oct 2019 19:59:35 +0000 Subject: [PATCH] Add tax category to sample products --- lib/tasks/sample_data/product_factory.rb | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/tasks/sample_data/product_factory.rb b/lib/tasks/sample_data/product_factory.rb index 01e92dddb7..9d5411bef5 100644 --- a/lib/tasks/sample_data/product_factory.rb +++ b/lib/tasks/sample_data/product_factory.rb @@ -72,10 +72,18 @@ class ProductFactory variant_unit: "weight", variant_unit_scale: 1, unit_value: 1, - shipping_category: DefaultShippingCategory.find_or_create + shipping_category: DefaultShippingCategory.find_or_create, + tax_category_id: find_or_create_tax_category.id ) product = Spree::Product.create_with(params).find_or_create_by_name!(params[:name]) product.variants.first.update_attribute :on_demand, true product end + + def find_or_create_tax_category + tax_category_name = "Tax Category" + tax_category = Spree::TaxCategory.find_by_name(tax_category_name) + tax_category ||= Spree::TaxCategory.create!(name: tax_category_name) + tax_category + end end