-
-
Notifications
You must be signed in to change notification settings - Fork 730
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4345 from Matt-Yorkley/shopfront_pagination
Shopfront pagination
- Loading branch information
Showing
91 changed files
with
980 additions
and
2,476 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
86 changes: 55 additions & 31 deletions
86
app/assets/javascripts/darkswarm/controllers/products_controller.js.coffee
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
app/assets/javascripts/darkswarm/services/order_cycle_resource.js.coffee
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
Darkswarm.factory 'OrderCycleResource', ($resource) -> | ||
$resource('/api/order_cycles/:id', {}, { | ||
'products': | ||
method: 'GET' | ||
isArray: true | ||
url: '/api/order_cycles/:id/products' | ||
params: | ||
id: '@id' | ||
'taxons': | ||
method: 'GET' | ||
isArray: true | ||
url: '/api/order_cycles/:id/taxons' | ||
params: | ||
id: '@id' | ||
'properties': | ||
method: 'GET' | ||
isArray: true | ||
url: '/api/order_cycles/:id/properties' | ||
params: | ||
id: '@id' | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
module Api | ||
class OrderCyclesController < BaseController | ||
include EnterprisesHelper | ||
respond_to :json | ||
|
||
skip_authorization_check | ||
|
||
def products | ||
products = ProductsRenderer.new( | ||
distributor, | ||
order_cycle, | ||
customer, | ||
search_params | ||
).products_json | ||
|
||
render json: products | ||
rescue ProductsRenderer::NoProducts | ||
render status: :not_found, json: '' | ||
end | ||
|
||
def taxons | ||
taxons = Spree::Taxon. | ||
joins(:products). | ||
where(spree_products: { id: distributed_products }). | ||
select('DISTINCT spree_taxons.*') | ||
|
||
render json: ActiveModel::ArraySerializer.new(taxons, each_serializer: Api::TaxonSerializer) | ||
end | ||
|
||
def properties | ||
render json: ActiveModel::ArraySerializer.new( | ||
product_properties | producer_properties, each_serializer: Api::PropertySerializer | ||
) | ||
end | ||
|
||
private | ||
|
||
def product_properties | ||
Spree::Property. | ||
joins(:products). | ||
where(spree_products: { id: distributed_products }). | ||
select('DISTINCT spree_properties.*') | ||
end | ||
|
||
def producer_properties | ||
producers = Enterprise. | ||
joins(:supplied_products). | ||
where(spree_products: { id: distributed_products }) | ||
|
||
Spree::Property. | ||
joins(:producer_properties). | ||
where(producer_properties: { producer_id: producers }). | ||
select('DISTINCT spree_properties.*') | ||
end | ||
|
||
def search_params | ||
permitted_search_params = params.slice :q, :page, :per_page | ||
|
||
if permitted_search_params.key? :q | ||
permitted_search_params[:q].slice!(*permitted_ransack_params) | ||
end | ||
|
||
permitted_search_params | ||
end | ||
|
||
def permitted_ransack_params | ||
[:name_or_meta_keywords_or_supplier_name_cont, | ||
:properties_id_or_supplier_properties_id_in_any, | ||
:primary_taxon_id_in_any] | ||
end | ||
|
||
def distributor | ||
Enterprise.find_by_id(params[:distributor]) | ||
end | ||
|
||
def order_cycle | ||
OrderCycle.find_by_id(params[:id]) | ||
end | ||
|
||
def customer | ||
@current_api_user.andand.customer_of(distributor) || nil | ||
end | ||
|
||
def distributed_products | ||
OrderCycleDistributedProducts.new(distributor, order_cycle, customer).products_relation | ||
end | ||
end | ||
end |
Oops, something went wrong.