diff --git a/.rubocop_manual_todo.yml b/.rubocop_manual_todo.yml index 6d4a4719e3..9826867220 100644 --- a/.rubocop_manual_todo.yml +++ b/.rubocop_manual_todo.yml @@ -123,7 +123,6 @@ Metrics/LineLength: - app/serializers/api/admin/subscription_serializer.rb - app/serializers/api/admin/tag_rule_serializer.rb - app/serializers/api/admin/variant_override_serializer.rb - - app/serializers/api/admin/variant_serializer.rb - app/services/cart_service.rb - app/services/default_stock_location.rb - app/services/embedded_page_service.rb diff --git a/app/serializers/api/admin/variant_serializer.rb b/app/serializers/api/admin/variant_serializer.rb index ad08a3edd6..479780064f 100644 --- a/app/serializers/api/admin/variant_serializer.rb +++ b/app/serializers/api/admin/variant_serializer.rb @@ -1,6 +1,9 @@ class Api::Admin::VariantSerializer < ActiveModel::Serializer - attributes :id, :options_text, :unit_value, :unit_description, :unit_to_display, :on_demand, :display_as, :display_name, :name_to_display, :sku - attributes :on_hand, :price, :import_date, :name, :producer_name, :image + attributes :id, :name, :producer_name, :image, :sku, :import_date + attributes :options_text, :unit_value, :unit_description, :unit_to_display + attributes :display_as, :display_name, :name_to_display + attributes :price, :on_demand, :on_hand, :in_stock, :stock_location_id, :stock_location_name + has_many :variant_overrides def name @@ -17,7 +20,7 @@ class Api::Admin::VariantSerializer < ActiveModel::Serializer end def price - # Decimals are passed to json as strings, we need to run parseFloat.toFixed(2) on the client side. + # Decimals are passed to json as strings, we need to run parseFloat.toFixed(2) on the client. object.price.nil? ? 0.to_f : object.price end @@ -26,6 +29,21 @@ class Api::Admin::VariantSerializer < ActiveModel::Serializer end def image + return if object.product.images.empty? object.product.images.first.mini_url end + + def in_stock + object.in_stock? + end + + def stock_location_id + return if object.stock_items.empty? + object.stock_items.first.stock_location.id + end + + def stock_location_name + return if object.stock_items.empty? + object.stock_items.first.stock_location.name + end end diff --git a/app/views/spree/admin/variants/_autocomplete.js.erb b/app/views/spree/admin/variants/_autocomplete.js.erb index 3e712673a1..527b55568c 100644 --- a/app/views/spree/admin/variants/_autocomplete.js.erb +++ b/app/views/spree/admin/variants/_autocomplete.js.erb @@ -16,7 +16,11 @@ @@ -38,7 +42,7 @@ - {{#if variant.[in_stock?]}} + {{#if variant.in_stock}} {{#if variant.on_demand}} <%= Spree.t(:on_demand) %> {{else}}