mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
Merge pull request #4430 from Matt-Yorkley/variant_option_types
Variant option_values
This commit is contained in:
@@ -4,9 +4,17 @@ module Admin
|
||||
#
|
||||
def index
|
||||
order_params = params[:q].andand.delete :order
|
||||
orders = OpenFoodNetwork::Permissions.new(spree_current_user).editable_orders.ransack(order_params).result
|
||||
line_items = OpenFoodNetwork::Permissions.new(spree_current_user).editable_line_items.where(order_id: orders).ransack(params[:q])
|
||||
render_as_json line_items.result.reorder('order_id ASC, id ASC')
|
||||
|
||||
orders = OpenFoodNetwork::Permissions.new(spree_current_user).
|
||||
editable_orders.ransack(order_params).result
|
||||
|
||||
line_items = OpenFoodNetwork::Permissions.new(spree_current_user).
|
||||
editable_line_items.where(order_id: orders).
|
||||
includes(variant: { option_values: :option_type }).
|
||||
ransack(params[:q]).result.
|
||||
reorder('spree_line_items.order_id ASC, spree_line_items.id ASC')
|
||||
|
||||
render_as_json line_items
|
||||
end
|
||||
|
||||
# PUT /admin/bulk_line_items/:id.json
|
||||
|
||||
@@ -148,7 +148,8 @@ module Admin
|
||||
|
||||
unless enterprises.empty?
|
||||
enterprises.includes(
|
||||
supplied_products: [:supplier, :variants, master: [:images]]
|
||||
supplied_products:
|
||||
[:supplier, master: [:images], variants: { option_values: :option_type }]
|
||||
)
|
||||
end
|
||||
when :index
|
||||
|
||||
@@ -115,7 +115,8 @@ module Api
|
||||
def product_query_includes
|
||||
[
|
||||
master: [:images],
|
||||
variants: [:default_price, :stock_locations, :stock_items, :variant_overrides]
|
||||
variants: [:default_price, :stock_locations, :stock_items, :variant_overrides,
|
||||
{ option_values: :option_type }]
|
||||
]
|
||||
end
|
||||
|
||||
|
||||
@@ -6,12 +6,12 @@ module Api
|
||||
before_filter :product
|
||||
|
||||
def index
|
||||
@variants = scope.includes(:option_values).ransack(params[:q]).result
|
||||
@variants = scope.includes(option_values: :option_type).ransack(params[:q]).result
|
||||
render json: @variants, each_serializer: Api::VariantSerializer
|
||||
end
|
||||
|
||||
def show
|
||||
@variant = scope.includes(:option_values).find(params[:id])
|
||||
@variant = scope.includes(option_values: :option_type).find(params[:id])
|
||||
render json: @variant, serializer: Api::VariantSerializer
|
||||
end
|
||||
|
||||
|
||||
@@ -35,6 +35,7 @@ class ProducerMailer < Spree::BaseMailer
|
||||
|
||||
def line_items_from(order_cycle, producer)
|
||||
Spree::LineItem.
|
||||
includes(variant: { option_values: :option_type }).
|
||||
from_order_cycle(order_cycle).
|
||||
sorted_by_name_and_unit_value.
|
||||
merge(Spree::Product.in_supplier(producer)).
|
||||
|
||||
@@ -51,8 +51,7 @@ module OpenFoodNetwork
|
||||
|
||||
def table_items
|
||||
return [] unless @render_table
|
||||
|
||||
Reports::LineItems.list(permissions, params)
|
||||
Reports::LineItems.list(permissions, report_options)
|
||||
end
|
||||
|
||||
def rules
|
||||
@@ -122,9 +121,17 @@ module OpenFoodNetwork
|
||||
|
||||
private
|
||||
|
||||
def report_options
|
||||
@params.merge(line_item_includes: line_item_includes)
|
||||
end
|
||||
|
||||
def line_item_includes
|
||||
[{ order: [:bill_address],
|
||||
variant: [{ option_values: :option_type }, { product: :supplier }] }]
|
||||
end
|
||||
|
||||
def permissions
|
||||
return @permissions unless @permissions.nil?
|
||||
|
||||
@permissions = OpenFoodNetwork::Permissions.new(@user)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -190,7 +190,7 @@ module OpenFoodNetwork
|
||||
# rubocop:enable Metrics/PerceivedComplexity
|
||||
|
||||
def line_item_includes
|
||||
[{ variant: { product: :supplier },
|
||||
[{ variant: [{ option_values: :option_type }, { product: :supplier }],
|
||||
order: [:bill_address, :ship_address, :order_cycle, :adjustments, :payments,
|
||||
:user, :distributor, shipments: { shipping_rates: :shipping_method }] }]
|
||||
end
|
||||
|
||||
@@ -69,7 +69,7 @@ module OpenFoodNetwork
|
||||
|
||||
def line_item_includes
|
||||
[{ order: [:distributor, :adjustments, shipments: { shipping_rates: :shipping_method }],
|
||||
variant: { product: :supplier } }]
|
||||
variant: [{ option_values: :option_type }, { product: :supplier }] }]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -69,7 +69,8 @@ module OpenFoodNetwork
|
||||
# rubocop:enable Metrics/AbcSize
|
||||
|
||||
def line_item_includes
|
||||
[{ order: :distributor, variant: { product: :supplier } }]
|
||||
[{ order: :distributor,
|
||||
variant: [{ option_values: :option_type }, { product: :supplier }] }]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -55,7 +55,7 @@ module OpenFoodNetwork
|
||||
# rubocop:enable Metrics/MethodLength
|
||||
|
||||
def line_item_includes
|
||||
[{ variant: { product: :supplier } }]
|
||||
[{ variant: [{ option_values: :option_type }, { product: :supplier }] }]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -43,8 +43,7 @@ module OpenFoodNetwork
|
||||
|
||||
def table_items
|
||||
return [] unless @render_table
|
||||
|
||||
Reports::LineItems.list(permissions, params)
|
||||
Reports::LineItems.list(permissions, report_options)
|
||||
end
|
||||
|
||||
def rules
|
||||
@@ -121,9 +120,17 @@ module OpenFoodNetwork
|
||||
|
||||
private
|
||||
|
||||
def report_options
|
||||
@params.merge(line_item_includes: line_item_includes)
|
||||
end
|
||||
|
||||
def line_item_includes
|
||||
[{ order: [:bill_address, :distributor],
|
||||
variant: [{ option_values: :option_type }, { product: :supplier }] }]
|
||||
end
|
||||
|
||||
def permissions
|
||||
return @permissions unless @permissions.nil?
|
||||
|
||||
@permissions = OpenFoodNetwork::Permissions.new(@user)
|
||||
end
|
||||
|
||||
|
||||
@@ -25,6 +25,7 @@ module OpenFoodNetwork
|
||||
def child_variants
|
||||
Spree::Variant.
|
||||
where(is_master: false).
|
||||
includes(option_values: :option_type).
|
||||
joins(:product).
|
||||
merge(visible_products).
|
||||
order('spree_products.name')
|
||||
|
||||
@@ -30,7 +30,9 @@ module OpenFoodNetwork
|
||||
end
|
||||
|
||||
def query_scope
|
||||
Spree::Variant.where(is_master: false).ransack(search_params.merge(m: 'or')).result
|
||||
Spree::Variant.where(is_master: false).
|
||||
includes(option_values: :option_type).
|
||||
ransack(search_params.merge(m: 'or')).result
|
||||
end
|
||||
|
||||
def distributor
|
||||
|
||||
@@ -8,11 +8,17 @@ module OpenFoodNetwork
|
||||
module VariantAndLineItemNaming
|
||||
# Copied and modified from Spree::Variant
|
||||
def options_text
|
||||
values = option_values.joins(:option_type).order("#{Spree::OptionType.table_name}.position asc")
|
||||
values = if option_values_eager_loaded?
|
||||
# Don't trigger N+1 queries if option_values are already eager-loaded.
|
||||
# For best results, use: `Spree::Variant.includes(option_values: :option_type)`
|
||||
# or: `Spree::Product.includes(variant: {option_values: :option_type})`
|
||||
option_values.sort_by{ |o| o.option_type.position }
|
||||
else
|
||||
option_values.joins(:option_type).
|
||||
order("#{Spree::OptionType.table_name}.position asc")
|
||||
end
|
||||
|
||||
values.map!(&:presentation) # This line changed
|
||||
|
||||
values.to_sentence(words_connector: ", ", two_words_connector: ", ")
|
||||
values.map(&:presentation).to_sentence(words_connector: ", ", two_words_connector: ", ")
|
||||
end
|
||||
|
||||
def product_and_full_name
|
||||
@@ -69,6 +75,10 @@ module OpenFoodNetwork
|
||||
|
||||
private
|
||||
|
||||
def option_values_eager_loaded?
|
||||
option_values.loaded?
|
||||
end
|
||||
|
||||
def option_value_name
|
||||
if has_attribute?(:display_as) && display_as.present?
|
||||
display_as
|
||||
|
||||
@@ -43,6 +43,15 @@ module OpenFoodNetwork
|
||||
|
||||
private
|
||||
|
||||
def report_options
|
||||
@opts.merge(line_item_includes: line_item_includes)
|
||||
end
|
||||
|
||||
def line_item_includes
|
||||
[:bill_address, :adjustments,
|
||||
line_items: { variant: [{ option_values: :option_type }, { product: :supplier }] }]
|
||||
end
|
||||
|
||||
def detail_rows_for_order(order, invoice_number, opts)
|
||||
rows = []
|
||||
|
||||
|
||||
Reference in New Issue
Block a user