workarea-wish_lists 3.0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (127) hide show
  1. checksums.yaml +7 -0
  2. data/.editorconfig +20 -0
  3. data/.eslintignore +2 -0
  4. data/.eslintrc +24 -0
  5. data/.github/ISSUE_TEMPLATE/bug_report.md +37 -0
  6. data/.github/ISSUE_TEMPLATE/documentation-request.md +17 -0
  7. data/.github/ISSUE_TEMPLATE/feature_request.md +20 -0
  8. data/.gitignore +15 -0
  9. data/.scss-lint.yml +188 -0
  10. data/.yardopts +1 -0
  11. data/CHANGELOG.md +610 -0
  12. data/CODE_OF_CONDUCT.md +3 -0
  13. data/CONTRIBUTING.md +3 -0
  14. data/Gemfile +6 -0
  15. data/LICENSE +52 -0
  16. data/README.md +58 -0
  17. data/Rakefile +53 -0
  18. data/app/assets/javascripts/workarea/storefront/wish_lists/modules/wish_list_button.js +35 -0
  19. data/app/assets/javascripts/workarea/storefront/wish_lists/modules/wish_list_public_quantity_fields.js +42 -0
  20. data/app/assets/javascripts/workarea/storefront/wish_lists/templates/hidden_input.jst.ejs +1 -0
  21. data/app/assets/stylesheets/workarea/storefront/wish_lists/components/_wish_list_button.scss +6 -0
  22. data/app/assets/stylesheets/workarea/storefront/wish_lists/components/_wish_lists.scss +24 -0
  23. data/app/controllers/workarea/admin/users_controller.decorator +20 -0
  24. data/app/controllers/workarea/storefront/users/wish_lists_controller.rb +128 -0
  25. data/app/controllers/workarea/storefront/wish_lists_controller.rb +22 -0
  26. data/app/models/workarea/wish_list.rb +212 -0
  27. data/app/models/workarea/wish_list/item.rb +76 -0
  28. data/app/models/workarea/wish_list/pricing.rb +14 -0
  29. data/app/models/workarea/wish_list/pricing/calculators/totals_calculator.rb +26 -0
  30. data/app/models/workarea/wish_list/public_search.rb +34 -0
  31. data/app/models/workarea/wish_list/request.rb +36 -0
  32. data/app/seeds/workarea/wish_list_seeds.rb +24 -0
  33. data/app/services/workarea/set_wish_list_details.rb +49 -0
  34. data/app/services/workarea/wish_list_session.rb +53 -0
  35. data/app/view_models/workarea/admin/user_view_model.decorator +12 -0
  36. data/app/view_models/workarea/storefront/user_view_model.decorator +31 -0
  37. data/app/view_models/workarea/storefront/wish_list_item_view_model.rb +35 -0
  38. data/app/view_models/workarea/storefront/wish_list_view_model.rb +75 -0
  39. data/app/views/layouts/workarea/storefront/_wish_lists_link.html.haml +6 -0
  40. data/app/views/workarea/admin/users/_wish_list_card.html.haml +24 -0
  41. data/app/views/workarea/admin/users/_wish_list_item_summary.html.haml +8 -0
  42. data/app/views/workarea/admin/users/wish_list.html.haml +26 -0
  43. data/app/views/workarea/storefront/carts/_move_to_wish_list.html.haml +4 -0
  44. data/app/views/workarea/storefront/products/_add_to_wish_list.html.haml +4 -0
  45. data/app/views/workarea/storefront/style_guides/_wish_lists_product_list_docs.html.haml +158 -0
  46. data/app/views/workarea/storefront/users/accounts/_wish_list_summary.html.haml +15 -0
  47. data/app/views/workarea/storefront/users/wish_lists/show.html.haml +125 -0
  48. data/app/views/workarea/storefront/wish_lists/_wish_lists_link.html.haml +4 -0
  49. data/app/views/workarea/storefront/wish_lists/index.html.haml +32 -0
  50. data/app/views/workarea/storefront/wish_lists/show.html.haml +97 -0
  51. data/app/workers/workarea/mark_wish_list_items_purchased.rb +18 -0
  52. data/app/workers/workarea/update_wish_list_details.rb +19 -0
  53. data/bin/rails +18 -0
  54. data/config/initializers/append_points.rb +46 -0
  55. data/config/initializers/configuration.rb +10 -0
  56. data/config/locales/en.yml +60 -0
  57. data/config/routes.rb +23 -0
  58. data/lib/workarea/testing/factories/wish_lists.rb +22 -0
  59. data/lib/workarea/wish_lists.rb +13 -0
  60. data/lib/workarea/wish_lists/engine.rb +15 -0
  61. data/lib/workarea/wish_lists/version.rb +5 -0
  62. data/test/dummy/Rakefile +6 -0
  63. data/test/dummy/app/assets/config/manifest.js +4 -0
  64. data/test/dummy/app/assets/images/.keep +0 -0
  65. data/test/dummy/app/assets/javascripts/application.js +13 -0
  66. data/test/dummy/app/assets/stylesheets/application.css +15 -0
  67. data/test/dummy/app/controllers/application_controller.rb +3 -0
  68. data/test/dummy/app/controllers/concerns/.keep +0 -0
  69. data/test/dummy/app/helpers/application_helper.rb +2 -0
  70. data/test/dummy/app/jobs/application_job.rb +2 -0
  71. data/test/dummy/app/mailers/application_mailer.rb +4 -0
  72. data/test/dummy/app/models/concerns/.keep +0 -0
  73. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  74. data/test/dummy/app/views/layouts/mailer.html.erb +13 -0
  75. data/test/dummy/app/views/layouts/mailer.text.erb +1 -0
  76. data/test/dummy/bin/bundle +3 -0
  77. data/test/dummy/bin/rails +4 -0
  78. data/test/dummy/bin/rake +4 -0
  79. data/test/dummy/bin/setup +34 -0
  80. data/test/dummy/bin/update +29 -0
  81. data/test/dummy/config.ru +5 -0
  82. data/test/dummy/config/application.rb +24 -0
  83. data/test/dummy/config/boot.rb +5 -0
  84. data/test/dummy/config/cable.yml +9 -0
  85. data/test/dummy/config/environment.rb +5 -0
  86. data/test/dummy/config/environments/development.rb +54 -0
  87. data/test/dummy/config/environments/production.rb +86 -0
  88. data/test/dummy/config/environments/test.rb +43 -0
  89. data/test/dummy/config/initializers/application_controller_renderer.rb +6 -0
  90. data/test/dummy/config/initializers/assets.rb +11 -0
  91. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  92. data/test/dummy/config/initializers/cookies_serializer.rb +5 -0
  93. data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  94. data/test/dummy/config/initializers/inflections.rb +16 -0
  95. data/test/dummy/config/initializers/mime_types.rb +4 -0
  96. data/test/dummy/config/initializers/new_framework_defaults.rb +21 -0
  97. data/test/dummy/config/initializers/session_store.rb +3 -0
  98. data/test/dummy/config/initializers/workarea.rb +5 -0
  99. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  100. data/test/dummy/config/locales/en.yml +23 -0
  101. data/test/dummy/config/puma.rb +47 -0
  102. data/test/dummy/config/routes.rb +5 -0
  103. data/test/dummy/config/secrets.yml +22 -0
  104. data/test/dummy/config/spring.rb +6 -0
  105. data/test/dummy/db/seeds.rb +3 -0
  106. data/test/dummy/lib/assets/.keep +0 -0
  107. data/test/dummy/log/.keep +0 -0
  108. data/test/dummy/public/404.html +67 -0
  109. data/test/dummy/public/422.html +67 -0
  110. data/test/dummy/public/500.html +66 -0
  111. data/test/dummy/public/apple-touch-icon-precomposed.png +0 -0
  112. data/test/dummy/public/apple-touch-icon.png +0 -0
  113. data/test/dummy/public/favicon.ico +0 -0
  114. data/test/integration/workarea/storefront/wish_lists_integration_test.rb +211 -0
  115. data/test/models/workarea/wish_list/public_search_test.rb +82 -0
  116. data/test/models/workarea/wish_list_test.rb +158 -0
  117. data/test/services/workarea/set_wish_list_details_test.rb +62 -0
  118. data/test/services/workarea/wish_list_session_test.rb +47 -0
  119. data/test/system/workarea/admin/wish_lists_system_test.rb +46 -0
  120. data/test/system/workarea/storefront/wish_lists_system_test.rb +287 -0
  121. data/test/test_helper.rb +10 -0
  122. data/test/view_models/workarea/storefront/user_view_model_test.rb +46 -0
  123. data/test/view_models/workarea/storefront/wish_list_item_view_model_test.rb +47 -0
  124. data/test/view_models/workarea/storefront/wish_list_view_model_test.rb +74 -0
  125. data/test/workers/workarea/mark_wish_list_items_purchased_test.rb +21 -0
  126. data/workarea-wish_lists.gemspec +21 -0
  127. metadata +188 -0
@@ -0,0 +1,3 @@
1
+ View this plugin's code of conduct here:
2
+
3
+ <https://github.com/workarea-commerce/workarea/blob/master/CODE_OF_CONDUCT.md>
@@ -0,0 +1,3 @@
1
+ View this plugin's contribution guidelines here:
2
+
3
+ <https://github.com/workarea-commerce/workarea/blob/master/CONTRIBUTING.md>
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+ git_source(:github) { |repo| "git@github.com:#{repo}.git" }
3
+
4
+ gemspec
5
+
6
+ gem 'workarea', '>= 3.3.0'
data/LICENSE ADDED
@@ -0,0 +1,52 @@
1
+ WebLinc
2
+ Business Source License
3
+
4
+ Licensor: WebLinc Corporation, 22 S. 3rd Street, 2nd Floor, Philadelphia PA 19106
5
+
6
+ Licensed Work: Workarea Commerce Platform
7
+ The Licensed Work is (c) 2019 WebLinc Corporation
8
+
9
+ Additional Use Grant:
10
+ You may make production use of the Licensed Work without an additional license agreement with WebLinc so long as you do not use the Licensed Work for a Commerce Service.
11
+
12
+ A "Commerce Service" is a commercial offering that allows third parties (other than your employees and contractors) to access the functionality of the Licensed Work by creating or managing commerce functionality, the products, taxonomy, assets and/or content of which are controlled by such third parties.
13
+
14
+ For information about obtaining an additional license agreement with WebLinc, contact licensing@workarea.com.
15
+
16
+ Change Date: 2019-08-20
17
+
18
+ Change License: Version 2.0 or later of the GNU General Public License as published by the Free Software Foundation
19
+
20
+ Terms
21
+
22
+ The Licensor hereby grants you the right to copy, modify, create derivative works, redistribute, and make non-production use of the Licensed Work. The Licensor may make an Additional Use Grant, above, permitting limited production use.
23
+
24
+ Effective on the Change Date, or the fourth anniversary of the first publicly available distribution of a specific version of the Licensed Work under this License, whichever comes first, the Licensor hereby grants you rights under the terms of the Change License, and the rights granted in the paragraph above terminate.
25
+
26
+ If your use of the Licensed Work does not comply with the requirements currently in effect as described in this License, you must purchase a commercial license from the Licensor, its affiliated entities, or authorized resellers, or you must refrain from using the Licensed Work.
27
+
28
+ All copies of the original and modified Licensed Work, and derivative works of the Licensed Work, are subject to this License. This License applies separately for each version of the Licensed Work and the Change Date may vary for each version of the Licensed Work released by Licensor.
29
+
30
+ You must conspicuously display this License on each original or modified copy of the Licensed Work. If you receive the Licensed Work in original or modified form from a third party, the terms and conditions set forth in this License apply to your use of that work.
31
+
32
+ Any use of the Licensed Work in violation of this License will automatically terminate your rights under this License for the current and all other versions of the Licensed Work.
33
+
34
+ This License does not grant you any right in any trademark or logo of Licensor or its affiliates (provided that you may use a trademark or logo of Licensor as expressly required by this License). TO THE EXTENT PERMITTED BY APPLICABLE LAW, THE LICENSED WORK IS PROVIDED ON AN "AS IS" BASIS. LICENSOR HEREBY DISCLAIMS ALL WARRANTIES AND CONDITIONS, EXPRESS OR IMPLIED, INCLUDING (WITHOUT LIMITATION) WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT, AND TITLE. MariaDB hereby grants you permission to use this License’s text to license your works and to refer to it using the trademark "Business Source License" as long as you comply with the Covenants of Licensor below.
35
+
36
+ Covenants of Licensor
37
+ In consideration of the right to use this License’s text and the "Business Source License" name and trademark, Licensor covenants to MariaDB, and to all other recipients of the licensed work to be provided by Licensor:
38
+
39
+ To specify as the Change License the GPL Version 2.0 or any later version, or a license that is compatible with GPL Version 2.0 or a later version, where "compatible" means that software provided under the Change License can be included in a program with software provided under GPL Version 2.0 or a later version. Licensor may specify additional Change Licenses without limitation.
40
+
41
+ To either: (a) specify an additional grant of rights to use that does not impose any additional restriction on the right granted in this License, as the Additional Use Grant; or (b) insert the text "None."
42
+
43
+ To specify a Change Date.
44
+
45
+ Not to modify this License in any other way.
46
+
47
+ Notice
48
+ The Business Source License (this document, or the "License") is not an Open Source license. However, the Licensed Work will eventually be made available under an Open Source License, as stated in this License.
49
+
50
+ For more information on the use of the Business Source License generally, please visit the Adopting and Developing Business Source License FAQ.
51
+
52
+ License text copyright (c) 2017 MariaDB Corporation Ab, All Rights Reserved. "Business Source License" is a trademark of MariaDB Corporation Ab.
@@ -0,0 +1,58 @@
1
+ Workarea Wish Lists
2
+ ================================================================================
3
+
4
+ A Workarea Commerce plugin to allow customers to create, manage, share, and search wish lists.
5
+
6
+ Overview
7
+ --------------------------------------------------------------------------------
8
+
9
+ * Add products to a wish list from the product details page or cart
10
+ * Manage list privacy - public, shared, or private
11
+ * Manage wish list items
12
+ * View products purchased from the wish lists
13
+ * Search public wish lists by customer's name or email address
14
+ * Add products to cart from wish lists
15
+ * Admin view of a customer's wish list items and purchase state
16
+
17
+ Getting Started
18
+ --------------------------------------------------------------------------------
19
+
20
+ Add the gem to your application's Gemfile:
21
+
22
+ ```ruby
23
+ # ...
24
+ gem 'workarea-wish_lists'
25
+ # ...
26
+ ```
27
+
28
+ Update your application's bundle.
29
+
30
+ ```bash
31
+ cd path/to/application
32
+ bundle
33
+ ```
34
+
35
+ Features
36
+ --------------------------------------------------------------------------------
37
+
38
+ ### Creating and managing wish lists
39
+
40
+ A customer can manage a list of products associated to their account. These products can be added from the product detail page directly, or from the cart. Wish list items maintain quantity, option, and customization selections for easy addition to orders at a later time. Quantity can be changed from the wish list page.
41
+
42
+ ### Privacy Control
43
+
44
+ A customer has control over the privacy level of their wish list. Setting a wish list to `public` allows other visitors of the site to search by a user's full name or email address and view a wish list, as well as purchase items off the wish list. Lists set to `shared` are not searchable but can be viewed by other visitors of the site if given a direct link to the wish list by the customer. A `private` wish list can be viewed only by the customer that owns the list.
45
+
46
+ ### Add to cart from wish list
47
+
48
+ An item can be added to a customer's cart from their own wish list or a wish list they have searched for / been given a link to view. Items purchased from the list will be marked as purchased.
49
+
50
+ Workarea Commerce Documentation
51
+ --------------------------------------------------------------------------------
52
+
53
+ See [https://developer.workarea.com](https://developer.workarea.com) for Workarea Commerce documentation.
54
+
55
+ License
56
+ --------------------------------------------------------------------------------
57
+
58
+ Workarea Wish Lists is released under the [Business Software License](LICENSE)
@@ -0,0 +1,53 @@
1
+ #!/usr/bin/env rake
2
+ begin
3
+ require 'bundler/setup'
4
+ rescue LoadError
5
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
6
+ end
7
+
8
+ require 'rdoc/task'
9
+
10
+ RDoc::Task.new(:rdoc) do |rdoc|
11
+ rdoc.rdoc_dir = 'rdoc'
12
+ rdoc.title = 'Tasker'
13
+ rdoc.options << '--line-numbers'
14
+ rdoc.rdoc_files.include('README.md')
15
+ rdoc.rdoc_files.include('lib/**/*.rb')
16
+ end
17
+
18
+ APP_RAKEFILE = File.expand_path('../test/dummy/Rakefile', __FILE__)
19
+ load 'rails/tasks/engine.rake'
20
+ load 'rails/tasks/statistics.rake'
21
+ load 'workarea/changelog.rake'
22
+
23
+ require 'rake/testtask'
24
+
25
+ Rake::TestTask.new(:test) do |t|
26
+ t.libs << 'lib'
27
+ t.libs << 'test'
28
+ t.pattern = 'test/**/*_test.rb'
29
+ t.verbose = false
30
+ end
31
+
32
+ task default: :test
33
+
34
+ $LOAD_PATH.unshift File.expand_path('../lib', __FILE__)
35
+ require 'workarea/wish_lists/version'
36
+
37
+ desc "Release version #{Workarea::WishLists::VERSION} of the gem"
38
+ task :release do
39
+ host = "https://#{ENV['BUNDLE_GEMS__WEBLINC__COM']}@gems.weblinc.com"
40
+
41
+ #Rake::Task['workarea:changelog'].execute
42
+ #system 'git add CHANGELOG.md'
43
+ #system 'git commit -m "Update CHANGELOG"'
44
+ #system 'git push origin HEAD'
45
+
46
+ system "git tag -a v#{Workarea::WishLists::VERSION} -m 'Tagging #{Workarea::WishLists::VERSION}'"
47
+ system 'git push --tags'
48
+
49
+ system 'gem build workarea-wish_lists.gemspec'
50
+ system "gem push workarea-wish_lists-#{Workarea::WishLists::VERSION}.gem"
51
+ system "gem push workarea-wish_lists-#{Workarea::WishLists::VERSION}.gem --host #{host}"
52
+ system "rm workarea-wish_lists-#{Workarea::WishLists::VERSION}.gem"
53
+ end
@@ -0,0 +1,35 @@
1
+ /**
2
+ * @namespace WORKAREA.wishListButton
3
+ */
4
+ WORKAREA.registerModule('wishListButton', (function () {
5
+ 'use strict';
6
+
7
+ var redirectToWishList = function() {
8
+ window.location = WORKAREA.routes.storefront.usersWishListPath();
9
+ },
10
+ addItemToWishList = function(event) {
11
+ var $button = $(event.currentTarget),
12
+ action = WORKAREA.routes.storefront.addToUsersWishListPath(),
13
+ $form = $button.closest('.product-details')
14
+ .find('.product-details__add-to-cart-form'),
15
+ payload = $form.serialize();
16
+
17
+ event.preventDefault();
18
+
19
+ if ($form.valid()) {
20
+ $.post(action, payload, redirectToWishList);
21
+ }
22
+ },
23
+ /**
24
+ * @method
25
+ * @name init
26
+ * @memberof WORKAREA.wishListButton
27
+ */
28
+ init = function($scope) {
29
+ $('[data-wish-list-button]', $scope).on('click', addItemToWishList);
30
+ };
31
+
32
+ return {
33
+ init: init
34
+ };
35
+ }()));
@@ -0,0 +1,42 @@
1
+ /**
2
+ * @namespace WORKAREA.wishListPublicQuantityFields
3
+ */
4
+ WORKAREA.registerModule('wishListPublicQuantityFields', (function () {
5
+ 'use strict';
6
+
7
+ var convertPriceToCents = function (textPrice) {
8
+ return parseInt(textPrice) * 100;
9
+ },
10
+
11
+ calculateTotalPrice = function (priceAsText, quantity) {
12
+ var total = convertPriceToCents(priceAsText) * quantity;
13
+ return total/100;
14
+ },
15
+
16
+ totalPrice = function (price, quantity) {
17
+ return '$' + calculateTotalPrice(price, quantity).toFixed(2);
18
+ },
19
+
20
+ updateItemTotalPrice = function (event) {
21
+ var $item = $(event.currentTarget).closest('tr'),
22
+ $itemPrice = $item.find('.wish-lists__public-item-price'),
23
+ $itemTotal = $item.find('.wish-lists__public-total-price'),
24
+ quantity = $item.find('.wish-lists__public-quantity-field').val(),
25
+ price = $itemPrice.text().replace('$', '');
26
+
27
+ $itemTotal.text(totalPrice(price, quantity));
28
+ },
29
+
30
+ /**
31
+ * @method
32
+ * @name init
33
+ * @memberof WORKAREA.wishListPublicQuantityFields
34
+ */
35
+ init = function ($scope) {
36
+ $('.wish-lists__public-quantity-field', $scope).on('change', updateItemTotalPrice);
37
+ };
38
+
39
+ return {
40
+ init: init
41
+ };
42
+ }()));
@@ -0,0 +1 @@
1
+ <input type="hidden" name="<%= name %>" value="<%= value %>">
@@ -0,0 +1,6 @@
1
+ /*------------------------------------*\
2
+ #WISH-LIST-BUTTON
3
+ \*------------------------------------*/
4
+
5
+ .wish-list-button {}
6
+ .wish-list-button__link {}
@@ -0,0 +1,24 @@
1
+ /*------------------------------------*\
2
+ #WISH-LISTS
3
+ \*------------------------------------*/
4
+
5
+ /**
6
+ * 1. Form submit action
7
+ */
8
+
9
+ .wish-lists {}
10
+
11
+ .wish-lists__link {}
12
+
13
+ .wish-lists__section {}
14
+
15
+ .wish-lists__public-url {}
16
+
17
+ .wish-lists__public-url-name,
18
+ .wish-lists__public-url-link {
19
+ margin: 0 0 halve($spacing-unit);
20
+ }
21
+
22
+ .wish-lists__section--settings {}
23
+ .wish-lists__section--share {}
24
+ .wish-lists__section--items {}
@@ -0,0 +1,20 @@
1
+ module Workarea
2
+ decorate Admin::UsersController, with: :wish_lists do
3
+ def wish_list
4
+ end
5
+
6
+ private
7
+
8
+ def find_user
9
+ if params[:user_id].present?
10
+ @user =
11
+ Admin::UserViewModel.new(
12
+ User.find(params[:user_id]),
13
+ view_model_options
14
+ )
15
+ else
16
+ super
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,128 @@
1
+ module Workarea
2
+ module Storefront
3
+ class Users::WishListsController < Storefront::ApplicationController
4
+ skip_before_action :verify_authenticity_token, only: [:add_item]
5
+ before_action :store_item_in_session, only: :add_item, unless: :logged_in?
6
+ before_action :store_item_in_session_when_moving_to_cart, only: :create_from_cart_item, unless: :logged_in?
7
+ before_action :require_login_and_redirect
8
+ before_action :add_item_from_session, only: :show, if: :item_stored_in_session?
9
+ before_action :validate_customizations, only: :add_item
10
+
11
+ def show
12
+ WishList::Pricing.perform(current_wish_list)
13
+ @wish_list = WishListViewModel.new(
14
+ current_wish_list,
15
+ view_model_options
16
+ )
17
+ end
18
+
19
+ def update
20
+ current_wish_list.update_attributes(params.permit(:privacy))
21
+ flash[:success] =
22
+ t('workarea.storefront.flash_messages.wish_list_updated')
23
+ redirect_to users_wish_list_path
24
+ end
25
+
26
+ def update_item_quantity
27
+ if current_wish_list.update_item_quantity(params[:item_id], params[:quantity].to_i)
28
+ flash[:success] =
29
+ t('workarea.storefront.flash_messages.wish_list_item_updated')
30
+ end
31
+ redirect_to users_wish_list_path
32
+ end
33
+
34
+ def create_from_cart_item
35
+ item = current_order.items.find(params[:item_id])
36
+ current_wish_list.add_item(
37
+ item.product_id,
38
+ item.sku,
39
+ item.quantity,
40
+ OrderItemDetails.find!(item.sku).to_h,
41
+ item.customizations
42
+ )
43
+ current_order.remove_item(params[:item_id])
44
+
45
+ flash[:success] =
46
+ t('workarea.storefront.flash_messages.item_moved_to_wish_list')
47
+ redirect_to users_wish_list_path
48
+ end
49
+
50
+ def add_item
51
+ current_wish_list.add_item(
52
+ product_id,
53
+ sku,
54
+ params[:quantity].to_i,
55
+ OrderItemDetails.find!(sku).to_h,
56
+ customizations.try(:to_h) || {}
57
+ )
58
+ flash[:success] =
59
+ t('workarea.storefront.flash_messages.wish_list_item_added')
60
+ redirect_to users_wish_list_path
61
+ end
62
+
63
+ def remove_item
64
+ current_wish_list.remove_item(params[:sku])
65
+ flash[:success] =
66
+ t('workarea.storefront.flash_messages.wish_list_item_removed')
67
+ redirect_to users_wish_list_path
68
+ end
69
+
70
+ private
71
+
72
+ def require_login_and_redirect
73
+ remember_location(users_wish_list_path) unless logged_in?
74
+ require_login
75
+ end
76
+
77
+ def current_wish_list
78
+ @wish_list ||= WishList.for_user(current_user.id)
79
+ end
80
+
81
+ def store_item_in_session
82
+ wish_list_session.store_item(params.merge(customizations: customizations.try(:to_h) || {}))
83
+ end
84
+
85
+ def store_item_in_session_when_moving_to_cart
86
+ item = current_order.items.where(id: params[:item_id]).first
87
+ wish_list_session.store_item(item.attributes.merge(item_id: params[:item_id]))
88
+ end
89
+
90
+ def add_item_from_session
91
+ item_id = session[:wish_list_item_id]
92
+
93
+ wish_list_session.add_item(current_wish_list)
94
+ current_order.remove_item(item_id) if item_id.present?
95
+ end
96
+
97
+ def wish_list_session
98
+ WishListSession.new(session)
99
+ end
100
+
101
+ def item_stored_in_session?
102
+ session.key?(:wish_list_product_id)
103
+ end
104
+
105
+ def customizations
106
+ @customizations ||= Catalog::Customizations.find(product_id, params.to_unsafe_h)
107
+ end
108
+
109
+ def validate_customizations
110
+ if customizations.present? && !customizations.valid?
111
+ flash[:error] = customizations.errors.full_messages.join(', ')
112
+ product = Catalog::Product.find(product_id)
113
+
114
+ redirect_back(fallback_location: product_path(product))
115
+ return false
116
+ end
117
+ end
118
+
119
+ def product_id
120
+ params[:product_id]
121
+ end
122
+
123
+ def sku
124
+ params[:sku]
125
+ end
126
+ end
127
+ end
128
+ end