From 138522bd171eafc5004b19613b77af169389ffb3 Mon Sep 17 00:00:00 2001 From: Luis Ramos Date: Sat, 13 Mar 2021 13:23:23 +0000 Subject: [PATCH 001/534] Add helper to view spec to make it work in rails 5 --- spec/views/spree/shared/_order_details.html.haml_spec.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/spec/views/spree/shared/_order_details.html.haml_spec.rb b/spec/views/spree/shared/_order_details.html.haml_spec.rb index d1b7986203..14ac869fa5 100644 --- a/spec/views/spree/shared/_order_details.html.haml_spec.rb +++ b/spec/views/spree/shared/_order_details.html.haml_spec.rb @@ -1,10 +1,12 @@ # frozen_string_literal: true require "spec_helper" - +require 'checkout_helper' describe "spree/shared/_order_details.html.haml" do include AuthenticationHelper helper Spree::BaseHelper + helper CheckoutHelper + helper OrderHelper let(:order) { create(:completed_order_with_fees) } @@ -12,7 +14,7 @@ describe "spree/shared/_order_details.html.haml" do assign(:order, order) allow(view).to receive_messages( order: order, - current_order: order, + current_order: order ) end From a953a12f76829102a9542cfc00b42d5c2891197e Mon Sep 17 00:00:00 2001 From: Luis Ramos Date: Sat, 13 Mar 2021 13:24:25 +0000 Subject: [PATCH 002/534] Remove dead code --- spec/spec_helper.rb | 1 - spec/support/spree/checkout_helpers.rb | 9 --------- 2 files changed, 10 deletions(-) delete mode 100644 spec/support/spree/checkout_helpers.rb diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index ab8a9802e4..0c08c0a3f4 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -185,7 +185,6 @@ RSpec.configure do |config| # Helpers config.include Rails.application.routes.url_helpers config.include Spree::UrlHelpers - config.include Spree::CheckoutHelpers config.include Spree::MoneyHelper config.include PreferencesHelper config.include ControllerRequestsHelper, type: :controller diff --git a/spec/support/spree/checkout_helpers.rb b/spec/support/spree/checkout_helpers.rb deleted file mode 100644 index 7731fe3822..0000000000 --- a/spec/support/spree/checkout_helpers.rb +++ /dev/null @@ -1,9 +0,0 @@ -# frozen_string_literal: true - -module Spree - module CheckoutHelpers - def click_checkout_continue_button - page.find('#add_new_save_checkout_button input[type=submit]').click - end - end -end From c5581fa25f500d8f52285e359c426ac965bb738d Mon Sep 17 00:00:00 2001 From: Luis Ramos Date: Sat, 13 Mar 2021 13:26:56 +0000 Subject: [PATCH 003/534] Rename spec/support/CheckoutHelper to resolve colision with app/helpers/CheckoutHelper --- spec/features/admin/order_print_ticket_spec.rb | 2 +- spec/features/consumer/shopping/checkout_auth_spec.rb | 2 +- spec/features/consumer/shopping/checkout_paypal_spec.rb | 2 +- spec/features/consumer/shopping/checkout_spec.rb | 2 +- spec/features/consumer/shopping/checkout_stripe_spec.rb | 2 +- spec/features/consumer/shopping/embedded_shopfronts_spec.rb | 2 +- spec/features/consumer/shopping/variant_overrides_spec.rb | 2 +- .../request/{checkout_helper.rb => checkout_request_helper.rb} | 2 +- spec/views/spree/shared/_order_details.html.haml_spec.rb | 2 +- 9 files changed, 9 insertions(+), 9 deletions(-) rename spec/support/request/{checkout_helper.rb => checkout_request_helper.rb} (97%) diff --git a/spec/features/admin/order_print_ticket_spec.rb b/spec/features/admin/order_print_ticket_spec.rb index 15fd46692a..e4d28d045a 100644 --- a/spec/features/admin/order_print_ticket_spec.rb +++ b/spec/features/admin/order_print_ticket_spec.rb @@ -6,7 +6,7 @@ feature ' As an administrator I want to print a ticket for an order ', js: true do - include CheckoutHelper + include CheckoutRequestsHelper include AuthenticationHelper include ActionView::Helpers::NumberHelper diff --git a/spec/features/consumer/shopping/checkout_auth_spec.rb b/spec/features/consumer/shopping/checkout_auth_spec.rb index 7bbb6e8922..2a9d178fc0 100644 --- a/spec/features/consumer/shopping/checkout_auth_spec.rb +++ b/spec/features/consumer/shopping/checkout_auth_spec.rb @@ -6,7 +6,7 @@ feature "As a consumer I want to check out my cart", js: true do include AuthenticationHelper include WebHelper include ShopWorkflow - include CheckoutHelper + include CheckoutRequestsHelper include UIComponentHelper describe "using the checkout" do diff --git a/spec/features/consumer/shopping/checkout_paypal_spec.rb b/spec/features/consumer/shopping/checkout_paypal_spec.rb index 4e8f6dce30..3135aa1d35 100644 --- a/spec/features/consumer/shopping/checkout_paypal_spec.rb +++ b/spec/features/consumer/shopping/checkout_paypal_spec.rb @@ -4,7 +4,7 @@ require "spec_helper" feature "Check out with Paypal", js: true do include ShopWorkflow - include CheckoutHelper + include CheckoutRequestsHelper include AuthenticationHelper include PaypalHelper diff --git a/spec/features/consumer/shopping/checkout_spec.rb b/spec/features/consumer/shopping/checkout_spec.rb index 20e141e262..6c07f0f0b8 100644 --- a/spec/features/consumer/shopping/checkout_spec.rb +++ b/spec/features/consumer/shopping/checkout_spec.rb @@ -5,7 +5,7 @@ require 'spec_helper' feature "As a consumer I want to check out my cart", js: true do include AuthenticationHelper include ShopWorkflow - include CheckoutHelper + include CheckoutRequestsHelper include WebHelper include UIComponentHelper diff --git a/spec/features/consumer/shopping/checkout_stripe_spec.rb b/spec/features/consumer/shopping/checkout_stripe_spec.rb index 07e1d98607..bd98d198a9 100644 --- a/spec/features/consumer/shopping/checkout_stripe_spec.rb +++ b/spec/features/consumer/shopping/checkout_stripe_spec.rb @@ -5,7 +5,7 @@ require 'spec_helper' feature "Check out with Stripe", js: true do include AuthenticationHelper include ShopWorkflow - include CheckoutHelper + include CheckoutRequestsHelper include StripeHelper include StripeStubs diff --git a/spec/features/consumer/shopping/embedded_shopfronts_spec.rb b/spec/features/consumer/shopping/embedded_shopfronts_spec.rb index 2d2d3113f1..86031e1ba5 100644 --- a/spec/features/consumer/shopping/embedded_shopfronts_spec.rb +++ b/spec/features/consumer/shopping/embedded_shopfronts_spec.rb @@ -7,7 +7,7 @@ feature "Using embedded shopfront functionality", js: true do include AuthenticationHelper include WebHelper include ShopWorkflow - include CheckoutHelper + include CheckoutRequestsHelper include UIComponentHelper describe "using iframes" do diff --git a/spec/features/consumer/shopping/variant_overrides_spec.rb b/spec/features/consumer/shopping/variant_overrides_spec.rb index ce8efc02ae..ce093f1c64 100644 --- a/spec/features/consumer/shopping/variant_overrides_spec.rb +++ b/spec/features/consumer/shopping/variant_overrides_spec.rb @@ -6,7 +6,7 @@ feature "shopping with variant overrides defined", js: true do include AuthenticationHelper include WebHelper include ShopWorkflow - include CheckoutHelper + include CheckoutRequestsHelper include UIComponentHelper let(:hub) { create(:distributor_enterprise, with_payment_and_shipping: true) } diff --git a/spec/support/request/checkout_helper.rb b/spec/support/request/checkout_request_helper.rb similarity index 97% rename from spec/support/request/checkout_helper.rb rename to spec/support/request/checkout_request_helper.rb index e27ffd27ed..3a6de815bd 100644 --- a/spec/support/request/checkout_helper.rb +++ b/spec/support/request/checkout_request_helper.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -module CheckoutHelper +module CheckoutRequestsHelper def have_checkout_details have_content "Your details" end diff --git a/spec/views/spree/shared/_order_details.html.haml_spec.rb b/spec/views/spree/shared/_order_details.html.haml_spec.rb index 14ac869fa5..5a37c4519e 100644 --- a/spec/views/spree/shared/_order_details.html.haml_spec.rb +++ b/spec/views/spree/shared/_order_details.html.haml_spec.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true require "spec_helper" -require 'checkout_helper' + describe "spree/shared/_order_details.html.haml" do include AuthenticationHelper helper Spree::BaseHelper From 58c3c49cfbc2c6f1a42222f9a51cd7f11c406d57 Mon Sep 17 00:00:00 2001 From: Luis Ramos Date: Fri, 12 Mar 2021 22:14:02 +0000 Subject: [PATCH 004/534] Adapt to new rspec syntax --- spec/controllers/admin/matomo_settings_controller_spec.rb | 2 +- spec/controllers/api/orders_controller_spec.rb | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/spec/controllers/admin/matomo_settings_controller_spec.rb b/spec/controllers/admin/matomo_settings_controller_spec.rb index 8644557a58..0bc9b35a16 100644 --- a/spec/controllers/admin/matomo_settings_controller_spec.rb +++ b/spec/controllers/admin/matomo_settings_controller_spec.rb @@ -20,7 +20,7 @@ describe Admin::MatomoSettingsController, type: :controller do it "changes Matomo settings" do expect { - post :update, params + post :update, params: params }.to change { [ Spree::Config[:matomo_url], diff --git a/spec/controllers/api/orders_controller_spec.rb b/spec/controllers/api/orders_controller_spec.rb index 2a5421e9cb..2dfd2dd035 100644 --- a/spec/controllers/api/orders_controller_spec.rb +++ b/spec/controllers/api/orders_controller_spec.rb @@ -133,7 +133,7 @@ module Api end it 'can show only completed orders' do - get :index, format: :json, q: { completed_at_not_null: true, s: 'created_at desc' } + get :index, params: { format: :json, q: { completed_at_not_null: true, s: 'created_at desc' } } expect(json_response['orders']).to eq serialized_orders([order4, order3, order2, order1]) end @@ -145,7 +145,7 @@ module Api end it 'returns pagination data when query params contain :per_page]' do - get :index, per_page: 15, page: 1 + get :index, params: { per_page: 15, page: 1 } pagination_data = { 'results' => 2, From f710bbed3efd47795f0fa99026b321cc70bf77a3 Mon Sep 17 00:00:00 2001 From: Luis Ramos Date: Sat, 13 Mar 2021 12:08:10 +0000 Subject: [PATCH 005/534] Convert calls to xhr to post or put with xhr: true --- .../admin/bulk_line_items_controller_spec.rb | 2 +- .../api/product_images_controller_spec.rb | 4 ++-- spec/controllers/cart_controller_spec.rb | 14 +++++++------- spec/controllers/enterprises_controller_spec.rb | 2 +- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/spec/controllers/admin/bulk_line_items_controller_spec.rb b/spec/controllers/admin/bulk_line_items_controller_spec.rb index 4d94591a0e..cdc1d8c0cc 100644 --- a/spec/controllers/admin/bulk_line_items_controller_spec.rb +++ b/spec/controllers/admin/bulk_line_items_controller_spec.rb @@ -237,7 +237,7 @@ describe Admin::BulkLineItemsController, type: :controller do context "hub enterprise" do before do allow(controller).to receive_messages spree_current_user: distributor1.owner - xhr :put, :update, params + put :update, params: params, xhr: true end it "updates the line item" do diff --git a/spec/controllers/api/product_images_controller_spec.rb b/spec/controllers/api/product_images_controller_spec.rb index 95ee3bd3de..b4858ae49e 100644 --- a/spec/controllers/api/product_images_controller_spec.rb +++ b/spec/controllers/api/product_images_controller_spec.rb @@ -19,14 +19,14 @@ module Api let(:current_api_user) { create(:admin_user) } it "saves a new image when none is present" do - xhr :post, :update_product_image, product_id: product_without_image.id, file: image, use_route: :product_images + post :update_product_image, xhr: true, params: { product_id: product_without_image.id, file: image, use_route: :product_images } expect(response.status).to eq 201 expect(product_without_image.images.first.id).to eq json_response['id'] end it "updates an existing product image" do - xhr :post, :update_product_image, product_id: product_with_image.id, file: image, use_route: :product_images + post :update_product_image, xhr: true, params: { product_id: product_with_image.id, file: image, use_route: :product_images } expect(response.status).to eq 200 expect(product_with_image.images.first.id).to eq json_response['id'] diff --git a/spec/controllers/cart_controller_spec.rb b/spec/controllers/cart_controller_spec.rb index b3f6d46c8f..836f7fa5da 100644 --- a/spec/controllers/cart_controller_spec.rb +++ b/spec/controllers/cart_controller_spec.rb @@ -17,7 +17,7 @@ describe CartController, type: :controller do allow(cart_service).to receive(:populate) { true } allow(cart_service).to receive(:valid?) { true } allow(cart_service).to receive(:variants_h) { {} } - xhr :post, :populate, use_route: :spree, format: :json + post :populate, xhr: true, params: { use_route: :spree, format: :json } expect(response.status).to eq(200) end @@ -26,7 +26,7 @@ describe CartController, type: :controller do allow(cart_service).to receive(:valid?) { false } allow(cart_service).to receive(:errors) { errors } allow(errors).to receive(:full_messages).and_return(["Error: foo"]) - xhr :post, :populate, use_route: :spree, format: :json + post :populate, xhr: true, params: { use_route: :spree, format: :json } expect(response.status).to eq(412) end @@ -34,7 +34,7 @@ describe CartController, type: :controller do allow(cart_service).to receive(:variants_h) { {} } allow(cart_service).to receive(:valid?) { true } expect(cart_service).to receive(:populate).with({}, true) - xhr :post, :populate, use_route: :spree, format: :json + post :populate, xhr: true, params: { use_route: :spree, format: :json } end it "returns stock levels as JSON on success" do @@ -44,7 +44,7 @@ describe CartController, type: :controller do allow(cart_service).to receive(:valid?) { true } allow(cart_service).to receive(:variants_h) { {} } - xhr :post, :populate, use_route: :spree, format: :json + post :populate, xhr: true, params: { use_route: :spree, format: :json } data = JSON.parse(response.body) expect(data['stock_levels']).to eq('my_stock_levels') @@ -82,7 +82,7 @@ describe CartController, type: :controller do end it "returns the variant override stock levels of the variant in the order" do - spree_post :populate, variants: { variant_in_the_order.id => 1 } + spree_post :populate, params: { variants: { variant_in_the_order.id => 1 } } data = JSON.parse(response.body) expect(data['stock_levels'][variant_in_the_order.id.to_s]["on_hand"]).to eq 20 @@ -93,7 +93,7 @@ describe CartController, type: :controller do # If the variant was not added to the order, VariantsStockLevels alternative calculation would fail # See #3222 for more details # This indicates that the VariantsStockLevels alternative calculation is never reached - spree_post :populate, variants: { variant_not_in_the_order.id => 1 } + spree_post :populate, params: { variants: { variant_not_in_the_order.id => 1 } } data = JSON.parse(response.body) expect(data['stock_levels'][variant_not_in_the_order.id.to_s]["on_hand"]).to eq 7 @@ -114,7 +114,7 @@ describe CartController, type: :controller do allow(controller).to receive(:current_order).and_return(order) expect do - spree_post :populate, variants: { variant.id => 1 }, variant_attributes: { variant.id => { max_quantity: "3" } } + spree_post :populate, params: { variants: { variant.id => 1 }, variant_attributes: { variant.id => { max_quantity: "3" } } } end.to change(Spree::LineItem, :count).by(1) end end diff --git a/spec/controllers/enterprises_controller_spec.rb b/spec/controllers/enterprises_controller_spec.rb index 86ff995516..cdfa2ef964 100644 --- a/spec/controllers/enterprises_controller_spec.rb +++ b/spec/controllers/enterprises_controller_spec.rb @@ -150,7 +150,7 @@ describe EnterprisesController, type: :controller do # let(:enterprise) { create(:enterprise, permalink: 'enterprise_permalink') } it "responds with status of 200 when the route does not exist" do - xhr :get, :check_permalink, permalink: 'some_nonexistent_route', format: :js + get :check_permalink, xhr: true, params: { permalink: 'some_nonexistent_route', format: :js } expect(response.status).to be 200 end From 25e0262364648cb6a18ce0205fec17e701129d8d Mon Sep 17 00:00:00 2001 From: Luis Ramos Date: Sat, 13 Mar 2021 12:12:16 +0000 Subject: [PATCH 006/534] Adapt spec to new rspec syntax with params and no xhr --- .../enterprises_controller_spec.rb | 32 +++++++++---------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/spec/controllers/enterprises_controller_spec.rb b/spec/controllers/enterprises_controller_spec.rb index cdfa2ef964..1170b7de6e 100644 --- a/spec/controllers/enterprises_controller_spec.rb +++ b/spec/controllers/enterprises_controller_spec.rb @@ -18,7 +18,7 @@ describe EnterprisesController, type: :controller do end it "sets the shop as the distributor on the order when shopping for the distributor" do - get :shop, id: distributor + get :shop, params: { id: distributor } expect(controller.current_distributor).to eq(distributor) expect(controller.current_order.distributor).to eq(distributor) @@ -29,7 +29,7 @@ describe EnterprisesController, type: :controller do before { allow(controller).to receive(:spree_current_user) { user } } it "sets the shop as the distributor on the order when shopping for the distributor" do - get :shop, id: distributor + get :shop, params: { id: distributor } expect(controller.current_distributor).to eq(distributor) expect(controller.current_order.distributor).to eq(distributor) @@ -39,11 +39,11 @@ describe EnterprisesController, type: :controller do it "sorts order cycles by the distributor's preferred ordering attr" do distributor.update_attribute(:preferred_shopfront_order_cycle_order, 'orders_close_at') - get :shop, id: distributor + get :shop, params: { id: distributor } expect(assigns(:order_cycles)).to eq([order_cycle1, order_cycle2].sort_by(&:orders_close_at)) distributor.update_attribute(:preferred_shopfront_order_cycle_order, 'orders_open_at') - get :shop, id: distributor + get :shop, params: { id: distributor } expect(assigns(:order_cycles)).to eq([order_cycle1, order_cycle2].sort_by(&:orders_open_at)) end @@ -64,23 +64,23 @@ describe EnterprisesController, type: :controller do preferred_exchange_tags: "wholesale", preferred_matched_order_cycles_visibility: 'hidden') - get :shop, id: distributor + get :shop, params: { id: distributor } expect(assigns(:order_cycles)).to include order_cycle1, order_cycle2, order_cycle3 allow(controller).to receive(:spree_current_user) { user } - get :shop, id: distributor + get :shop, params: { id: distributor } expect(assigns(:order_cycles)).to include order_cycle1, order_cycle2, order_cycle3 oc3_exchange.update_attribute(:tag_list, "wholesale") - get :shop, id: distributor + get :shop, params: { id: distributor } expect(assigns(:order_cycles)).to include order_cycle1, order_cycle2 expect(assigns(:order_cycles)).not_to include order_cycle3 customer.update_attribute(:tag_list, ["wholesale"]) - get :shop, id: distributor + get :shop, params: { id: distributor } expect(assigns(:order_cycles)).to include order_cycle1, order_cycle2, order_cycle3 end end @@ -89,7 +89,7 @@ describe EnterprisesController, type: :controller do line_item = create(:line_item) controller.current_order.line_items << line_item - get :shop, id: distributor + get :shop, params: { id: distributor } expect(controller.current_order.distributor).to eq(distributor) expect(controller.current_order.order_cycle).to be_nil @@ -97,7 +97,7 @@ describe EnterprisesController, type: :controller do end it "should not empty an order if returning to the same distributor" do - get :shop, id: current_distributor + get :shop, params: { id: current_distributor } expect(controller.current_order.distributor).to eq current_distributor expect(controller.current_order.line_items.first.variant).to eq line_item.variant @@ -117,7 +117,7 @@ describe EnterprisesController, type: :controller do end it "redirects to the cart" do - get :shop, id: current_distributor + get :shop, params: { id: current_distributor } expect(response).to redirect_to cart_path end @@ -129,7 +129,7 @@ describe EnterprisesController, type: :controller do order.save order_cycle1.update_attribute :orders_close_at, Time.zone.now - get :shop, id: distributor + get :shop, params: { id: distributor } expect(controller.current_order.distributor).to eq(distributor) expect(controller.current_order.order_cycle).to eq(order_cycle2) @@ -139,7 +139,7 @@ describe EnterprisesController, type: :controller do it "sets order cycle if only one is available at the chosen distributor" do order_cycle2.destroy - get :shop, id: distributor + get :shop, params: { id: distributor } expect(controller.current_order.distributor).to eq(distributor) expect(controller.current_order.order_cycle).to eq(order_cycle1) @@ -157,16 +157,16 @@ describe EnterprisesController, type: :controller do it "responds with status of 409 when the permalink matches an existing route" do # get :check_permalink, { permalink: 'enterprise_permalink', format: :js } # expect(response.status).to be 409 - xhr :get, :check_permalink, permalink: 'map', format: :js + get :check_permalink, xhr: true, params: { permalink: 'map', format: :js } expect(response.status).to be 409 - xhr :get, :check_permalink, permalink: '', format: :js + get :check_permalink, xhr: true, params: { permalink: '', format: :js } expect(response.status).to be 409 end end context "checking access on nonexistent enterprise" do before do - get :shop, id: "some_nonexistent_enterprise" + get :shop, params: { id: "some_nonexistent_enterprise" } end it "redirects to shops_path" do From 4505fa7fd975d3e2ba95f02e2f266d32a91a050d Mon Sep 17 00:00:00 2001 From: Matt-Yorkley <9029026+Matt-Yorkley@users.noreply.github.com> Date: Thu, 11 Mar 2021 18:28:16 +0000 Subject: [PATCH 007/534] Fix warning on Product variants_including_master scope --- app/models/spree/product.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/spree/product.rb b/app/models/spree/product.rb index 09b239855b..ba436551f8 100755 --- a/app/models/spree/product.rb +++ b/app/models/spree/product.rb @@ -56,7 +56,7 @@ module Spree }, class_name: 'Spree::Variant' has_many :variants_including_master, - -> { order("#{::Spree::Variant.quoted_table_name}.position ASC") }, + -> { order("spree_variants.position ASC") }, class_name: 'Spree::Variant', dependent: :destroy From 29e07869063c67b013787d8e37ee3f8430d7176b Mon Sep 17 00:00:00 2001 From: Matt-Yorkley <9029026+Matt-Yorkley@users.noreply.github.com> Date: Thu, 11 Mar 2021 19:23:06 +0000 Subject: [PATCH 008/534] Fix inheritance of Migration object in spec Fixes: Spree::Preferences::Preferable persisted preferables requires a valid id but returns default values Failure/Error: class CreatePrefTest < ActiveRecord::Migration def self.up create_table :pref_tests do |t| t.string :col end end def self.down drop_table :pref_tests end StandardError: Directly inheriting from ActiveRecord::Migration is not supported. Please specify the Rails release the migration was written for: class CreatePrefTest < ActiveRecord::Migration[4.2] # ./spec/models/spree/preferences/preferable_spec.rb:225:in `block (3 levels) in ' --- spec/models/spree/preferences/preferable_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/models/spree/preferences/preferable_spec.rb b/spec/models/spree/preferences/preferable_spec.rb index 3e156fce1f..b355ba415c 100644 --- a/spec/models/spree/preferences/preferable_spec.rb +++ b/spec/models/spree/preferences/preferable_spec.rb @@ -222,7 +222,7 @@ describe Spree::Preferences::Preferable do describe "persisted preferables" do before(:all) do - class CreatePrefTest < ActiveRecord::Migration + class CreatePrefTest < ActiveRecord::Migration[4.2] def self.up create_table :pref_tests do |t| t.string :col From da6a7da99d675f54af8e7c086e1ecdfbf5424227 Mon Sep 17 00:00:00 2001 From: Luis Ramos Date: Thu, 11 Mar 2021 21:54:08 +0000 Subject: [PATCH 009/534] Remove sanitize This was added here for no specific reason I think, it's just an id, I dont think we need this https://github.com/openfoodfoundation/openfoodnetwork/commit/1d83809866a93f91a507991c12b4e60630ab6fc0 --- app/models/spree/variant.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/spree/variant.rb b/app/models/spree/variant.rb index 93430b3b2b..71c10a16e3 100644 --- a/app/models/spree/variant.rb +++ b/app/models/spree/variant.rb @@ -114,7 +114,7 @@ module Spree joins(" LEFT OUTER JOIN (SELECT * FROM inventory_items - WHERE enterprise_id = #{sanitize enterprise.andand.id}) + WHERE enterprise_id = #{enterprise.andand.id}) AS o_inventory_items ON o_inventory_items.variant_id = spree_variants.id") .where("o_inventory_items.id IS NULL OR o_inventory_items.visible = (?)", true) From 39b1ae0ee8dca4f1fd6e3aa452e7ed2ed40eed02 Mon Sep 17 00:00:00 2001 From: Matt-Yorkley <9029026+Matt-Yorkley@users.noreply.github.com> Date: Fri, 12 Mar 2021 11:07:29 +0000 Subject: [PATCH 010/534] Fix validation conditional in Spree::Product --- app/models/spree/product.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/spree/product.rb b/app/models/spree/product.rb index ba436551f8..bb42d78b43 100755 --- a/app/models/spree/product.rb +++ b/app/models/spree/product.rb @@ -90,7 +90,7 @@ module Spree validates :supplier, presence: true validates :primary_taxon, presence: true - validates :tax_category_id, presence: true, if: "Spree::Config.products_require_tax_category" + validates :tax_category_id, presence: true, if: proc { Spree::Config[:products_require_tax_category] } validates :variant_unit, presence: true validates :unit_value, presence: { if: ->(p) { %w(weight volume).include? p.variant_unit } } From 333a488dc81e9aa19c3910f62072db66c021bf3a Mon Sep 17 00:00:00 2001 From: Luis Ramos Date: Fri, 12 Mar 2021 22:34:33 +0000 Subject: [PATCH 011/534] Fix deprecation warning --- app/models/spree/product.rb | 2 +- spec/models/spree/product_spec.rb | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/models/spree/product.rb b/app/models/spree/product.rb index bb42d78b43..140a508af7 100755 --- a/app/models/spree/product.rb +++ b/app/models/spree/product.rb @@ -52,7 +52,7 @@ module Spree dependent: :destroy has_many :variants, -> { - where(is_master: false).order("#{::Spree::Variant.quoted_table_name}.position ASC") + where(is_master: false).order("spree_variants.position ASC") }, class_name: 'Spree::Variant' has_many :variants_including_master, diff --git a/spec/models/spree/product_spec.rb b/spec/models/spree/product_spec.rb index c1da45eddc..c3814bebf8 100644 --- a/spec/models/spree/product_spec.rb +++ b/spec/models/spree/product_spec.rb @@ -88,13 +88,13 @@ module Spree describe 'Variants sorting' do context 'without master variant' do it 'sorts variants by position' do - expect(product.variants.to_sql).to match(/ORDER BY (\`|\")spree_variants(\`|\").position ASC/) + expect(product.variants.to_sql).to match(/ORDER BY spree_variants.position ASC/) end end context 'with master variant' do it 'sorts variants by position' do - expect(product.variants_including_master.to_sql).to match(/ORDER BY (\`|\")spree_variants(\`|\").position ASC/) + expect(product.variants_including_master.to_sql).to match(/ORDER BY spree_variants.position ASC/) end end end From 12b66d82ab75805474c069e08934cf01430193e5 Mon Sep 17 00:00:00 2001 From: Andy Brett Date: Mon, 8 Mar 2021 11:25:52 -0800 Subject: [PATCH 012/534] verify line item when placing sub order This removes the inventory unit from the shipment manifest, so that the item no longer appears on the order view in the admin view. --- app/jobs/subscription_placement_job.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/jobs/subscription_placement_job.rb b/app/jobs/subscription_placement_job.rb index ee4369c1d9..432ddc021a 100644 --- a/app/jobs/subscription_placement_job.rb +++ b/app/jobs/subscription_placement_job.rb @@ -62,6 +62,7 @@ class SubscriptionPlacementJob < ActiveJob::Base unavailable_stock_lines_for(order).each do |line_item| changes[line_item.id] = changes[line_item.id] || line_item.quantity line_item.update(quantity: 0) + Spree::OrderInventory.new(order).verify(line_item) end changes end From 70b7143e7b7dfba31b6106ecfcaca911470195aa Mon Sep 17 00:00:00 2001 From: Andy Brett Date: Wed, 17 Mar 2021 11:33:27 -0700 Subject: [PATCH 013/534] reload line items and recalculate fees after removing line item --- app/jobs/subscription_placement_job.rb | 7 ++++++- app/models/spree/order_inventory.rb | 3 +-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/app/jobs/subscription_placement_job.rb b/app/jobs/subscription_placement_job.rb index 432ddc021a..4cd02392a4 100644 --- a/app/jobs/subscription_placement_job.rb +++ b/app/jobs/subscription_placement_job.rb @@ -62,7 +62,12 @@ class SubscriptionPlacementJob < ActiveJob::Base unavailable_stock_lines_for(order).each do |line_item| changes[line_item.id] = changes[line_item.id] || line_item.quantity line_item.update(quantity: 0) - Spree::OrderInventory.new(order).verify(line_item) + + Spree::OrderInventory.new(order).verify(line_item, order.shipment) + end + if changes.present? + order.line_items.reload + order.update_order_fees! end changes end diff --git a/app/models/spree/order_inventory.rb b/app/models/spree/order_inventory.rb index 8416bb4755..44ff226609 100644 --- a/app/models/spree/order_inventory.rb +++ b/app/models/spree/order_inventory.rb @@ -98,8 +98,7 @@ module Spree inventory_unit.destroy removed_quantity += 1 end - - shipment.destroy if shipment.inventory_units.count == 0 + shipment.destroy if shipment.inventory_units.reload.count == 0 # removing this from shipment, and adding to stock_location if order.completed? From 429cf4a5cb563b835a85f189d6a2ba61654a391e Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Bellet Date: Tue, 2 Mar 2021 16:04:15 +0100 Subject: [PATCH 014/534] Create a new angularjs module: OFNShared - This module could be shared between Darkswarm and admin - add this new module to test environment --- app/assets/javascripts/admin/admin_ofn.js.coffee | 3 ++- app/assets/javascripts/darkswarm/darkswarm.js.coffee | 3 ++- app/assets/javascripts/shared/shared.js.coffee | 4 ++++ config/ng-test.conf.js | 1 + 4 files changed, 9 insertions(+), 2 deletions(-) create mode 100644 app/assets/javascripts/shared/shared.js.coffee diff --git a/app/assets/javascripts/admin/admin_ofn.js.coffee b/app/assets/javascripts/admin/admin_ofn.js.coffee index bca7364525..639106fe09 100644 --- a/app/assets/javascripts/admin/admin_ofn.js.coffee +++ b/app/assets/javascripts/admin/admin_ofn.js.coffee @@ -8,6 +8,7 @@ angular.module("ofn.admin", [ "admin.dropdown", "admin.products", "admin.taxons", - "infinite-scroll" + "infinite-scroll", + "OFNShared" ]).config ($httpProvider) -> $httpProvider.defaults.headers.common["Accept"] = "application/json, text/javascript, */*" diff --git a/app/assets/javascripts/darkswarm/darkswarm.js.coffee b/app/assets/javascripts/darkswarm/darkswarm.js.coffee index 453f05a2c3..86bc4ef0f2 100644 --- a/app/assets/javascripts/darkswarm/darkswarm.js.coffee +++ b/app/assets/javascripts/darkswarm/darkswarm.js.coffee @@ -10,7 +10,8 @@ window.Darkswarm = angular.module("Darkswarm", [ 'uiGmapgoogle-maps', 'duScroll', 'angularFileUpload', - 'angularSlideables' + 'angularSlideables', + 'OFNShared' ]).config ($httpProvider, $tooltipProvider, $locationProvider, $anchorScrollProvider) -> $httpProvider.defaults.headers['common']['X-Requested-With'] = 'XMLHttpRequest' $httpProvider.defaults.headers.common['Accept'] = "application/json, text/javascript, */*" diff --git a/app/assets/javascripts/shared/shared.js.coffee b/app/assets/javascripts/shared/shared.js.coffee new file mode 100644 index 0000000000..2584fbdc2d --- /dev/null +++ b/app/assets/javascripts/shared/shared.js.coffee @@ -0,0 +1,4 @@ +window.OFNShared = angular.module("OFNShared", [ + +]).config ($httpProvider) -> + $httpProvider.defaults.headers.common["Accept"] = "application/json, text/javascript, */*" diff --git a/config/ng-test.conf.js b/config/ng-test.conf.js index 8c4d5e971b..618b533b58 100644 --- a/config/ng-test.conf.js +++ b/config/ng-test.conf.js @@ -16,6 +16,7 @@ module.exports = function(config) { 'app/assets/javascripts/admin/**/*.js*', 'app/assets/javascripts/darkswarm/*.js*', 'app/assets/javascripts/darkswarm/**/*.js*', + 'app/assets/javascripts/shared/shared.js.coffee', 'spec/javascripts/unit/**/*.js*' ], From 3fcbb1a5fe216305c0e0bd99275c804fa9155f7d Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Bellet Date: Fri, 12 Mar 2021 15:38:56 +0100 Subject: [PATCH 015/534] Move files from darkswarm to shared - As this directive is now used by Darkswarm and admin, move files in shared/ folders - Needs some css variable in admin part : as question-mark-with-tooltip is used in admin part, it needs some css variable - Add own scss variables file with all needed variables for question-mark-icon. Some duplication, but now really independant and shared between both darkswarm and admin. - Remove strange border around the button, rendered by chrome when button is focused. --- .../directives/question_mark_tooltip.js.coffee | 11 ++++++----- .../question_mark_with_tooltip.html.haml | 0 .../question_mark_with_tooltip_icon.html.haml | 0 app/assets/stylesheets/admin/all.scss | 2 ++ .../{darkswarm => shared}/question-mark-icon.scss | 6 ++++++ .../stylesheets/shared/variables/variables.scss | 14 ++++++++++++++ 6 files changed, 28 insertions(+), 5 deletions(-) rename app/assets/javascripts/{darkswarm => shared}/directives/question_mark_tooltip.js.coffee (61%) rename app/assets/javascripts/templates/{ => shared}/question_mark_with_tooltip.html.haml (100%) rename app/assets/javascripts/templates/{ => shared}/question_mark_with_tooltip_icon.html.haml (100%) rename app/assets/stylesheets/{darkswarm => shared}/question-mark-icon.scss (96%) create mode 100644 app/assets/stylesheets/shared/variables/variables.scss diff --git a/app/assets/javascripts/darkswarm/directives/question_mark_tooltip.js.coffee b/app/assets/javascripts/shared/directives/question_mark_tooltip.js.coffee similarity index 61% rename from app/assets/javascripts/darkswarm/directives/question_mark_tooltip.js.coffee rename to app/assets/javascripts/shared/directives/question_mark_tooltip.js.coffee index e93a9779fe..d6f2c87178 100644 --- a/app/assets/javascripts/darkswarm/directives/question_mark_tooltip.js.coffee +++ b/app/assets/javascripts/shared/directives/question_mark_tooltip.js.coffee @@ -1,17 +1,18 @@ -Darkswarm.directive "questionMarkWithTooltip", ($tooltip)-> + +OFNShared.directive "questionMarkWithTooltip", ($tooltip)-> # We use the $tooltip service from Angular foundation to give us boilerplate # Subsequently we patch the scope, template and restrictions tooltip = $tooltip 'questionMarkWithTooltip', 'questionMarkWithTooltip', 'click' tooltip.scope = - context: "=" - tooltip.templateUrl = "question_mark_with_tooltip_icon.html" + variant: "=" + tooltip.templateUrl = "shared/question_mark_with_tooltip_icon.html" tooltip.replace = true tooltip.restrict = 'E' tooltip # This is automatically referenced via naming convention in $tooltip -Darkswarm.directive 'questionMarkWithTooltipPopup', -> +OFNShared.directive 'questionMarkWithTooltipPopup', -> restrict: 'EA' replace: true - templateUrl: 'question_mark_with_tooltip.html' + templateUrl: 'shared/question_mark_with_tooltip.html' scope: false diff --git a/app/assets/javascripts/templates/question_mark_with_tooltip.html.haml b/app/assets/javascripts/templates/shared/question_mark_with_tooltip.html.haml similarity index 100% rename from app/assets/javascripts/templates/question_mark_with_tooltip.html.haml rename to app/assets/javascripts/templates/shared/question_mark_with_tooltip.html.haml diff --git a/app/assets/javascripts/templates/question_mark_with_tooltip_icon.html.haml b/app/assets/javascripts/templates/shared/question_mark_with_tooltip_icon.html.haml similarity index 100% rename from app/assets/javascripts/templates/question_mark_with_tooltip_icon.html.haml rename to app/assets/javascripts/templates/shared/question_mark_with_tooltip_icon.html.haml diff --git a/app/assets/stylesheets/admin/all.scss b/app/assets/stylesheets/admin/all.scss index 12635372f3..bcd049a94f 100644 --- a/app/assets/stylesheets/admin/all.scss +++ b/app/assets/stylesheets/admin/all.scss @@ -48,3 +48,5 @@ @import 'components/*'; @import 'pages/*'; @import '*'; + +@import "../shared/question-mark-icon"; diff --git a/app/assets/stylesheets/darkswarm/question-mark-icon.scss b/app/assets/stylesheets/shared/question-mark-icon.scss similarity index 96% rename from app/assets/stylesheets/darkswarm/question-mark-icon.scss rename to app/assets/stylesheets/shared/question-mark-icon.scss index 82728f2ea2..6de5315c4f 100644 --- a/app/assets/stylesheets/darkswarm/question-mark-icon.scss +++ b/app/assets/stylesheets/shared/question-mark-icon.scss @@ -1,3 +1,5 @@ +@import "variables/variables"; + .unit-price { display: flex; align-items: center; @@ -26,6 +28,10 @@ background-image: none; background-color: $teal-500; + &:focus { + outline: 0; + } + &::before { @include icon-font; content: ""; diff --git a/app/assets/stylesheets/shared/variables/variables.scss b/app/assets/stylesheets/shared/variables/variables.scss new file mode 100644 index 0000000000..04e2d9eae5 --- /dev/null +++ b/app/assets/stylesheets/shared/variables/variables.scss @@ -0,0 +1,14 @@ +$padding-small: 0.5rem; +$radius-small: 0.25em; +$white: #fff; +$dynamic-blue: #3d8dd1; +$teal-500: #0096ad; +@import "../../darkswarm/style"; // Import "OFN" font +@mixin icon-font { + font-family: "OFN"; + display: inline-block; + font-weight: normal; + font-style: normal; + font-variant: normal; + text-transform: none; +} \ No newline at end of file From ec0f99a949e7f26b4f322fe64342b4d78f1aded0 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Bellet Date: Fri, 5 Mar 2021 10:03:40 +0100 Subject: [PATCH 016/534] Add joyride-tip-guide css specifications - Could not add the file itself because of many dependancies are broken the admin part. - Just use the strict minimum --- app/assets/stylesheets/admin/all.scss | 1 + .../admin/question-mark-tooltip.scss | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+) create mode 100644 app/assets/stylesheets/admin/question-mark-tooltip.scss diff --git a/app/assets/stylesheets/admin/all.scss b/app/assets/stylesheets/admin/all.scss index bcd049a94f..bafa929c49 100644 --- a/app/assets/stylesheets/admin/all.scss +++ b/app/assets/stylesheets/admin/all.scss @@ -50,3 +50,4 @@ @import '*'; @import "../shared/question-mark-icon"; +@import "question-mark-tooltip"; diff --git a/app/assets/stylesheets/admin/question-mark-tooltip.scss b/app/assets/stylesheets/admin/question-mark-tooltip.scss new file mode 100644 index 0000000000..8247a5b5b8 --- /dev/null +++ b/app/assets/stylesheets/admin/question-mark-tooltip.scss @@ -0,0 +1,18 @@ +.joyride-tip-guide { + background: $color-3; + color: $white; + font-family: inherit; + font-weight: $font-weight-normal; + position: absolute; + z-index: 101; + padding: 5px 15px; + + .joyride-nub.bottom { + border: 10px solid; + display: block; + height: 0; + position: absolute; + width: 0; + } +} + From daa7cca8665921d0886d647432b8a281ccb0ce19 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Bellet Date: Tue, 2 Mar 2021 22:50:04 +0100 Subject: [PATCH 017/534] Adjust import to include shared/* between Darkswarm and admin - Import joyride css file - Used by question-mark-with-tooltip used in admin part --- app/assets/javascripts/admin/all.js | 3 +++ app/assets/javascripts/darkswarm/all.js.coffee | 2 ++ app/assets/stylesheets/darkswarm/all.scss | 2 ++ 3 files changed, 7 insertions(+) diff --git a/app/assets/javascripts/admin/all.js b/app/assets/javascripts/admin/all.js index 6f0dc8bbd4..f28f55565a 100644 --- a/app/assets/javascripts/admin/all.js +++ b/app/assets/javascripts/admin/all.js @@ -52,6 +52,9 @@ //= require admin/spree/handlebar_extensions // OFN specific +//= require ../shared/shared +//= require_tree ../shared/directives +//= require_tree ../templates/shared //= require_tree ../templates/admin //= require ./admin_ofn //= require ./customers/customers diff --git a/app/assets/javascripts/darkswarm/all.js.coffee b/app/assets/javascripts/darkswarm/all.js.coffee index e7a53a9268..30b5d19c07 100644 --- a/app/assets/javascripts/darkswarm/all.js.coffee +++ b/app/assets/javascripts/darkswarm/all.js.coffee @@ -19,6 +19,8 @@ #= require ../shared/ng-infinite-scroll.min.js #= require ../shared/angular-local-storage.js #= require ../shared/angular-slideables.js +#= require ../shared/shared +#= require_tree ../shared/directives #= require angularjs-file-upload #= require i18n/translations diff --git a/app/assets/stylesheets/darkswarm/all.scss b/app/assets/stylesheets/darkswarm/all.scss index 7698726035..2a7eefd1e9 100644 --- a/app/assets/stylesheets/darkswarm/all.scss +++ b/app/assets/stylesheets/darkswarm/all.scss @@ -21,3 +21,5 @@ ofn-modal { display: block; } + +@import "../shared/question-mark-icon"; From 30606704662f9e91cac48bc1fa8c39045b307b13 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Bellet Date: Thu, 18 Feb 2021 11:28:00 +0100 Subject: [PATCH 018/534] Add a key parameter to have possibility of different text inside - The tooltip between the shopfront and the admin will not be the same --- .../shared/directives/question_mark_tooltip.js.coffee | 1 + .../templates/shared/question_mark_with_tooltip.html.haml | 2 +- .../templates/shop_variant_with_unit_price.html.haml | 3 ++- config/locales/en.yml | 3 ++- 4 files changed, 6 insertions(+), 3 deletions(-) diff --git a/app/assets/javascripts/shared/directives/question_mark_tooltip.js.coffee b/app/assets/javascripts/shared/directives/question_mark_tooltip.js.coffee index d6f2c87178..6fa2d46ee5 100644 --- a/app/assets/javascripts/shared/directives/question_mark_tooltip.js.coffee +++ b/app/assets/javascripts/shared/directives/question_mark_tooltip.js.coffee @@ -5,6 +5,7 @@ OFNShared.directive "questionMarkWithTooltip", ($tooltip)-> tooltip = $tooltip 'questionMarkWithTooltip', 'questionMarkWithTooltip', 'click' tooltip.scope = variant: "=" + key: "=" tooltip.templateUrl = "shared/question_mark_with_tooltip_icon.html" tooltip.replace = true tooltip.restrict = 'E' diff --git a/app/assets/javascripts/templates/shared/question_mark_with_tooltip.html.haml b/app/assets/javascripts/templates/shared/question_mark_with_tooltip.html.haml index 75a697fe12..9c68ca47c4 100644 --- a/app/assets/javascripts/templates/shared/question_mark_with_tooltip.html.haml +++ b/app/assets/javascripts/templates/shared/question_mark_with_tooltip.html.haml @@ -1,6 +1,6 @@ .joyride-tip-guide.question-mark-tooltip{class: "{{ context }}", ng: {class: "{ in: tt_isOpen, fade: tt_animation }", show: "tt_isOpen"}} .background{ng: {click: "tt_isOpen = false"}} .joyride-content-wrapper - {{ "js.shopfront.unit_price_tooltip" | t }} + {{ key | t }} %span.joyride-nub.bottom \ No newline at end of file diff --git a/app/assets/javascripts/templates/shop_variant_with_unit_price.html.haml b/app/assets/javascripts/templates/shop_variant_with_unit_price.html.haml index 4a3d2d7211..c9b9785a2c 100644 --- a/app/assets/javascripts/templates/shop_variant_with_unit_price.html.haml +++ b/app/assets/javascripts/templates/shop_variant_with_unit_price.html.haml @@ -12,7 +12,8 @@ %question-mark-with-tooltip{"question-mark-with-tooltip" => "_", "question-mark-with-tooltip-append-to-body" => "true", "question-mark-with-tooltip-placement" => "top", - "question-mark-with-tooltip-animation" => true} + "question-mark-with-tooltip-animation" => true, + key: "'js.shopfront.unit_price_tooltip.shopfront'"} {{ variant.unit_price_price | localizeCurrency }} / {{ variant.unit_price_unit }} .medium-2.large-2.columns.total-price diff --git a/config/locales/en.yml b/config/locales/en.yml index 8aefff8022..91718b176f 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -2782,7 +2782,8 @@ See the %{link} to find out more about %{sitename}'s features and to start using min_quantity: "Min quantity" max_quantity: "Max quantity" price_breakdown: "Price breakdown" - unit_price_tooltip: "This is the unit price of this product. It allows you to compare the price of products independent of packaging sizes & weights." + unit_price_tooltip: + shopfront: "This is the unit price of this product. It allows you to compare the price of products independent of packaging sizes & weights." variants: on_demand: "yes": "On demand" From b494cd2f8ba7bbd403bdaf030cb04121edd87d79 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Bellet Date: Fri, 5 Mar 2021 10:57:46 +0100 Subject: [PATCH 019/534] Add unit price field to New Product form - Add a new i18n key for the content of the tooltip: js.shopfront.unit_price_tooltip.admin - Display unit price readonly field near the price field - Still fake values, needs to be updated --- app/views/spree/admin/products/new.html.haml | 35 ++++++++++++++------ config/locales/en.yml | 3 ++ 2 files changed, 28 insertions(+), 10 deletions(-) diff --git a/app/views/spree/admin/products/new.html.haml b/app/views/spree/admin/products/new.html.haml index 5bc7530619..d51a363344 100644 --- a/app/views/spree/admin/products/new.html.haml +++ b/app/views/spree/admin/products/new.html.haml @@ -45,33 +45,48 @@ .sixteen.columns.alpha .eight.columns.alpha = render 'spree/admin/products/primary_taxon_form', f: f - .three.columns + .four.columns = f.field_container :price do = f.label :price, t(".price") %span.required * %br/ = f.text_field :price, class: 'fullwidth' = f.error_message_on :price + - if feature? :unit_price, spree_current_user + .four.columns{ ng: { app: 'ofn.admin'}} + = f.field_container :unit_price do + = f.label :unit_price, t(".unit_price") + %question-mark-with-tooltip{"question-mark-with-tooltip" => "_", + "question-mark-with-tooltip-append-to-body" => "true", + "question-mark-with-tooltip-placement" => "top", + "question-mark-with-tooltip-animation" => true, + key: "'js.shopfront.unit_price_tooltip.admin'"} + %br/ + = f.text_field :price, class: '', disabled: true, value: "value" + %span{style: "color: #757575"} + unit + %div{style: "color: black"} + = t(".unit_price_legend") + .sixteen.columns.alpha .three.columns + - if Spree::TaxCategory.any? + = render 'spree/admin/products/tax_category_form', f: f + - else +   + .five.columns.omega + = render 'spree/admin/products/shipping_category_form', f: f + .five.columns = f.field_container :on_hand do = f.label :on_hand, t(".on_hand") %br/ = f.text_field :on_hand, class: 'fullwidth' = f.error_message_on :on_hand - .two.columns.omega + .three.columns.omega = f.field_container :on_demand do = f.label :on_demand, t(".on_demand") %br/ = f.check_box :on_demand = f.error_message_on :on_demand - .sixteen.columns.alpha - .four.columns - - if Spree::TaxCategory.any? - = render 'spree/admin/products/tax_category_form', f: f - - else -   - .four.columns.omega - = render 'spree/admin/products/shipping_category_form', f: f .sixteen.columns.alpha = f.field_container :description do diff --git a/config/locales/en.yml b/config/locales/en.yml index 91718b176f..dc394f165e 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -2784,6 +2784,7 @@ See the %{link} to find out more about %{sitename}'s features and to start using price_breakdown: "Price breakdown" unit_price_tooltip: shopfront: "This is the unit price of this product. It allows you to compare the price of products independent of packaging sizes & weights." + admin: "The unit price increases transparency by allowing your customers to easily compare prices between different products and packaging sizes. Note, that the final unit price displayed in the shopfront might differ as it is includes taxes & fees." variants: on_demand: "yes": "On demand" @@ -3478,6 +3479,8 @@ See the %{link} to find out more about %{sitename}'s features and to start using value: "Value" unit_name: "Unit name" price: "Price" + unit_price: "Unit Price" + unit_price_legend: "Calculated based on the item price" on_hand: "On Hand" on_demand: "On Demand" product_description: "Product Description" From 7abb3868fce195bd38578fd3e37ce91ba9c4bfc9 Mon Sep 17 00:00:00 2001 From: Andy Brett Date: Tue, 2 Mar 2021 21:48:31 -0800 Subject: [PATCH 020/534] add UnitPrices service --- .../products/services/unit_prices.js.coffee | 25 +++++++++++++++++++ .../services/variant_unit_manager.js.coffee | 6 +++++ 2 files changed, 31 insertions(+) create mode 100644 app/assets/javascripts/admin/products/services/unit_prices.js.coffee diff --git a/app/assets/javascripts/admin/products/services/unit_prices.js.coffee b/app/assets/javascripts/admin/products/services/unit_prices.js.coffee new file mode 100644 index 0000000000..0867d8deb8 --- /dev/null +++ b/app/assets/javascripts/admin/products/services/unit_prices.js.coffee @@ -0,0 +1,25 @@ +angular.module("admin.products").factory "UnitPrices", (VariantUnitManager) -> + class UnitPrices + @price: (price, scale, unit_type, unit_value) -> + price / @denominator(unit_value, variant_unit) + + @denominator: (scale, unit_type, unit_value) -> + unit = @unit(scale, unit_type) + if unit == "lb" + unit_value / 453.6 + else if unit == "kg" + unit_value / 1000 + else + unit_value + + @unit: (scale, unit_type, variant_unit_name = '') -> + if VariantUnitManager.systemOfMeasurement(scale, unit_type) == "imperial" + "lb" + else if unit_type == "weight" + "kg" + else if unit_type == "volume" + "L" + else if variant_unit_name.length > 0 + variant_unit_name + else + "item" diff --git a/app/assets/javascripts/admin/products/services/variant_unit_manager.js.coffee b/app/assets/javascripts/admin/products/services/variant_unit_manager.js.coffee index 7875347ac8..31a3a14bd9 100644 --- a/app/assets/javascripts/admin/products/services/variant_unit_manager.js.coffee +++ b/app/assets/javascripts/admin/products/services/variant_unit_manager.js.coffee @@ -67,3 +67,9 @@ angular.module("admin.products").factory "VariantUnitManager", (availableUnits) scaleSystem = @units[unitType][scale]['system'] (parseFloat(scale) for scale, scaleInfo of @units[unitType] when scaleInfo['system'] == scaleSystem).sort (a, b) -> a - b + + @systemOfMeasurement: (scale, unitType) -> + if @units[unitType][scale] + @units[unitType][scale]['system'] + else + 'custom' From 8ad3109e950ab736f91314f6e7525e64443726ad Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Bellet Date: Thu, 18 Mar 2021 09:47:21 +0100 Subject: [PATCH 021/534] Pass needed arguments and reorder state machine - Arguments were misordered and `scale` is needed to compute the denominator. - Reorder "state machine" if-else as variant_unit_name is priority and "item" is too. - @andrewpbrett I need your review here ;) - Still need to test imperial system --- .../products/services/unit_prices.js.coffee | 14 +-- .../services/unit_prices_spec.js.coffee | 116 ++++++++++++++++++ 2 files changed, 123 insertions(+), 7 deletions(-) create mode 100644 spec/javascripts/unit/admin/products/services/unit_prices_spec.js.coffee diff --git a/app/assets/javascripts/admin/products/services/unit_prices.js.coffee b/app/assets/javascripts/admin/products/services/unit_prices.js.coffee index 0867d8deb8..bf6655ae37 100644 --- a/app/assets/javascripts/admin/products/services/unit_prices.js.coffee +++ b/app/assets/javascripts/admin/products/services/unit_prices.js.coffee @@ -1,7 +1,7 @@ angular.module("admin.products").factory "UnitPrices", (VariantUnitManager) -> class UnitPrices @price: (price, scale, unit_type, unit_value) -> - price / @denominator(unit_value, variant_unit) + price / @denominator(scale, unit_type, unit_value) @denominator: (scale, unit_type, unit_value) -> unit = @unit(scale, unit_type) @@ -13,13 +13,13 @@ angular.module("admin.products").factory "UnitPrices", (VariantUnitManager) -> unit_value @unit: (scale, unit_type, variant_unit_name = '') -> - if VariantUnitManager.systemOfMeasurement(scale, unit_type) == "imperial" + if variant_unit_name.length > 0 + variant_unit_name + else if unit_type == "items" + "item" + else if VariantUnitManager.systemOfMeasurement(scale, unit_type) == "imperial" "lb" else if unit_type == "weight" "kg" else if unit_type == "volume" - "L" - else if variant_unit_name.length > 0 - variant_unit_name - else - "item" + "L" \ No newline at end of file diff --git a/spec/javascripts/unit/admin/products/services/unit_prices_spec.js.coffee b/spec/javascripts/unit/admin/products/services/unit_prices_spec.js.coffee new file mode 100644 index 0000000000..c21f3a16a4 --- /dev/null +++ b/spec/javascripts/unit/admin/products/services/unit_prices_spec.js.coffee @@ -0,0 +1,116 @@ +describe "UnitPrices service", -> + UnitPrices = null + + beforeEach -> + module "admin.products" + module ($provide)-> + $provide.value "availableUnits", "g,kg,T,mL,L,kL" + null + inject (_UnitPrices_) -> + UnitPrices = _UnitPrices_ + + describe "get correct unit price duo unit/value for weight", -> + unit_type = "weight" + + it "with scale: 1", -> + price = 1 + scale = 1 + unit_value = 1 + expect(UnitPrices.price(price, scale, unit_type, unit_value)).toEqual 1000 + expect(UnitPrices.unit(scale, unit_type)).toEqual "kg" + + it "with scale and unit_value: 1000", -> + price = 1 + scale = 1000 + unit_value = 1000 + expect(UnitPrices.price(price, scale, unit_type, unit_value)).toEqual 1 + expect(UnitPrices.unit(scale, unit_type)).toEqual "kg" + + it "with scale: 1000 and unit_value: 2000", -> + price = 1 + scale = 1000 + unit_value = 2000 + expect(UnitPrices.price(price, scale, unit_type, unit_value)).toEqual 0.5 + expect(UnitPrices.unit(scale, unit_type)).toEqual "kg" + + it "with price: 2", -> + price = 2 + scale = 1 + unit_value = 1 + expect(UnitPrices.price(price, scale, unit_type, unit_value)).toEqual 2000 + expect(UnitPrices.unit(scale, unit_type)).toEqual "kg" + + it "with price: 2, scale and unit_value: 1000", -> + price = 2 + scale = 1000 + unit_value = 1000 + expect(UnitPrices.price(price, scale, unit_type, unit_value)).toEqual 2 + expect(UnitPrices.unit(scale, unit_type)).toEqual "kg" + + it "with price: 2, scale: 1000 and unit_value: 2000", -> + price = 2 + scale = 1000 + unit_value = 2000 + expect(UnitPrices.price(price, scale, unit_type, unit_value)).toEqual 1 + expect(UnitPrices.unit(scale, unit_type)).toEqual "kg" + + it "with price: 2, scale: 1000 and unit_value: 500", -> + price = 2 + scale = 1000 + unit_value = 500 + expect(UnitPrices.price(price, scale, unit_type, unit_value)).toEqual 4 + expect(UnitPrices.unit(scale, unit_type)).toEqual "kg" + + + describe "get correct unit price duo unit/value for volume", -> + unit_type = "volume" + + it "with scale: 1", -> + price = 1 + scale = 1 + unit_value = 1 + expect(UnitPrices.price(price, scale, unit_type, unit_value)).toEqual 1 + expect(UnitPrices.unit(scale, unit_type)).toEqual "L" + + it "with price: 2 and unit_value: 0.5", -> + price = 2 + scale = 1 + unit_value = 0.5 + expect(UnitPrices.price(price, scale, unit_type, unit_value)).toEqual 4 + expect(UnitPrices.unit(scale, unit_type)).toEqual "L" + + it "with price: 2, scale: 0.001 and unit_value: 0.01", -> + price = 2 + scale = 0.001 + unit_value = 0.01 + expect(UnitPrices.price(price, scale, unit_type, unit_value)).toEqual 200 + expect(UnitPrices.unit(scale, unit_type)).toEqual "L" + + it "with price: 20000, scale: 1000 and unit_value: 10000", -> + price = 20000 + scale = 1000 + unit_value = 10000 + expect(UnitPrices.price(price, scale, unit_type, unit_value)).toEqual 2 + expect(UnitPrices.unit(scale, unit_type)).toEqual "L" + + describe "get correct unit price duo unit/value for items", -> + unit_type = "items" + scale = null + + it "with price: 1 and unit_value: 1", -> + price = 1 + unit_value = 1 + expect(UnitPrices.price(price, scale, unit_type, unit_value)).toEqual 1 + expect(UnitPrices.unit(scale, unit_type)).toEqual "item" + + it "with price: 1 and unit_value: 10", -> + price = 1 + unit_value = 10 + expect(UnitPrices.price(price, scale, unit_type, unit_value)).toEqual 0.1 + expect(UnitPrices.unit(scale, unit_type)).toEqual "item" + + it "with price: 10 and unit_value: 1", -> + price = 10 + unit_value = 1 + expect(UnitPrices.price(price, scale, unit_type, unit_value)).toEqual 10 + expect(UnitPrices.unit(scale, unit_type)).toEqual "item" From fa4974ddb2ae22b0908c06fd3cc85883a8d22d34 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Bellet Date: Mon, 8 Mar 2021 12:22:58 +0100 Subject: [PATCH 022/534] React to form changes, compute unit price and display accurate values. - Add method `processUnitPrice` which is responsible for computing the right unit price, that depends on `price`, `variant_unit_scale`, `variant_unit`, `unit_value` and `variant_unit_name` - Watch the needed model to compute the unit price: `product.price` and `product.variant_unit_name` - Add dependencies : UnitPrices and localizeCurrencyFilter - Add currencyconfig to spec, as it's needed by localizeCurrencyFilter - Put `'ng-controller' => 'unitsCtrl'` to the relevant node. - Add new ng-model, as it's needed to watch it in order to compute unit price : `product.price` - Finally display the needed information: `product.unit_price_value` and `product.unit_price_unit` --- .../controllers/units_controller.js.coffee | 15 +++++++++++++-- app/views/spree/admin/products/new.html.haml | 13 +++++++------ .../products/units_controller_spec.js.coffee | 6 ++++++ 3 files changed, 26 insertions(+), 8 deletions(-) diff --git a/app/assets/javascripts/admin/products/controllers/units_controller.js.coffee b/app/assets/javascripts/admin/products/controllers/units_controller.js.coffee index a84f048580..a8646cceb8 100644 --- a/app/assets/javascripts/admin/products/controllers/units_controller.js.coffee +++ b/app/assets/javascripts/admin/products/controllers/units_controller.js.coffee @@ -1,12 +1,13 @@ angular.module("admin.products") - .controller "unitsCtrl", ($scope, VariantUnitManager, OptionValueNamer) -> + .controller "unitsCtrl", ($scope, VariantUnitManager, OptionValueNamer, UnitPrices, localizeCurrencyFilter) -> $scope.product = { master: {} } $scope.product.master.product = $scope.product $scope.placeholder_text = "" - $scope.$watchCollection '[product.variant_unit_with_scale, product.master.unit_value_with_description]', -> + $scope.$watchCollection '[product.variant_unit_with_scale, product.master.unit_value_with_description, product.price, product.variant_unit_name]', -> $scope.processVariantUnitWithScale() $scope.processUnitValueWithDescription() + $scope.processUnitPrice() $scope.placeholder_text = new OptionValueNamer($scope.product.master).name() $scope.variant_unit_options = VariantUnitManager.variantUnitOptions() @@ -32,6 +33,16 @@ angular.module("admin.products") $scope.product.master.unit_value *= $scope.product.variant_unit_scale if $scope.product.master.unit_value && $scope.product.variant_unit_scale $scope.product.master.unit_description = match[3] + $scope.processUnitPrice = -> + price = $scope.product.price + scale = $scope.product.variant_unit_scale + unit_type = $scope.product.variant_unit + unit_value = $scope.product.master.unit_value + variant_unit_name = $scope.product.variant_unit_name + if price && unit_type && unit_value + $scope.product.unit_price_value = localizeCurrencyFilter(UnitPrices.price(price, scale, unit_type, unit_value, variant_unit_name)) + $scope.product.unit_price_unit = UnitPrices.unit(scale, unit_type, variant_unit_name) + $scope.hasVariants = (product) -> Object.keys(product.variants).length > 0 diff --git a/app/views/spree/admin/products/new.html.haml b/app/views/spree/admin/products/new.html.haml index d51a363344..da605a22a1 100644 --- a/app/views/spree/admin/products/new.html.haml +++ b/app/views/spree/admin/products/new.html.haml @@ -4,7 +4,7 @@ = form_for [:admin, @product], :html => { :multipart => true } do |f| .twelve.columns.alpha - %fieldset.no-border-bottom{ id: "new_product" } + %fieldset.no-border-bottom{ id: "new_product", 'ng-controller' => 'unitsCtrl' } %legend{align: "center"}= t(".new_product") .sixteen.columns.alpha .eight.columns.alpha @@ -20,7 +20,7 @@ %br/ = f.text_field :name, :class => 'fullwidth title' = f.error_message_on :name - .sixteen.columns.alpha{ 'ng-controller' => 'unitsCtrl' } + .sixteen.columns.alpha .eight.columns.alpha = f.field_container :units do = f.label :variant_unit_with_scale, t(".units") @@ -50,7 +50,7 @@ = f.label :price, t(".price") %span.required * %br/ - = f.text_field :price, class: 'fullwidth' + = f.text_field :price, { "class" => "fullwidth", "ng-model" => "product.price" } = f.error_message_on :price - if feature? :unit_price, spree_current_user .four.columns{ ng: { app: 'ofn.admin'}} @@ -62,9 +62,10 @@ "question-mark-with-tooltip-animation" => true, key: "'js.shopfront.unit_price_tooltip.admin'"} %br/ - = f.text_field :price, class: '', disabled: true, value: "value" - %span{style: "color: #757575"} - unit + = f.text_field :price, {"class" => '', "disabled" => true, "ng-model" => "product.unit_price_value"} + %span +  /  + %span{style: "color: #757575", "ng-bind" => "product.unit_price_unit" } %div{style: "color: black"} = t(".unit_price_legend") .sixteen.columns.alpha diff --git a/spec/javascripts/unit/admin/products/units_controller_spec.js.coffee b/spec/javascripts/unit/admin/products/units_controller_spec.js.coffee index bb9175eaca..7e7ea03888 100644 --- a/spec/javascripts/unit/admin/products/units_controller_spec.js.coffee +++ b/spec/javascripts/unit/admin/products/units_controller_spec.js.coffee @@ -2,11 +2,17 @@ describe "unitsCtrl", -> ctrl = null scope = null product = null + currencyconfig = + symbol: "$" + symbol_position: "before" + currency: "D" + hide_cents: "false" beforeEach -> module('admin.products') module ($provide)-> $provide.value "availableUnits", "g,kg,T,mL,L,kL" + $provide.value "currencyConfig", currencyconfig null inject ($rootScope, $controller, VariantUnitManager) -> scope = $rootScope From c8099dc2a4f8fbb0f42b713d227645b5b0a909db Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Bellet Date: Tue, 9 Mar 2021 14:03:54 +0100 Subject: [PATCH 023/534] Do not display unit price value and unit until information is filled - Display the field but with `null` value --- .../admin/products/controllers/units_controller.js.coffee | 2 ++ app/views/spree/admin/products/new.html.haml | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/app/assets/javascripts/admin/products/controllers/units_controller.js.coffee b/app/assets/javascripts/admin/products/controllers/units_controller.js.coffee index a8646cceb8..b3bbacc09b 100644 --- a/app/assets/javascripts/admin/products/controllers/units_controller.js.coffee +++ b/app/assets/javascripts/admin/products/controllers/units_controller.js.coffee @@ -39,6 +39,8 @@ angular.module("admin.products") unit_type = $scope.product.variant_unit unit_value = $scope.product.master.unit_value variant_unit_name = $scope.product.variant_unit_name + $scope.product.unit_price_value = null + $scope.product.unit_price_unit = null if price && unit_type && unit_value $scope.product.unit_price_value = localizeCurrencyFilter(UnitPrices.price(price, scale, unit_type, unit_value, variant_unit_name)) $scope.product.unit_price_unit = UnitPrices.unit(scale, unit_type, variant_unit_name) diff --git a/app/views/spree/admin/products/new.html.haml b/app/views/spree/admin/products/new.html.haml index da605a22a1..a5ce8ab67e 100644 --- a/app/views/spree/admin/products/new.html.haml +++ b/app/views/spree/admin/products/new.html.haml @@ -63,9 +63,9 @@ key: "'js.shopfront.unit_price_tooltip.admin'"} %br/ = f.text_field :price, {"class" => '', "disabled" => true, "ng-model" => "product.unit_price_value"} - %span + %span{ style: "color: #757575", "ng-show": "product.unit_price_unit !== null" }  /  - %span{style: "color: #757575", "ng-bind" => "product.unit_price_unit" } + %span{ "ng-bind" => "product.unit_price_unit" } %div{style: "color: black"} = t(".unit_price_legend") .sixteen.columns.alpha From c084299b72ba06444001872c992e3d3c568df66a Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Bellet Date: Thu, 18 Mar 2021 09:47:44 +0100 Subject: [PATCH 024/534] Add tests in imperial weight system --- .../services/unit_prices_spec.js.coffee | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/spec/javascripts/unit/admin/products/services/unit_prices_spec.js.coffee b/spec/javascripts/unit/admin/products/services/unit_prices_spec.js.coffee index c21f3a16a4..1c5067f7ee 100644 --- a/spec/javascripts/unit/admin/products/services/unit_prices_spec.js.coffee +++ b/spec/javascripts/unit/admin/products/services/unit_prices_spec.js.coffee @@ -4,7 +4,7 @@ describe "UnitPrices service", -> beforeEach -> module "admin.products" module ($provide)-> - $provide.value "availableUnits", "g,kg,T,mL,L,kL" + $provide.value "availableUnits", "g,kg,T,mL,L,kL,oz,lb" null inject (_UnitPrices_) -> UnitPrices = _UnitPrices_ @@ -114,3 +114,21 @@ describe "UnitPrices service", -> unit_value = 1 expect(UnitPrices.price(price, scale, unit_type, unit_value)).toEqual 10 expect(UnitPrices.unit(scale, unit_type)).toEqual "item" + + + describe "get correct unit price duo unit/value for weight in imperial system", -> + unit_type = "weight" + + it "with price: 1 and scale/unit_value: 28.35 (OZ)", -> + price = 1 + scale = 28.35 + unit_value = 28.35 + expect(UnitPrices.price(price, scale, unit_type, unit_value)).toEqual 16 + expect(UnitPrices.unit(scale, unit_type)).toEqual "lb" + + it "with price: 1 and scale/unit_value: 453.6 (LB)", -> + price = 1 + scale = 453.6 + unit_value = 453.6 + expect(UnitPrices.price(price, scale, unit_type, unit_value)).toEqual 1 + expect(UnitPrices.unit(scale, unit_type)).toEqual "lb" From 5ce558c2db649f07a8371d88da20584c395a6e18 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Bellet Date: Tue, 9 Mar 2021 16:47:49 +0100 Subject: [PATCH 025/534] Move value and unit into the same input disabled text field - Both value and unit of the unit price is now inside the `` text field. --- .../admin/products/controllers/units_controller.js.coffee | 8 ++++---- app/views/spree/admin/products/new.html.haml | 5 +---- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/app/assets/javascripts/admin/products/controllers/units_controller.js.coffee b/app/assets/javascripts/admin/products/controllers/units_controller.js.coffee index b3bbacc09b..fb42028d60 100644 --- a/app/assets/javascripts/admin/products/controllers/units_controller.js.coffee +++ b/app/assets/javascripts/admin/products/controllers/units_controller.js.coffee @@ -39,11 +39,11 @@ angular.module("admin.products") unit_type = $scope.product.variant_unit unit_value = $scope.product.master.unit_value variant_unit_name = $scope.product.variant_unit_name - $scope.product.unit_price_value = null - $scope.product.unit_price_unit = null + $scope.unit_price = null if price && unit_type && unit_value - $scope.product.unit_price_value = localizeCurrencyFilter(UnitPrices.price(price, scale, unit_type, unit_value, variant_unit_name)) - $scope.product.unit_price_unit = UnitPrices.unit(scale, unit_type, variant_unit_name) + value = localizeCurrencyFilter(UnitPrices.price(price, scale, unit_type, unit_value, variant_unit_name)) + unit = UnitPrices.unit(scale, unit_type, variant_unit_name) + $scope.unit_price = value + " / " + unit $scope.hasVariants = (product) -> Object.keys(product.variants).length > 0 diff --git a/app/views/spree/admin/products/new.html.haml b/app/views/spree/admin/products/new.html.haml index a5ce8ab67e..757abf650e 100644 --- a/app/views/spree/admin/products/new.html.haml +++ b/app/views/spree/admin/products/new.html.haml @@ -62,10 +62,7 @@ "question-mark-with-tooltip-animation" => true, key: "'js.shopfront.unit_price_tooltip.admin'"} %br/ - = f.text_field :price, {"class" => '', "disabled" => true, "ng-model" => "product.unit_price_value"} - %span{ style: "color: #757575", "ng-show": "product.unit_price_unit !== null" } -  /  - %span{ "ng-bind" => "product.unit_price_unit" } + = f.text_field :price, {"class" => 'fullwidth', "disabled" => true, "ng-model" => "unit_price"} %div{style: "color: black"} = t(".unit_price_legend") .sixteen.columns.alpha From 945ed5fb7805587821edcf98a3287a097baff1e0 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Bellet Date: Tue, 9 Mar 2021 16:49:23 +0100 Subject: [PATCH 026/534] Avoid NaN on unit price computing --- .../admin/products/controllers/units_controller.js.coffee | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/assets/javascripts/admin/products/controllers/units_controller.js.coffee b/app/assets/javascripts/admin/products/controllers/units_controller.js.coffee index fb42028d60..cc1f4cc669 100644 --- a/app/assets/javascripts/admin/products/controllers/units_controller.js.coffee +++ b/app/assets/javascripts/admin/products/controllers/units_controller.js.coffee @@ -40,7 +40,7 @@ angular.module("admin.products") unit_value = $scope.product.master.unit_value variant_unit_name = $scope.product.variant_unit_name $scope.unit_price = null - if price && unit_type && unit_value + if price && !isNaN(price) && unit_type && unit_value value = localizeCurrencyFilter(UnitPrices.price(price, scale, unit_type, unit_value, variant_unit_name)) unit = UnitPrices.unit(scale, unit_type, variant_unit_name) $scope.unit_price = value + " / " + unit From e137eb724b24ed7a5ff84e81fc31b4b562642ade Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Bellet Date: Tue, 9 Mar 2021 17:01:41 +0100 Subject: [PATCH 027/534] Readjust height of the question mark icon - 15px is actually the height of an `