From 4f7f2e2035239836bbb248a0874becdb79b0050e Mon Sep 17 00:00:00 2001 From: Maikel Linke Date: Fri, 21 Aug 2015 16:42:36 +1000 Subject: [PATCH 1/4] Displaying customer tags --- lib/open_food_network/orders_and_fulfillments_report.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/open_food_network/orders_and_fulfillments_report.rb b/lib/open_food_network/orders_and_fulfillments_report.rb index 2d4e1d1f1f..77573d1ff2 100644 --- a/lib/open_food_network/orders_and_fulfillments_report.rb +++ b/lib/open_food_network/orders_and_fulfillments_report.rb @@ -222,7 +222,7 @@ module OpenFoodNetwork proc { |line_items| line_items.first.order.order_cycle.andand.name }, proc { |line_items| line_items.first.order.payments.first.andand.payment_method.andand.name }, proc { |line_items| line_items.first.order.user.andand.customer_of(line_items.first.order.distributor).andand.code }, - proc { |line_items| "" }, + proc { |line_items| line_items.first.order.user.andand.customer_of(line_items.first.order.distributor).tags.join(', ') }, proc { |line_items| line_items.first.order.bill_address.andand.address1 }, proc { |line_items| line_items.first.order.bill_address.andand.address2 }, From 5d34b711e91687a1e84de6166e7b898654bc6d71 Mon Sep 17 00:00:00 2001 From: Maikel Linke Date: Wed, 26 Aug 2015 15:01:20 +1000 Subject: [PATCH 2/4] Handling undefined customer tags --- lib/open_food_network/orders_and_fulfillments_report.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/open_food_network/orders_and_fulfillments_report.rb b/lib/open_food_network/orders_and_fulfillments_report.rb index 77573d1ff2..03c4ec801a 100644 --- a/lib/open_food_network/orders_and_fulfillments_report.rb +++ b/lib/open_food_network/orders_and_fulfillments_report.rb @@ -222,7 +222,7 @@ module OpenFoodNetwork proc { |line_items| line_items.first.order.order_cycle.andand.name }, proc { |line_items| line_items.first.order.payments.first.andand.payment_method.andand.name }, proc { |line_items| line_items.first.order.user.andand.customer_of(line_items.first.order.distributor).andand.code }, - proc { |line_items| line_items.first.order.user.andand.customer_of(line_items.first.order.distributor).tags.join(', ') }, + proc { |line_items| line_items.first.order.user.andand.customer_of(line_items.first.order.distributor).andand.tags.andand.join(', ') }, proc { |line_items| line_items.first.order.bill_address.andand.address1 }, proc { |line_items| line_items.first.order.bill_address.andand.address2 }, From 64834dd50afdc8c57d17bbf9f1cb0ef5ab43277f Mon Sep 17 00:00:00 2001 From: Maikel Linke Date: Thu, 27 Aug 2015 11:55:31 +1000 Subject: [PATCH 3/4] Fixing display of cloned products The producer and the unit is displayed again. --- .../javascripts/admin/services/bulk_products.js.coffee | 1 + app/views/spree/api/products/bulk_show.v1.rabl | 10 +++++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/app/assets/javascripts/admin/services/bulk_products.js.coffee b/app/assets/javascripts/admin/services/bulk_products.js.coffee index 6085d48fcc..4e06a87bd2 100644 --- a/app/assets/javascripts/admin/services/bulk_products.js.coffee +++ b/app/assets/javascripts/admin/services/bulk_products.js.coffee @@ -19,6 +19,7 @@ angular.module("ofn.admin").factory "BulkProducts", (PagedFetcher, dataFetcher) # when a respond_overrride for the clone action is used. id = data.product.id dataFetcher("/api/products/" + id + "?template=bulk_show").then (newProduct) => + @unpackProduct newProduct @insertProductAfter(product, newProduct) updateVariantLists: (serverProducts, productsWithUnsavedVariants) -> diff --git a/app/views/spree/api/products/bulk_show.v1.rabl b/app/views/spree/api/products/bulk_show.v1.rabl index d2cd23bd03..c336d72530 100644 --- a/app/views/spree/api/products/bulk_show.v1.rabl +++ b/app/views/spree/api/products/bulk_show.v1.rabl @@ -1,5 +1,11 @@ object @product -attributes :id, :name, :variant_unit, :variant_unit_scale, :variant_unit_name, :on_demand + +# TODO: This is used by bulk product edit when a product is cloned. +# But the list of products is serialized by Api::Admin::ProductSerializer. +# This should probably be unified. + +attributes :id, :name, :sku, :variant_unit, :variant_unit_scale, :variant_unit_name, :on_demand, :inherits_properties +attributes :on_hand, :price, :available_on, :permalink_live, :tax_category_id # Infinity is not a valid JSON object, but Rails encodes it anyway node( :taxon_ids ) { |p| p.taxons.map{ |t| t.id }.join(",") } @@ -8,6 +14,8 @@ node( :price ) { |p| p.price.nil? ? '0.0' : p.price } node( :available_on ) { |p| p.available_on.blank? ? "" : p.available_on.strftime("%F %T") } node( :permalink_live ) { |p| p.permalink } +node( :producer_id ) { |p| p.supplier_id } +node( :category_id ) { |p| p.primary_taxon_id } node( :supplier ) do |p| partial 'api/enterprises/bulk_show', :object => p.supplier end From ced254919a218332eac849607a77ae69d4ef45ab Mon Sep 17 00:00:00 2001 From: Maikel Linke Date: Thu, 27 Aug 2015 13:51:19 +1000 Subject: [PATCH 4/4] Updating JS spec --- .../unit/admin/services/bulk_products_spec.js.coffee | 3 +++ 1 file changed, 3 insertions(+) diff --git a/spec/javascripts/unit/admin/services/bulk_products_spec.js.coffee b/spec/javascripts/unit/admin/services/bulk_products_spec.js.coffee index 54b57aed48..7d4c5d1d7c 100644 --- a/spec/javascripts/unit/admin/services/bulk_products_spec.js.coffee +++ b/spec/javascripts/unit/admin/services/bulk_products_spec.js.coffee @@ -62,12 +62,15 @@ describe "BulkProducts service", -> id: 17 spyOn(BulkProducts, "insertProductAfter") + spyOn(BulkProducts, "unpackProduct") BulkProducts.products = [originalProduct] $httpBackend.expectGET("/admin/products/oranges/clone.json").respond 200, product: clonedProduct $httpBackend.expectGET("/api/products/17?template=bulk_show").respond 200, clonedProduct BulkProducts.cloneProduct BulkProducts.products[0] $httpBackend.flush() + expect(BulkProducts.unpackProduct).toHaveBeenCalledWith clonedProduct + BulkProducts.unpackProduct(clonedProduct) expect(BulkProducts.insertProductAfter).toHaveBeenCalledWith originalProduct, clonedProduct