From 42ee4b9f4206e4534e86af666f37977aa40564ab Mon Sep 17 00:00:00 2001 From: Maikel Linke Date: Thu, 21 Mar 2019 17:31:43 +1100 Subject: [PATCH 1/4] Remove usage of ProductDistribution which is dead Sample data was failing since: https://github.com/openfoodfoundation/openfoodnetwork/pull/3570 --- lib/tasks/sample_data/product_factory.rb | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/lib/tasks/sample_data/product_factory.rb b/lib/tasks/sample_data/product_factory.rb index 260ddb49cc..ba2bbfa208 100644 --- a/lib/tasks/sample_data/product_factory.rb +++ b/lib/tasks/sample_data/product_factory.rb @@ -76,18 +76,6 @@ class ProductFactory unit_value: 1, on_demand: true ) - create_product_with_distribution(params, hash[:supplier]) - end - - def create_product_with_distribution(params, supplier) - product = Spree::Product.create_with(params).find_or_create_by_name!(params[:name]) - - distribution_params = { - distributor_id: params[:distributor].id, - enterprise_fee_id: supplier.enterprise_fees.first.id - } - ProductDistribution.create_with(distribution_params).find_or_create_by_product_id!(product.id) - - product + Spree::Product.create_with(params).find_or_create_by_name!(params[:name]) end end From 98a262f86e1583b760f1b5fe5bbd10d69d005a81 Mon Sep 17 00:00:00 2001 From: luisramos0 Date: Sun, 17 Mar 2019 21:02:24 +0000 Subject: [PATCH 2/4] Fix sample data in v2 by setting a Default shipping category in both products and shipping methods --- lib/tasks/sample_data/product_factory.rb | 4 ++-- lib/tasks/sample_data/shipping_method_factory.rb | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/tasks/sample_data/product_factory.rb b/lib/tasks/sample_data/product_factory.rb index ba2bbfa208..0e13fa9762 100644 --- a/lib/tasks/sample_data/product_factory.rb +++ b/lib/tasks/sample_data/product_factory.rb @@ -74,8 +74,8 @@ class ProductFactory variant_unit: "weight", variant_unit_scale: 1, unit_value: 1, - on_demand: true + on_demand: true, + shipping_category: Spree::ShippingCategory.find_or_create_by_name('Default') ) - Spree::Product.create_with(params).find_or_create_by_name!(params[:name]) end end diff --git a/lib/tasks/sample_data/shipping_method_factory.rb b/lib/tasks/sample_data/shipping_method_factory.rb index 87e3747781..27b27ce192 100644 --- a/lib/tasks/sample_data/shipping_method_factory.rb +++ b/lib/tasks/sample_data/shipping_method_factory.rb @@ -48,6 +48,7 @@ class ShippingMethodFactory params[:distributor_ids] = [enterprise.id] method = enterprise.shipping_methods.new(params) method.zone = zone + method.shipping_categories << Spree::ShippingCategory.find_or_create_by_name('Default') method.save! method end From 88335c7f6c06158afd18fb9ec18ad422fad3a857 Mon Sep 17 00:00:00 2001 From: luisramos0 Date: Wed, 20 Mar 2019 23:04:25 +0000 Subject: [PATCH 3/4] Fix sample data in v2 by adapting to the fact that shipping methods can now have multiple zones --- lib/tasks/sample_data/shipping_method_factory.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/tasks/sample_data/shipping_method_factory.rb b/lib/tasks/sample_data/shipping_method_factory.rb index 27b27ce192..1e05109210 100644 --- a/lib/tasks/sample_data/shipping_method_factory.rb +++ b/lib/tasks/sample_data/shipping_method_factory.rb @@ -47,7 +47,7 @@ class ShippingMethodFactory def create_shipping_method(enterprise, params) params[:distributor_ids] = [enterprise.id] method = enterprise.shipping_methods.new(params) - method.zone = zone + method.zones << zone method.shipping_categories << Spree::ShippingCategory.find_or_create_by_name('Default') method.save! method From e2f5515412bc927b740c474007e7117274696ec1 Mon Sep 17 00:00:00 2001 From: luisramos0 Date: Thu, 21 Mar 2019 13:10:34 +0000 Subject: [PATCH 4/4] Fix sample data by setting on_demand in the product variant, setting product.on_demand is not possible in v2 --- lib/tasks/sample_data/product_factory.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/tasks/sample_data/product_factory.rb b/lib/tasks/sample_data/product_factory.rb index 0e13fa9762..117f25b2e3 100644 --- a/lib/tasks/sample_data/product_factory.rb +++ b/lib/tasks/sample_data/product_factory.rb @@ -74,8 +74,10 @@ class ProductFactory variant_unit: "weight", variant_unit_scale: 1, unit_value: 1, - on_demand: true, shipping_category: Spree::ShippingCategory.find_or_create_by_name('Default') ) + product = Spree::Product.create_with(params).find_or_create_by_name!(params[:name]) + product.variants.first.update_attribute :on_demand, true + product end end