mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-16 04:24:23 +00:00
Merge branch 'master' into 2-0-stable-nov-8th
This commit is contained in:
@@ -90,7 +90,7 @@ module Admin
|
||||
{
|
||||
filepath: @filepath,
|
||||
item_count: @importer.item_count,
|
||||
supplier_product_counts: @importer.supplier_products,
|
||||
enterprise_product_counts: @importer.enterprise_products,
|
||||
import_url: main_app.admin_product_import_process_async_path,
|
||||
save_url: main_app.admin_product_import_save_async_path,
|
||||
reset_url: main_app.admin_product_import_reset_async_path,
|
||||
|
||||
23
app/controllers/api/orders_controller.rb
Normal file
23
app/controllers/api/orders_controller.rb
Normal file
@@ -0,0 +1,23 @@
|
||||
module Api
|
||||
class OrdersController < BaseController
|
||||
def index
|
||||
authorize! :admin, Spree::Order
|
||||
|
||||
search_results = SearchOrders.new(params, spree_current_user)
|
||||
|
||||
render json: {
|
||||
orders: serialized_orders(search_results.orders),
|
||||
pagination: search_results.pagination_data
|
||||
}
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def serialized_orders(orders)
|
||||
ActiveModel::ArraySerializer.new(
|
||||
orders,
|
||||
each_serializer: Api::Admin::OrderSerializer
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -20,51 +20,11 @@ Spree::Admin::OrdersController.class_eval do
|
||||
|
||||
before_filter :require_distributor_abn, only: :invoice
|
||||
|
||||
|
||||
respond_to :html, :json
|
||||
|
||||
# Mostly the original Spree method, tweaked to allow us to ransack with completed_at in a sane way
|
||||
def index
|
||||
params[:q] ||= {}
|
||||
params[:q][:completed_at_not_null] ||= '1' if Spree::Config[:show_only_complete_orders_by_default]
|
||||
@show_only_completed = params[:q][:completed_at_not_null].present?
|
||||
params[:q][:s] ||= @show_only_completed ? 'completed_at desc' : 'created_at desc'
|
||||
|
||||
# As date params are deleted if @show_only_completed, store
|
||||
# the original date so we can restore them into the params
|
||||
# after the search
|
||||
created_at_gt = params[:q][:created_at_gt]
|
||||
created_at_lt = params[:q][:created_at_lt]
|
||||
|
||||
if !params[:q][:created_at_gt].blank?
|
||||
params[:q][:created_at_gt] = Time.zone.parse(params[:q][:created_at_gt]).beginning_of_day rescue ""
|
||||
end
|
||||
|
||||
if !params[:q][:created_at_lt].blank?
|
||||
params[:q][:created_at_lt] = Time.zone.parse(params[:q][:created_at_lt]).end_of_day rescue ""
|
||||
end
|
||||
|
||||
# Changed this to stop completed_at being overriden when present
|
||||
if @show_only_completed
|
||||
params[:q][:completed_at_gt] = params[:q].delete(:created_at_gt) unless params[:q][:completed_at_gt]
|
||||
params[:q][:completed_at_lt] = params[:q].delete(:created_at_lt) unless params[:q][:completed_at_gt]
|
||||
end
|
||||
|
||||
@orders = orders
|
||||
|
||||
# Restore dates
|
||||
params[:q][:created_at_gt] = created_at_gt
|
||||
params[:q][:created_at_lt] = created_at_lt
|
||||
|
||||
respond_with(@orders) do |format|
|
||||
format.html
|
||||
format.json do
|
||||
render json: {
|
||||
orders: ActiveModel::ArraySerializer.new(@orders, each_serializer: Api::Admin::OrderSerializer),
|
||||
pagination: pagination_data
|
||||
}
|
||||
end
|
||||
end
|
||||
# Overriding the action so we only render the page template. An angular request
|
||||
# within the page then fetches the data it needs from Api::OrdersController
|
||||
end
|
||||
|
||||
# Overwrite to use confirm_email_for_customer instead of confirm_email.
|
||||
@@ -100,42 +60,6 @@ Spree::Admin::OrdersController.class_eval do
|
||||
|
||||
private
|
||||
|
||||
def orders
|
||||
if json_request?
|
||||
@search = OpenFoodNetwork::Permissions.new(spree_current_user).editable_orders.ransack(params[:q])
|
||||
else
|
||||
@search = Spree::Order.accessible_by(current_ability, :index).ransack(params[:q])
|
||||
|
||||
# Replaced this search to filter orders to only show those distributed by current user (or all for admin user)
|
||||
@search.result.includes([:user, :shipments, :payments]).distributed_by_user(spree_current_user)
|
||||
end
|
||||
|
||||
search_results
|
||||
end
|
||||
|
||||
def search_results
|
||||
if using_pagination?
|
||||
@search.result.page(params[:page]).per(params[:per_page] || Spree::Config[:orders_per_page])
|
||||
else
|
||||
@search.result
|
||||
end
|
||||
end
|
||||
|
||||
def using_pagination?
|
||||
params[:per_page]
|
||||
end
|
||||
|
||||
def pagination_data
|
||||
if using_pagination?
|
||||
{
|
||||
results: @orders.total_count,
|
||||
pages: @orders.num_pages,
|
||||
page: params[:page].to_i,
|
||||
per_page: params[:per_page].to_i
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
def require_distributor_abn
|
||||
unless @order.distributor.abn.present?
|
||||
flash[:error] = t(:must_have_valid_business_number, enterprise_name: @order.distributor.name)
|
||||
@@ -163,5 +87,4 @@ Spree::Admin::OrdersController.class_eval do
|
||||
render 'set_distribution', locals: { order: @order }
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -76,7 +76,11 @@ Spree::Api::ProductsController.class_eval do
|
||||
end
|
||||
|
||||
def render_paged_products(products)
|
||||
render text: { products: ActiveModel::ArraySerializer.new(products, each_serializer: Api::Admin::ProductSerializer), pages: products.num_pages }.to_json
|
||||
end
|
||||
serializer = ActiveModel::ArraySerializer.new(
|
||||
products,
|
||||
each_serializer: Api::Admin::ProductSerializer
|
||||
)
|
||||
|
||||
render text: { products: serializer, pages: products.num_pages }.to_json
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
class Spree::StoreController
|
||||
layout 'darkswarm'
|
||||
|
||||
include I18nHelper
|
||||
before_filter :set_locale
|
||||
|
||||
def unauthorized
|
||||
render 'shared/unauthorized', :status => 401
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user