workarea-api-storefront 4.4.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +12 -0
- data/README.md +58 -0
- data/Rakefile +10 -0
- data/app/controllers/workarea/api/storefront/accounts_controller.rb +31 -0
- data/app/controllers/workarea/api/storefront/analytics_controller.rb +41 -0
- data/app/controllers/workarea/api/storefront/application_controller.rb +65 -0
- data/app/controllers/workarea/api/storefront/assets_controller.rb +11 -0
- data/app/controllers/workarea/api/storefront/authentication.rb +30 -0
- data/app/controllers/workarea/api/storefront/authentication_tokens_controller.rb +50 -0
- data/app/controllers/workarea/api/storefront/cart_items_controller.rb +100 -0
- data/app/controllers/workarea/api/storefront/carts_controller.rb +47 -0
- data/app/controllers/workarea/api/storefront/categories_controller.rb +25 -0
- data/app/controllers/workarea/api/storefront/checkouts_controller.rb +117 -0
- data/app/controllers/workarea/api/storefront/contacts_controller.rb +20 -0
- data/app/controllers/workarea/api/storefront/current_checkout.rb +60 -0
- data/app/controllers/workarea/api/storefront/email_signups_controller.rb +15 -0
- data/app/controllers/workarea/api/storefront/menus_controller.rb +19 -0
- data/app/controllers/workarea/api/storefront/orders_controller.rb +32 -0
- data/app/controllers/workarea/api/storefront/pages_controller.rb +14 -0
- data/app/controllers/workarea/api/storefront/password_resets_controller.rb +17 -0
- data/app/controllers/workarea/api/storefront/products_controller.rb +17 -0
- data/app/controllers/workarea/api/storefront/recent_views_controller.rb +46 -0
- data/app/controllers/workarea/api/storefront/recommendations_controller.rb +22 -0
- data/app/controllers/workarea/api/storefront/saved_addresses_controller.rb +38 -0
- data/app/controllers/workarea/api/storefront/saved_credit_cards_controller.rb +54 -0
- data/app/controllers/workarea/api/storefront/searches_controller.rb +29 -0
- data/app/controllers/workarea/api/storefront/system_content_controller.rb +16 -0
- data/app/controllers/workarea/api/storefront/taxons_controller.rb +20 -0
- data/app/controllers/workarea/api/storefront/user_activity.rb +36 -0
- data/app/controllers/workarea/storefront/application_controller.decorator +12 -0
- data/app/helpers/workarea/api/storefront/application_helper.rb +15 -0
- data/app/helpers/workarea/api/storefront/checkouts_helper.rb +11 -0
- data/app/helpers/workarea/api/storefront/content_blocks_helper.rb +38 -0
- data/app/models/workarea/catalog/category.decorator +7 -0
- data/app/models/workarea/user/authentication_token.rb +33 -0
- data/app/models/workarea/user.decorator +8 -0
- data/app/view_models/workarea/api/storefront/search_suggestion_view_model.rb +21 -0
- data/app/views/workarea/api/storefront/accounts/_account.json.jbuilder +7 -0
- data/app/views/workarea/api/storefront/accounts/create.json.jbuilder +7 -0
- data/app/views/workarea/api/storefront/accounts/show.json.jbuilder +1 -0
- data/app/views/workarea/api/storefront/assets/show.json.jbuilder +4 -0
- data/app/views/workarea/api/storefront/authentication_tokens/_authentication_token.json.jbuilder +2 -0
- data/app/views/workarea/api/storefront/authentication_tokens/create.json.jbuilder +1 -0
- data/app/views/workarea/api/storefront/authentication_tokens/update.json.jbuilder +1 -0
- data/app/views/workarea/api/storefront/cart_items/item.json.jbuilder +9 -0
- data/app/views/workarea/api/storefront/carts/index.json.jbuilder +4 -0
- data/app/views/workarea/api/storefront/carts/show.json.jbuilder +1 -0
- data/app/views/workarea/api/storefront/categories/_category.json.jbuilder +4 -0
- data/app/views/workarea/api/storefront/categories/index.json.jbuilder +3 -0
- data/app/views/workarea/api/storefront/categories/show.json.jbuilder +30 -0
- data/app/views/workarea/api/storefront/checkouts/_shipping_options.json.jbuilder +4 -0
- data/app/views/workarea/api/storefront/checkouts/show.json.jbuilder +17 -0
- data/app/views/workarea/api/storefront/checkouts/steps/_addresses.json.jbuilder +19 -0
- data/app/views/workarea/api/storefront/checkouts/steps/_payment.json.jbuilder +9 -0
- data/app/views/workarea/api/storefront/checkouts/steps/_shipping.json.jbuilder +9 -0
- data/app/views/workarea/api/storefront/content_blocks/_block.json.jbuilder +7 -0
- data/app/views/workarea/api/storefront/email_signups/create.json.jbuilder +2 -0
- data/app/views/workarea/api/storefront/email_signups/show.json.jbuilder +4 -0
- data/app/views/workarea/api/storefront/facets/_range.json.jbuilder +8 -0
- data/app/views/workarea/api/storefront/facets/_terms.json.jbuilder +8 -0
- data/app/views/workarea/api/storefront/fulfillments/_fulfillment.json.jbuilder +18 -0
- data/app/views/workarea/api/storefront/menus/_menu.json.jbuilder +11 -0
- data/app/views/workarea/api/storefront/menus/index.json.jbuilder +3 -0
- data/app/views/workarea/api/storefront/menus/show.json.jbuilder +1 -0
- data/app/views/workarea/api/storefront/orders/_item.json.jbuilder +26 -0
- data/app/views/workarea/api/storefront/orders/_order.json.jbuilder +42 -0
- data/app/views/workarea/api/storefront/orders/index.json.jbuilder +4 -0
- data/app/views/workarea/api/storefront/orders/show.json.jbuilder +7 -0
- data/app/views/workarea/api/storefront/orders/tenders/_credit_card.json.jbuilder +6 -0
- data/app/views/workarea/api/storefront/orders/tenders/_store_credit.json.jbuilder +2 -0
- data/app/views/workarea/api/storefront/pages/show.json.jbuilder +16 -0
- data/app/views/workarea/api/storefront/products/_image_urls.json.jbuilder +5 -0
- data/app/views/workarea/api/storefront/products/_product.json.jbuilder +41 -0
- data/app/views/workarea/api/storefront/products/show.json.jbuilder +9 -0
- data/app/views/workarea/api/storefront/recent_views/show.json.jbuilder +8 -0
- data/app/views/workarea/api/storefront/recommendations/show.json.jbuilder +3 -0
- data/app/views/workarea/api/storefront/saved_addresses/_saved_address.json.jbuilder +2 -0
- data/app/views/workarea/api/storefront/saved_addresses/index.json.jbuilder +4 -0
- data/app/views/workarea/api/storefront/saved_addresses/show.json.jbuilder +2 -0
- data/app/views/workarea/api/storefront/saved_credit_cards/_card.json.jbuilder +9 -0
- data/app/views/workarea/api/storefront/saved_credit_cards/index.json.jbuilder +4 -0
- data/app/views/workarea/api/storefront/saved_credit_cards/show.json.jbuilder +2 -0
- data/app/views/workarea/api/storefront/searches/index.json.jbuilder +1 -0
- data/app/views/workarea/api/storefront/searches/show.json.jbuilder +19 -0
- data/app/views/workarea/api/storefront/shared/_address.json.jbuilder +12 -0
- data/app/views/workarea/api/storefront/shared/_pagination.json.jbuilder +11 -0
- data/app/views/workarea/api/storefront/system_content/show.json.jbuilder +12 -0
- data/app/views/workarea/api/storefront/taxons/_taxon.json.jbuilder +10 -0
- data/app/views/workarea/api/storefront/taxons/show.json.jbuilder +7 -0
- data/app/workers/workarea/remove_authentication_tokens_on_password_changes.rb +19 -0
- data/bin/rails +18 -0
- data/config/initializers/config.rb +2 -0
- data/config/locales/en.yml +13 -0
- data/config/routes.rb +41 -0
- data/lib/workarea/api/storefront/engine.rb +10 -0
- data/lib/workarea/api/storefront.rb +15 -0
- data/test/documentation/workarea/api/storefront/accounts_documentation_test.rb +70 -0
- data/test/documentation/workarea/api/storefront/analytics_documentation_test.rb +51 -0
- data/test/documentation/workarea/api/storefront/assets_documentation_test.rb +32 -0
- data/test/documentation/workarea/api/storefront/authentication_documentation_test.rb +84 -0
- data/test/documentation/workarea/api/storefront/cart_items_documentation_test.rb +104 -0
- data/test/documentation/workarea/api/storefront/carts_documentation_test.rb +121 -0
- data/test/documentation/workarea/api/storefront/categories_documentation_test.rb +90 -0
- data/test/documentation/workarea/api/storefront/checkouts_documentation_test.rb +142 -0
- data/test/documentation/workarea/api/storefront/contacts_documentation_test.rb +39 -0
- data/test/documentation/workarea/api/storefront/email_signups_documentation_test.rb +53 -0
- data/test/documentation/workarea/api/storefront/menus_documentation_test.rb +67 -0
- data/test/documentation/workarea/api/storefront/orders_documentation_test.rb +127 -0
- data/test/documentation/workarea/api/storefront/pages_documentation_test.rb +66 -0
- data/test/documentation/workarea/api/storefront/password_resets_documentation_test.rb +30 -0
- data/test/documentation/workarea/api/storefront/products_documentation_test.rb +64 -0
- data/test/documentation/workarea/api/storefront/recent_views_documentation_test.rb +116 -0
- data/test/documentation/workarea/api/storefront/recommendations_documentation_test.rb +68 -0
- data/test/documentation/workarea/api/storefront/saved_addresses_documentation_test.rb +129 -0
- data/test/documentation/workarea/api/storefront/saved_credit_cards_documentation_test.rb +129 -0
- data/test/documentation/workarea/api/storefront/searches_documentation_test.rb +88 -0
- data/test/documentation/workarea/api/storefront/system_content_documentation_test.rb +66 -0
- data/test/documentation/workarea/api/storefront/taxons_documentation_test.rb +37 -0
- data/test/documentation/workarea/api/storefront/validation_documentation_test.rb +81 -0
- data/test/dummy/Rakefile +7 -0
- data/test/dummy/app/assets/config/manifest.js +4 -0
- data/test/dummy/app/assets/images/.keep +0 -0
- data/test/dummy/app/assets/javascripts/application.js +13 -0
- data/test/dummy/app/assets/stylesheets/application.css +15 -0
- data/test/dummy/app/controllers/application_controller.rb +3 -0
- data/test/dummy/app/controllers/concerns/.keep +0 -0
- data/test/dummy/app/helpers/application_helper.rb +2 -0
- data/test/dummy/app/jobs/application_job.rb +2 -0
- data/test/dummy/app/mailers/.keep +0 -0
- data/test/dummy/app/mailers/application_mailer.rb +4 -0
- data/test/dummy/app/models/.keep +0 -0
- data/test/dummy/app/models/concerns/.keep +0 -0
- data/test/dummy/app/views/layouts/application.html.erb +14 -0
- data/test/dummy/app/views/layouts/mailer.html.erb +13 -0
- data/test/dummy/app/views/layouts/mailer.text.erb +1 -0
- data/test/dummy/bin/bundle +3 -0
- data/test/dummy/bin/rails +4 -0
- data/test/dummy/bin/rake +4 -0
- data/test/dummy/bin/setup +34 -0
- data/test/dummy/bin/update +29 -0
- data/test/dummy/config/application.rb +25 -0
- data/test/dummy/config/boot.rb +5 -0
- data/test/dummy/config/cable.yml +9 -0
- data/test/dummy/config/environment.rb +5 -0
- data/test/dummy/config/environments/development.rb +55 -0
- data/test/dummy/config/environments/production.rb +86 -0
- data/test/dummy/config/environments/test.rb +43 -0
- data/test/dummy/config/initializers/application_controller_renderer.rb +6 -0
- data/test/dummy/config/initializers/assets.rb +11 -0
- data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/test/dummy/config/initializers/cookies_serializer.rb +5 -0
- data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
- data/test/dummy/config/initializers/inflections.rb +16 -0
- data/test/dummy/config/initializers/mime_types.rb +4 -0
- data/test/dummy/config/initializers/new_framework_defaults.rb +21 -0
- data/test/dummy/config/initializers/session_store.rb +3 -0
- data/test/dummy/config/initializers/workarea.rb +8 -0
- data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/test/dummy/config/locales/en.yml +23 -0
- data/test/dummy/config/puma.rb +47 -0
- data/test/dummy/config/routes.rb +6 -0
- data/test/dummy/config/secrets.yml +22 -0
- data/test/dummy/config/spring.rb +6 -0
- data/test/dummy/config.ru +4 -0
- data/test/dummy/db/seeds.rb +2 -0
- data/test/dummy/log/.keep +0 -0
- data/test/dummy/public/404.html +67 -0
- data/test/dummy/public/422.html +67 -0
- data/test/dummy/public/500.html +66 -0
- data/test/dummy/public/apple-touch-icon-precomposed.png +0 -0
- data/test/dummy/public/apple-touch-icon.png +0 -0
- data/test/dummy/public/favicon.ico +1 -0
- data/test/integration/workarea/api/storefront/accounts_integration_test.rb +49 -0
- data/test/integration/workarea/api/storefront/analytics_integration_test.rb +36 -0
- data/test/integration/workarea/api/storefront/assets_integration_test.rb +24 -0
- data/test/integration/workarea/api/storefront/authentication_integration_test.rb +50 -0
- data/test/integration/workarea/api/storefront/authentication_tokens_integration_test.rb +87 -0
- data/test/integration/workarea/api/storefront/cart_items_integration_test.rb +149 -0
- data/test/integration/workarea/api/storefront/carts_integration_test.rb +114 -0
- data/test/integration/workarea/api/storefront/categories_integration_test.rb +84 -0
- data/test/integration/workarea/api/storefront/checkouts_integration_test.rb +203 -0
- data/test/integration/workarea/api/storefront/contacts_integration_test.rb +28 -0
- data/test/integration/workarea/api/storefront/email_signups_integration_test.rb +35 -0
- data/test/integration/workarea/api/storefront/menus_integration_test.rb +53 -0
- data/test/integration/workarea/api/storefront/orders_integration_test.rb +115 -0
- data/test/integration/workarea/api/storefront/pages_integration_test.rb +57 -0
- data/test/integration/workarea/api/storefront/password_resets_integration_test.rb +20 -0
- data/test/integration/workarea/api/storefront/products_integration_test.rb +50 -0
- data/test/integration/workarea/api/storefront/recent_views_integration_test.rb +118 -0
- data/test/integration/workarea/api/storefront/recommendations_integration_test.rb +51 -0
- data/test/integration/workarea/api/storefront/saved_addresses_integration_test.rb +100 -0
- data/test/integration/workarea/api/storefront/saved_credit_cards_integration_test.rb +107 -0
- data/test/integration/workarea/api/storefront/searches_integration_test.rb +128 -0
- data/test/integration/workarea/api/storefront/system_content_integration_test.rb +35 -0
- data/test/integration/workarea/api/storefront/taxons_integration_test.rb +44 -0
- data/test/integration/workarea/api/storefront/user_carts_integration_test.rb +55 -0
- data/test/models/workarea/user/authentication_token_test.rb +30 -0
- data/test/support/authentication_test.rb +25 -0
- data/test/support/orders_test.rb +18 -0
- data/test/test_helper.rb +10 -0
- data/workarea-api-storefront.gemspec +18 -0
- metadata +277 -0
@@ -0,0 +1,15 @@
|
|
1
|
+
module Workarea
|
2
|
+
module Api
|
3
|
+
module Storefront
|
4
|
+
class EmailSignupsController < Api::Storefront::ApplicationController
|
5
|
+
def show
|
6
|
+
@email_signup = Workarea::Storefront::EmailSignupsViewModel.new
|
7
|
+
end
|
8
|
+
|
9
|
+
def create
|
10
|
+
@signup = Workarea::Email::Signup.create!(email: params[:email])
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Workarea
|
2
|
+
module Api
|
3
|
+
module Storefront
|
4
|
+
class MenusController < Api::Storefront::ApplicationController
|
5
|
+
before_action :cache_page
|
6
|
+
|
7
|
+
def index
|
8
|
+
models = Navigation::Menu.all.select(&:active?)
|
9
|
+
@menus = Workarea::Storefront::MenuViewModel.wrap(models, params)
|
10
|
+
end
|
11
|
+
|
12
|
+
def show
|
13
|
+
model = Navigation::Menu.active.find(params[:id])
|
14
|
+
@menu = Workarea::Storefront::MenuViewModel.wrap(model, params)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module Workarea
|
2
|
+
module Api
|
3
|
+
module Storefront
|
4
|
+
class OrdersController < Api::Storefront::ApplicationController
|
5
|
+
def index
|
6
|
+
models = Order.recent(
|
7
|
+
current_user.id,
|
8
|
+
Workarea.config.storefront_user_order_display_count
|
9
|
+
)
|
10
|
+
statuses = Fulfillment.find_statuses(*models.map(&:id))
|
11
|
+
|
12
|
+
@orders = models.map do |order|
|
13
|
+
Workarea::Storefront::OrderViewModel.new(
|
14
|
+
order,
|
15
|
+
fulfillment_status: statuses[order.id]
|
16
|
+
)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def show
|
21
|
+
model = Order.find(params[:id])
|
22
|
+
|
23
|
+
if model.user_id != current_user.id.to_s
|
24
|
+
head :forbidden
|
25
|
+
else
|
26
|
+
@order = Workarea::Storefront::OrderViewModel.new(model)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module Workarea
|
2
|
+
module Api
|
3
|
+
module Storefront
|
4
|
+
class PagesController < Api::Storefront::ApplicationController
|
5
|
+
before_action :cache_page
|
6
|
+
|
7
|
+
def show
|
8
|
+
model = Content::Page.active.find_by(slug: params[:id])
|
9
|
+
@page = Workarea::Storefront::PageViewModel.new(model, view_model_options)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Workarea
|
2
|
+
module Api
|
3
|
+
module Storefront
|
4
|
+
class PasswordResetsController < Api::Storefront::ApplicationController
|
5
|
+
def create
|
6
|
+
password_reset = Workarea::User::PasswordReset.setup!(params[:email])
|
7
|
+
|
8
|
+
Workarea::Storefront::AccountMailer
|
9
|
+
.password_reset(password_reset.id.to_s)
|
10
|
+
.deliver_later
|
11
|
+
|
12
|
+
head :ok
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Workarea
|
2
|
+
module Api
|
3
|
+
module Storefront
|
4
|
+
class ProductsController < Api::Storefront::ApplicationController
|
5
|
+
before_action :cache_page
|
6
|
+
|
7
|
+
def show
|
8
|
+
model = Workarea::Catalog::Product.active.find_by(slug: params[:id])
|
9
|
+
@product = Workarea::Storefront::ProductViewModel.wrap(
|
10
|
+
model,
|
11
|
+
view_model_options
|
12
|
+
)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
module Workarea
|
2
|
+
module Api
|
3
|
+
module Storefront
|
4
|
+
class RecentViewsController < Api::Storefront::ApplicationController
|
5
|
+
before_action :assert_current_user_activity_id
|
6
|
+
|
7
|
+
def show
|
8
|
+
if stale?(
|
9
|
+
etag: user_activity,
|
10
|
+
last_modified: user_activity.updated_at,
|
11
|
+
public: true
|
12
|
+
)
|
13
|
+
@recent_views = Workarea::Storefront::UserActivityViewModel.new(
|
14
|
+
user_activity
|
15
|
+
)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def update
|
20
|
+
if params[:product_id].present?
|
21
|
+
Recommendation::UserActivity.save_product(
|
22
|
+
current_user_activity_id,
|
23
|
+
params[:product_id]
|
24
|
+
)
|
25
|
+
end
|
26
|
+
|
27
|
+
if params[:category_id].present?
|
28
|
+
Recommendation::UserActivity.save_category(
|
29
|
+
current_user_activity_id,
|
30
|
+
params[:category_id]
|
31
|
+
)
|
32
|
+
end
|
33
|
+
|
34
|
+
if params[:search].present?
|
35
|
+
Recommendation::UserActivity.save_search(
|
36
|
+
current_user_activity_id,
|
37
|
+
params[:search]
|
38
|
+
)
|
39
|
+
end
|
40
|
+
|
41
|
+
head :ok
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module Workarea
|
2
|
+
module Api
|
3
|
+
module Storefront
|
4
|
+
class RecommendationsController < Api::Storefront::ApplicationController
|
5
|
+
before_action :assert_current_user_activity_id
|
6
|
+
|
7
|
+
def show
|
8
|
+
fresh_when(
|
9
|
+
etag: user_activity,
|
10
|
+
last_modified: user_activity.updated_at,
|
11
|
+
public: true
|
12
|
+
)
|
13
|
+
|
14
|
+
@recommendations = Workarea::Storefront::PersonalizedRecommendationsViewModel.new(
|
15
|
+
user_activity,
|
16
|
+
view_model_options
|
17
|
+
)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module Workarea
|
2
|
+
module Api
|
3
|
+
module Storefront
|
4
|
+
class SavedAddressesController < Api::Storefront::ApplicationController
|
5
|
+
def index
|
6
|
+
@addresses = current_user.addresses
|
7
|
+
end
|
8
|
+
|
9
|
+
def show
|
10
|
+
@address = current_user.addresses.find(params[:id])
|
11
|
+
end
|
12
|
+
|
13
|
+
def create
|
14
|
+
@address = current_user.addresses.create!(address_params)
|
15
|
+
render :show
|
16
|
+
end
|
17
|
+
|
18
|
+
def update
|
19
|
+
@address = current_user.addresses.find(params[:id])
|
20
|
+
|
21
|
+
@address.update_attributes!(address_params)
|
22
|
+
render :show
|
23
|
+
end
|
24
|
+
|
25
|
+
def destroy
|
26
|
+
current_user.addresses.find(params[:id]).destroy
|
27
|
+
head :no_content
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def address_params
|
33
|
+
params.permit(*Workarea.config.address_attributes)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
module Workarea
|
2
|
+
module Api
|
3
|
+
module Storefront
|
4
|
+
class SavedCreditCardsController < Api::Storefront::ApplicationController
|
5
|
+
before_action :set_payment_profile
|
6
|
+
|
7
|
+
def index
|
8
|
+
@credit_cards = @payment_profile.credit_cards
|
9
|
+
end
|
10
|
+
|
11
|
+
def show
|
12
|
+
@credit_card = @payment_profile.credit_cards.find(params[:id])
|
13
|
+
end
|
14
|
+
|
15
|
+
def create
|
16
|
+
@credit_card = @payment_profile.credit_cards.create!(card_params)
|
17
|
+
render :show
|
18
|
+
end
|
19
|
+
|
20
|
+
def update
|
21
|
+
@credit_card = @payment_profile.credit_cards.find(params[:id])
|
22
|
+
|
23
|
+
@credit_card.update_attributes!(card_params)
|
24
|
+
render :show
|
25
|
+
end
|
26
|
+
|
27
|
+
def destroy
|
28
|
+
@payment_profile.credit_cards.find(params[:id]).destroy
|
29
|
+
head :no_content
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
def set_payment_profile
|
35
|
+
@payment_profile ||= Payment::Profile.lookup(
|
36
|
+
PaymentReference.new(current_user)
|
37
|
+
)
|
38
|
+
end
|
39
|
+
|
40
|
+
def card_params
|
41
|
+
params.permit(
|
42
|
+
:first_name,
|
43
|
+
:last_name,
|
44
|
+
:number,
|
45
|
+
:month,
|
46
|
+
:year,
|
47
|
+
:cvv,
|
48
|
+
:default
|
49
|
+
)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module Workarea
|
2
|
+
module Api
|
3
|
+
module Storefront
|
4
|
+
class SearchesController < Api::Storefront::ApplicationController
|
5
|
+
before_action :cache_page
|
6
|
+
|
7
|
+
def index
|
8
|
+
search_query = QueryString.new(params[:q]).sanitized
|
9
|
+
|
10
|
+
render(nothing: true) && (return) if search_query.blank?
|
11
|
+
autocomplete_params = params.permit(:q)
|
12
|
+
search = Search::SearchSuggestions.new(autocomplete_params)
|
13
|
+
|
14
|
+
@results = search.results.map do |result|
|
15
|
+
SearchSuggestionViewModel.new(result).to_h
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def show
|
20
|
+
response = Search::StorefrontSearch.new(params.to_unsafe_h).response
|
21
|
+
@search = Workarea::Storefront::SearchViewModel.new(
|
22
|
+
response,
|
23
|
+
view_model_options
|
24
|
+
)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module Workarea
|
2
|
+
module Api
|
3
|
+
module Storefront
|
4
|
+
class SystemContentController < Api::Storefront::ApplicationController
|
5
|
+
before_action :cache_page
|
6
|
+
|
7
|
+
def show
|
8
|
+
@content = Workarea::Storefront::ContentViewModel.new(
|
9
|
+
Content.for(params['id']),
|
10
|
+
view_model_options
|
11
|
+
)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Workarea
|
2
|
+
module Api
|
3
|
+
module Storefront
|
4
|
+
class TaxonsController < Api::Storefront::ApplicationController
|
5
|
+
before_action :cache_page
|
6
|
+
|
7
|
+
def show
|
8
|
+
@taxon = Navigation::Taxon.find(params[:id])
|
9
|
+
|
10
|
+
unless @taxon.active?
|
11
|
+
raise Mongoid::Errors::DocumentNotFound.new(
|
12
|
+
Navigation::Taxon,
|
13
|
+
id: params[:id]
|
14
|
+
)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module Workarea
|
2
|
+
module Api
|
3
|
+
module Storefront
|
4
|
+
module UserActivity
|
5
|
+
extend ActiveSupport::Concern
|
6
|
+
|
7
|
+
def user_activity
|
8
|
+
@user_activity ||= Recommendation::UserActivity.find_or_initialize_by(
|
9
|
+
id: current_user_activity_id
|
10
|
+
)
|
11
|
+
end
|
12
|
+
|
13
|
+
def current_user_activity_id
|
14
|
+
if authentication?
|
15
|
+
current_user.id
|
16
|
+
else
|
17
|
+
params[:session_id]
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def assert_current_user_activity_id
|
22
|
+
if current_user_activity_id.blank?
|
23
|
+
render(
|
24
|
+
json: {
|
25
|
+
problem: t('workarea.api.storefront.recent_views.missing_id')
|
26
|
+
},
|
27
|
+
status: :unprocessable_entity
|
28
|
+
)
|
29
|
+
|
30
|
+
return false
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
module Workarea
|
2
|
+
decorate Storefront::ApplicationController do
|
3
|
+
# Rendering content blocks in the context of Storefront for output
|
4
|
+
# in the api response requires current_user to look at signed cookies
|
5
|
+
# which don't exist. So return nil if a cookie salt is not there.
|
6
|
+
#
|
7
|
+
def current_user
|
8
|
+
return nil if request.signed_cookie_salt.nil?
|
9
|
+
super
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Workarea
|
2
|
+
module Api
|
3
|
+
module Storefront
|
4
|
+
module ApplicationHelper
|
5
|
+
def storefront_api_url_for(taxon)
|
6
|
+
if taxon.url?
|
7
|
+
taxon.url
|
8
|
+
elsif taxon.navigable?
|
9
|
+
send("#{taxon.resource_name}_url", taxon.navigable_slug)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module Workarea
|
2
|
+
module Api
|
3
|
+
module Storefront
|
4
|
+
module ContentBlocksHelper
|
5
|
+
def block_data_with_urls(block)
|
6
|
+
data = block.data.deep_dup
|
7
|
+
|
8
|
+
block.type.fields.inject(data) do |data, field|
|
9
|
+
value = block.data[field.slug.to_s]
|
10
|
+
|
11
|
+
if field.type == :asset && value.present?
|
12
|
+
asset =
|
13
|
+
begin
|
14
|
+
Content::Asset.find(value)
|
15
|
+
rescue
|
16
|
+
Content::Asset.placeholder
|
17
|
+
end
|
18
|
+
|
19
|
+
data["#{field.slug.to_s}_url"] = url_to_content_asset(asset)
|
20
|
+
end
|
21
|
+
|
22
|
+
data
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def render_block_to_string(block)
|
27
|
+
Workarea::Storefront::ApplicationController.render(
|
28
|
+
template: 'workarea/storefront/content_blocks/show',
|
29
|
+
layout: false,
|
30
|
+
assigns: {
|
31
|
+
block: Workarea::Storefront::ContentBlockViewModel.wrap(block)
|
32
|
+
}
|
33
|
+
)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module Workarea
|
2
|
+
class User
|
3
|
+
class AuthenticationToken
|
4
|
+
include ApplicationDocument
|
5
|
+
include UrlToken
|
6
|
+
|
7
|
+
field :expires_at, type: Time, default: -> { AuthenticationToken.expires_at }
|
8
|
+
|
9
|
+
belongs_to :user, class_name: 'Workarea::User', index: true
|
10
|
+
|
11
|
+
def self.expires_at
|
12
|
+
Time.now + Workarea.config.authentication_token_expiration
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.authenticate(token, options = {})
|
16
|
+
result = where(token: token).first
|
17
|
+
return if result.try(:expired?)
|
18
|
+
result
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.refresh!(token, options = {})
|
22
|
+
result = where(token: token).first
|
23
|
+
return if result.try(:expired?)
|
24
|
+
return unless result.update_attribute(:expires_at, expires_at)
|
25
|
+
result
|
26
|
+
end
|
27
|
+
|
28
|
+
def expired?
|
29
|
+
expires_at <= Time.now
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Workarea
|
2
|
+
module Api
|
3
|
+
module Storefront
|
4
|
+
class SearchSuggestionViewModel < Workarea::Storefront::SearchSuggestionViewModel
|
5
|
+
def url
|
6
|
+
helpers = Api::Storefront::Engine.routes.url_helpers
|
7
|
+
|
8
|
+
if suggestion_type == 'product'
|
9
|
+
helpers.product_path(product)
|
10
|
+
elsif suggestion_type == 'search'
|
11
|
+
helpers.search_path(q: name)
|
12
|
+
elsif suggestion_type == 'category'
|
13
|
+
helpers.category_path(source['slug'])
|
14
|
+
elsif suggestion_type == 'page'
|
15
|
+
helpers.page_path(source['slug'])
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
json.partial! 'workarea/api/storefront/accounts/account', user: current_user
|
@@ -0,0 +1 @@
|
|
1
|
+
json.partial! 'workarea/api/storefront/authentication_tokens/authentication_token', authentication_token: @authentication_token
|
@@ -0,0 +1 @@
|
|
1
|
+
json.partial! 'workarea/api/storefront/authentication_tokens/authentication_token', authentication_token: @authentication_token
|
@@ -0,0 +1 @@
|
|
1
|
+
json.partial! 'workarea/api/storefront/orders/order', order: @order
|
@@ -0,0 +1,30 @@
|
|
1
|
+
json.cache! @category.cache_key, expires_in: 1.hour do
|
2
|
+
json.id @category.id
|
3
|
+
json.name @category.name
|
4
|
+
json.slug @category.slug
|
5
|
+
json.url category_url(@category)
|
6
|
+
|
7
|
+
json.browser_title @category.browser_title
|
8
|
+
json.meta_description @category.meta_description
|
9
|
+
|
10
|
+
json.sorts @category.sorts
|
11
|
+
json.sort @category.sort
|
12
|
+
|
13
|
+
json.breadcrumbs @category.breadcrumbs do |taxon|
|
14
|
+
json.partial! 'workarea/api/storefront/taxons/taxon', taxon: taxon
|
15
|
+
end
|
16
|
+
|
17
|
+
json.content_blocks @category.content.blocks do |block|
|
18
|
+
json.partial! 'workarea/api/storefront/content_blocks/block', block: block
|
19
|
+
end
|
20
|
+
|
21
|
+
json.partial! 'workarea/api/storefront/shared/pagination', model: @category
|
22
|
+
|
23
|
+
json.facets @category.facets do |facet|
|
24
|
+
json.partial! "workarea/api/storefront/facets/#{facet.type}", facet: facet
|
25
|
+
end
|
26
|
+
|
27
|
+
json.products @category.products do |product|
|
28
|
+
json.partial! 'workarea/api/storefront/products/product', product: product
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
json.order do
|
2
|
+
json.partial! 'workarea/api/storefront/orders/order', order: @order
|
3
|
+
end
|
4
|
+
|
5
|
+
json.checkout do
|
6
|
+
json.url checkout_url(@cart.id)
|
7
|
+
json.started_at @cart.checkout_started_at
|
8
|
+
json.shippable @summary.shippable?
|
9
|
+
json.complete @summary.complete?
|
10
|
+
|
11
|
+
@summary.steps.each do |klass|
|
12
|
+
json.partial! "workarea/api/storefront/checkouts/steps/#{checkout_step_name(klass)}",
|
13
|
+
step: klass.new(@summary.model),
|
14
|
+
summary: @summary,
|
15
|
+
cart: @cart
|
16
|
+
end
|
17
|
+
end
|