diff --git a/api/app/controllers/spree/api/variants_controller.rb b/api/app/controllers/spree/api/variants_controller.rb index 83431f7f503..78b8d9a6eb4 100644 --- a/api/app/controllers/spree/api/variants_controller.rb +++ b/api/app/controllers/spree/api/variants_controller.rb @@ -23,7 +23,7 @@ def destroy # we render on the view so we better update it any time a node is included # or removed from the views. def index - @variants = scope.includes({ option_values: :option_type }, :product, :default_price, :images, { stock_items: :stock_location }) + @variants = scope.includes(include_list) .ransack(params[:q]).result @variants = paginate(@variants) @@ -34,7 +34,7 @@ def new end def show - @variant = scope.includes({ option_values: :option_type }, :option_values, :product, :default_price, :images, { stock_items: :stock_location }) + @variant = scope.includes(include_list) .find(params[:id]) respond_with(@variant) end @@ -74,6 +74,10 @@ def scope def variant_params params.require(:variant).permit(permitted_variant_attributes) end + + def include_list + [{ option_values: :option_type }, :product, :default_price, :images, { stock_items: :stock_location }] + end end end end