From 8fa053a0a8bbdd25cf0c8834d2f359d514d69ee2 Mon Sep 17 00:00:00 2001 From: summerscope Date: Tue, 3 Jun 2014 10:28:18 +1000 Subject: [PATCH 1/5] Commenting out promo image from About tab in shopfront page. This needs an additional image style to be applied before it can be implemented correctly. --- app/views/shopping_shared/_about.html.haml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/views/shopping_shared/_about.html.haml b/app/views/shopping_shared/_about.html.haml index 0fbfc1cc11..e03eb05255 100644 --- a/app/views/shopping_shared/_about.html.haml +++ b/app/views/shopping_shared/_about.html.haml @@ -3,5 +3,6 @@ .small-12.large-9.columns %p= current_distributor.long_description.andand.html_safe .small-12.large-3.columns - %img.about.right{src: current_distributor.promo_image.url(:large)} + / Hide image until image styles are working correctly: + / %img.about.right{src: current_distributor.promo_image.url(:large)} From 60711301c15075c76b3f522280dc61a571c891aa Mon Sep 17 00:00:00 2001 From: Rohan Mitchell Date: Tue, 3 Jun 2014 11:16:42 +1000 Subject: [PATCH 2/5] Initialise primary taxon in migration instead of in model callback --- app/models/spree/product_decorator.rb | 5 ----- ...522044009_add_primary_taxon_to_products.rb | 21 +++++++++++-------- db/schema.rb | 2 +- 3 files changed, 13 insertions(+), 15 deletions(-) diff --git a/app/models/spree/product_decorator.rb b/app/models/spree/product_decorator.rb index 72da0e52b1..36473d4e24 100644 --- a/app/models/spree/product_decorator.rb +++ b/app/models/spree/product_decorator.rb @@ -28,7 +28,6 @@ Spree::Product.class_eval do after_initialize :set_available_on_to_now, :if => :new_record? after_save :update_units before_save :add_primary_taxon_to_taxons - before_validation :set_primary_taxon_to_first_taxon # -- Joins @@ -163,10 +162,6 @@ Spree::Product.class_eval do end end - def set_primary_taxon_to_first_taxon - self.primary_taxon = taxons.first unless primary_taxon - end - def add_primary_taxon_to_taxons taxons << primary_taxon unless taxons.find_by_id(primary_taxon) end diff --git a/db/migrate/20140522044009_add_primary_taxon_to_products.rb b/db/migrate/20140522044009_add_primary_taxon_to_products.rb index fb7b9b3160..28c27f820f 100644 --- a/db/migrate/20140522044009_add_primary_taxon_to_products.rb +++ b/db/migrate/20140522044009_add_primary_taxon_to_products.rb @@ -1,15 +1,18 @@ class AddPrimaryTaxonToProducts < ActiveRecord::Migration - def change + def up add_column :spree_products, :primary_taxon_id, :integer -<<<<<<< HEAD -<<<<<<< HEAD + add_index :spree_products, :primary_taxon_id add_foreign_key :spree_products, :spree_taxons, column: :primary_taxon_id -======= ->>>>>>> fd1e7eb... Adding primary taxon field to product -======= - add_index :spree_products, :primary_taxon_id - add_foreign_key :spree_products, :spree_taxons, column: :primary_taxon_id ->>>>>>> 110a6f2... Adding primary taxon to admin forms + + Spree::Product.all.each do |p| + p.update_column :primary_taxon_id, (p.taxons.first || Spree::Taxon.first) + end + + change_column :spree_products, :primary_taxon_id, :integer, null: false + end + + def down + remove_column :spree_products, :primary_taxon_id end end diff --git a/db/schema.rb b/db/schema.rb index 6005fd7cb5..999ff55705 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -681,7 +681,7 @@ ActiveRecord::Schema.define(:version => 20140522044009) do t.float "variant_unit_scale" t.string "variant_unit_name" t.text "notes" - t.integer "primary_taxon_id" + t.integer "primary_taxon_id", :null => false end add_index "spree_products", ["available_on"], :name => "index_products_on_available_on" From 4e45a682fd6e93a54b273fda611091c6a286854d Mon Sep 17 00:00:00 2001 From: Rohan Mitchell Date: Tue, 3 Jun 2014 11:29:07 +1000 Subject: [PATCH 3/5] Do not show deleted products in order cycle admin --- .../admin/enterprises/_supplied_product.rabl | 10 ++++++++++ app/views/admin/enterprises/index.rabl | 11 +++-------- spec/views/admin/enterprises/index.rabl_spec.rb | 15 +++++++++++++++ 3 files changed, 28 insertions(+), 8 deletions(-) create mode 100644 app/views/admin/enterprises/_supplied_product.rabl create mode 100644 spec/views/admin/enterprises/index.rabl_spec.rb diff --git a/app/views/admin/enterprises/_supplied_product.rabl b/app/views/admin/enterprises/_supplied_product.rabl new file mode 100644 index 0000000000..268ff302d5 --- /dev/null +++ b/app/views/admin/enterprises/_supplied_product.rabl @@ -0,0 +1,10 @@ +object @product + +attributes :name +node(:supplier_name) { |p| p.supplier.andand.name } +node(:image_url) { |p| p.images.present? ? p.images.first.attachment.url(:mini) : nil } +node(:master_id) { |p| p.master.id } +child variants: :variants do |variant| + attributes :id + node(:label) { |v| v.options_text } +end diff --git a/app/views/admin/enterprises/index.rabl b/app/views/admin/enterprises/index.rabl index 9e1ee893d1..1342d6eb1a 100644 --- a/app/views/admin/enterprises/index.rabl +++ b/app/views/admin/enterprises/index.rabl @@ -2,13 +2,8 @@ collection @collection attributes :id, :name -child supplied_products: :supplied_products do |product| - attributes :name - node(:supplier_name) { |p| p.supplier.andand.name } - node(:image_url) { |p| p.images.present? ? p.images.first.attachment.url(:mini) : nil } - node(:master_id) { |p| p.master.id } - child variants: :variants do |variant| - attributes :id - node(:label) { |v| v.options_text } +node(:supplied_products) do |enterprise| + enterprise.supplied_products.not_deleted.map do |product| + partial 'admin/enterprises/supplied_product', object: product end end diff --git a/spec/views/admin/enterprises/index.rabl_spec.rb b/spec/views/admin/enterprises/index.rabl_spec.rb new file mode 100644 index 0000000000..e92388da61 --- /dev/null +++ b/spec/views/admin/enterprises/index.rabl_spec.rb @@ -0,0 +1,15 @@ +require 'spec_helper' + +describe "admin/enterprises/index.rabl" do + let(:enterprise) { create(:distributor_enterprise) } + let!(:product) { create(:simple_product, supplier: enterprise) } + let!(:deleted_product) { create(:simple_product, supplier: enterprise, deleted_at: Time.now) } + let(:render) { Rabl.render([enterprise], 'admin/enterprises/index', view_path: 'app/views', scope: RablHelper::FakeContext.instance) } + + describe "supplied products" do + it "does not render deleted products" do + render.should have_json_size(1).at_path '0/supplied_products' + render.should be_json_eql(product.master.id).at_path '0/supplied_products/0/master_id' + end + end +end From d4f65a63bb96dac3b6cfcf2bf57b6c81af13d504 Mon Sep 17 00:00:00 2001 From: Rohan Mitchell Date: Tue, 3 Jun 2014 11:31:30 +1000 Subject: [PATCH 4/5] Remove spec for removed image --- spec/features/consumer/shopping/shopping_spec.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/spec/features/consumer/shopping/shopping_spec.rb b/spec/features/consumer/shopping/shopping_spec.rb index b1b905fe82..ecc988f7ea 100644 --- a/spec/features/consumer/shopping/shopping_spec.rb +++ b/spec/features/consumer/shopping/shopping_spec.rb @@ -24,7 +24,6 @@ feature "As a consumer I want to shop with a distributor", js: true do page.should have_text distributor.name find("#tab_about a").click first("distributor img")['src'].should == distributor.logo.url(:thumb) - first("#about img")['src'].should == distributor.promo_image.url(:large) end it "shows the producers for a distributor" do From d52c1fa5daeb6cbc8310e94b4e4c078ed07f8a7b Mon Sep 17 00:00:00 2001 From: Rohan Mitchell Date: Tue, 3 Jun 2014 12:18:27 +1000 Subject: [PATCH 5/5] Revert "Do not show deleted products in order cycle admin" This reverts commit 4e45a682fd6e93a54b273fda611091c6a286854d. --- .../admin/enterprises/_supplied_product.rabl | 10 ---------- app/views/admin/enterprises/index.rabl | 11 ++++++++--- spec/views/admin/enterprises/index.rabl_spec.rb | 15 --------------- 3 files changed, 8 insertions(+), 28 deletions(-) delete mode 100644 app/views/admin/enterprises/_supplied_product.rabl delete mode 100644 spec/views/admin/enterprises/index.rabl_spec.rb diff --git a/app/views/admin/enterprises/_supplied_product.rabl b/app/views/admin/enterprises/_supplied_product.rabl deleted file mode 100644 index 268ff302d5..0000000000 --- a/app/views/admin/enterprises/_supplied_product.rabl +++ /dev/null @@ -1,10 +0,0 @@ -object @product - -attributes :name -node(:supplier_name) { |p| p.supplier.andand.name } -node(:image_url) { |p| p.images.present? ? p.images.first.attachment.url(:mini) : nil } -node(:master_id) { |p| p.master.id } -child variants: :variants do |variant| - attributes :id - node(:label) { |v| v.options_text } -end diff --git a/app/views/admin/enterprises/index.rabl b/app/views/admin/enterprises/index.rabl index 1342d6eb1a..9e1ee893d1 100644 --- a/app/views/admin/enterprises/index.rabl +++ b/app/views/admin/enterprises/index.rabl @@ -2,8 +2,13 @@ collection @collection attributes :id, :name -node(:supplied_products) do |enterprise| - enterprise.supplied_products.not_deleted.map do |product| - partial 'admin/enterprises/supplied_product', object: product +child supplied_products: :supplied_products do |product| + attributes :name + node(:supplier_name) { |p| p.supplier.andand.name } + node(:image_url) { |p| p.images.present? ? p.images.first.attachment.url(:mini) : nil } + node(:master_id) { |p| p.master.id } + child variants: :variants do |variant| + attributes :id + node(:label) { |v| v.options_text } end end diff --git a/spec/views/admin/enterprises/index.rabl_spec.rb b/spec/views/admin/enterprises/index.rabl_spec.rb deleted file mode 100644 index e92388da61..0000000000 --- a/spec/views/admin/enterprises/index.rabl_spec.rb +++ /dev/null @@ -1,15 +0,0 @@ -require 'spec_helper' - -describe "admin/enterprises/index.rabl" do - let(:enterprise) { create(:distributor_enterprise) } - let!(:product) { create(:simple_product, supplier: enterprise) } - let!(:deleted_product) { create(:simple_product, supplier: enterprise, deleted_at: Time.now) } - let(:render) { Rabl.render([enterprise], 'admin/enterprises/index', view_path: 'app/views', scope: RablHelper::FakeContext.instance) } - - describe "supplied products" do - it "does not render deleted products" do - render.should have_json_size(1).at_path '0/supplied_products' - render.should be_json_eql(product.master.id).at_path '0/supplied_products/0/master_id' - end - end -end