workarea-gift_wrapping 1.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (108) hide show
  1. checksums.yaml +7 -0
  2. data/.editorconfig +20 -0
  3. data/.github/ISSUE_TEMPLATE/bug_report.md +37 -0
  4. data/.github/ISSUE_TEMPLATE/documentation-request.md +17 -0
  5. data/.github/ISSUE_TEMPLATE/feature_request.md +20 -0
  6. data/.gitignore +23 -0
  7. data/CHANGELOG.md +34 -0
  8. data/CODE_OF_CONDUCT.md +3 -0
  9. data/CONTRIBUTING.md +3 -0
  10. data/Gemfile +9 -0
  11. data/LICENSE +52 -0
  12. data/README.md +41 -0
  13. data/Rakefile +60 -0
  14. data/app/controllers/workarea/admin/catalog_gift_wraps_controller.rb +77 -0
  15. data/app/models/workarea/catalog/gift_wrap.rb +10 -0
  16. data/app/models/workarea/catalog/product.decorator +7 -0
  17. data/app/models/workarea/checkout/steps/shipping.decorator +57 -0
  18. data/app/models/workarea/order/item.decorator +53 -0
  19. data/app/models/workarea/pricing/calculators/gift_wrapping_calculator.rb +38 -0
  20. data/app/models/workarea/pricing/request.decorator +9 -0
  21. data/app/models/workarea/shipping.decorator +10 -0
  22. data/app/seeds/workarea/gift_wrapping_seeds.rb +19 -0
  23. data/app/view_models/workarea/order_item_view_model.decorator +19 -0
  24. data/app/view_models/workarea/storefront/checkout/gift_options_view_model.rb +45 -0
  25. data/app/view_models/workarea/storefront/checkout/summary_view_model.decorator +11 -0
  26. data/app/views/workarea/admin/catalog_gift_wraps/_aux_navigation.html.haml +7 -0
  27. data/app/views/workarea/admin/catalog_gift_wraps/_navigation.html.haml +1 -0
  28. data/app/views/workarea/admin/catalog_gift_wraps/edit.html.haml +38 -0
  29. data/app/views/workarea/admin/catalog_gift_wraps/index.html.haml +41 -0
  30. data/app/views/workarea/admin/catalog_gift_wraps/new.html.haml +39 -0
  31. data/app/views/workarea/admin/catalog_products/_gift_wrapping_fields.html.haml +3 -0
  32. data/app/views/workarea/admin/orders/_gift_wrapping.html.haml +4 -0
  33. data/app/views/workarea/admin/shippings/_gift_message.html.haml +5 -0
  34. data/app/views/workarea/storefront/checkouts/_gift_message.html.haml +10 -0
  35. data/app/views/workarea/storefront/checkouts/_gift_message_summary.html.haml +4 -0
  36. data/app/views/workarea/storefront/checkouts/_gift_wrapping.html.haml +34 -0
  37. data/app/views/workarea/storefront/checkouts/_gift_wrapping_summary.html.haml +5 -0
  38. data/app/views/workarea/storefront/order_mailer/_gift_message.html.haml +8 -0
  39. data/app/views/workarea/storefront/order_mailer/_gift_message.text.erb +5 -0
  40. data/app/views/workarea/storefront/order_mailer/_gift_wrapping.html.haml +4 -0
  41. data/app/views/workarea/storefront/order_mailer/_gift_wrapping.text.erb +3 -0
  42. data/app/views/workarea/storefront/orders/_gift_message.html.haml +7 -0
  43. data/app/views/workarea/storefront/orders/_gift_wrapping.html.haml +4 -0
  44. data/bin/rails +20 -0
  45. data/config/initializers/appends.rb +68 -0
  46. data/config/initializers/configuration.rb +15 -0
  47. data/config/locales/en.yml +42 -0
  48. data/config/routes.rb +5 -0
  49. data/lib/workarea/gift_wrapping/engine.rb +22 -0
  50. data/lib/workarea/gift_wrapping/version.rb +5 -0
  51. data/lib/workarea/gift_wrapping.rb +11 -0
  52. data/test/dummy/Rakefile +6 -0
  53. data/test/dummy/app/assets/config/manifest.js +4 -0
  54. data/test/dummy/app/assets/images/.keep +0 -0
  55. data/test/dummy/app/assets/javascripts/application.js +13 -0
  56. data/test/dummy/app/assets/stylesheets/application.css +15 -0
  57. data/test/dummy/app/controllers/application_controller.rb +3 -0
  58. data/test/dummy/app/controllers/concerns/.keep +0 -0
  59. data/test/dummy/app/helpers/application_helper.rb +2 -0
  60. data/test/dummy/app/jobs/application_job.rb +2 -0
  61. data/test/dummy/app/mailers/application_mailer.rb +4 -0
  62. data/test/dummy/app/models/concerns/.keep +0 -0
  63. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  64. data/test/dummy/app/views/layouts/mailer.html.erb +13 -0
  65. data/test/dummy/app/views/layouts/mailer.text.erb +1 -0
  66. data/test/dummy/bin/bundle +3 -0
  67. data/test/dummy/bin/rails +4 -0
  68. data/test/dummy/bin/rake +4 -0
  69. data/test/dummy/bin/setup +37 -0
  70. data/test/dummy/bin/update +29 -0
  71. data/test/dummy/bin/yarn +11 -0
  72. data/test/dummy/config/application.rb +27 -0
  73. data/test/dummy/config/boot.rb +5 -0
  74. data/test/dummy/config/cable.yml +10 -0
  75. data/test/dummy/config/environment.rb +5 -0
  76. data/test/dummy/config/environments/development.rb +54 -0
  77. data/test/dummy/config/environments/production.rb +91 -0
  78. data/test/dummy/config/environments/test.rb +44 -0
  79. data/test/dummy/config/initializers/application_controller_renderer.rb +8 -0
  80. data/test/dummy/config/initializers/assets.rb +14 -0
  81. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  82. data/test/dummy/config/initializers/cookies_serializer.rb +5 -0
  83. data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  84. data/test/dummy/config/initializers/inflections.rb +16 -0
  85. data/test/dummy/config/initializers/mime_types.rb +4 -0
  86. data/test/dummy/config/initializers/workarea.rb +5 -0
  87. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  88. data/test/dummy/config/locales/en.yml +33 -0
  89. data/test/dummy/config/puma.rb +56 -0
  90. data/test/dummy/config/routes.rb +5 -0
  91. data/test/dummy/config/secrets.yml +32 -0
  92. data/test/dummy/config/spring.rb +6 -0
  93. data/test/dummy/config.ru +5 -0
  94. data/test/dummy/db/seeds.rb +2 -0
  95. data/test/dummy/lib/assets/.keep +0 -0
  96. data/test/dummy/log/.keep +0 -0
  97. data/test/factories/workarea/gift_wrapping.rb +21 -0
  98. data/test/integration/workarea/admin/catalog_gift_wrap_integration_test.rb +50 -0
  99. data/test/integration/workarea/storefront/gift_wrapping_integration_test.rb +76 -0
  100. data/test/models/workarea/checkout/steps/gift_wrapping_shipping_test.rb +37 -0
  101. data/test/models/workarea/order/gift_wrapping_item_test.rb +52 -0
  102. data/test/models/workarea/pricing/calculators/gift_wrapping_calculator_test.rb +84 -0
  103. data/test/system/workarea/admin/gift_wrap_system_test.rb +48 -0
  104. data/test/system/workarea/storefront/gift_wrap_system_test.rb +93 -0
  105. data/test/teaspoon_env.rb +6 -0
  106. data/test/test_helper.rb +10 -0
  107. data/workarea-gift_wrapping.gemspec +21 -0
  108. metadata +170 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: c216a76421466fe47b68975565365b36c0571a977bf72bbfe2e7be38ba673d83
4
+ data.tar.gz: 105cce6ad199d767bbea62f2dcadec16b803ee4153dc3599e158a1727d14fb88
5
+ SHA512:
6
+ metadata.gz: abb5b841156814754fd506cedbe4441b2ffae72572404ad3f5d3c58746244fd16a461172d8a651edc93a0241af8ae26ddb1b367b4b4e5d42ec5e78801437efe8
7
+ data.tar.gz: dbba9362042d9219d026b47af9e6c65d32bfcc3ecfdcf5524f2d2775fb21896f3710f48d506cb4c91008ac2729b489eb132683bc1cbda8d062a35c1142fa8986
data/.editorconfig ADDED
@@ -0,0 +1,20 @@
1
+ # editorconfig.org
2
+ root = true
3
+
4
+ [*]
5
+ charset = utf-8
6
+ indent_style = space
7
+ end_of_line = lf
8
+ trim_trailing_whitespace = true
9
+ insert_final_newline = true
10
+
11
+ [{*.rb,*.haml,*.decorator,*.yml,*.yaml,*.jbuilder}]
12
+ indent_size = 2
13
+ indent_style = space
14
+
15
+ [{*.js,*.jst,*.ejs,*.scss}]
16
+ indent_size = 4
17
+
18
+ [*.md]
19
+ indent_size = 4
20
+ trim_trailing_whitespace = false
@@ -0,0 +1,37 @@
1
+ ---
2
+ name: Bug report
3
+ about: Create a report to help us improve Workarea
4
+ title: ''
5
+ labels: bug
6
+ assignees: ''
7
+
8
+ ---
9
+
10
+ ⚠️**Before you create**⚠️
11
+ Please verify the issue you're experiencing is not part of your Workarea project customizations. The best way to do this is with a [vanilla Workarea installation](https://developer.workarea.com/articles/create-a-new-host-application.html). This will help us spend time on fixes/improvements for the whole community. Thank you!
12
+
13
+ **Describe the bug**
14
+ A clear and concise description of what the bug is.
15
+
16
+ **To Reproduce**
17
+ Steps to reproduce the behavior:
18
+ 1. Go to '...'
19
+ 2. Click on '....'
20
+ 3. Scroll down to '....'
21
+ 4. See error
22
+
23
+ **Expected behavior**
24
+ A clear and concise description of what you expected to happen.
25
+
26
+ **Workarea Setup (please complete the following information):**
27
+ - Workarea Version: [e.g. v3.4.6]
28
+ - Plugins [e.g. workarea-blog, workarea-sitemaps]
29
+
30
+ **Attachments**
31
+ If applicable, add any attachments to help explain your problem, things like:
32
+ - screenshots
33
+ - Gemfile.lock
34
+ - test cases
35
+
36
+ **Additional context**
37
+ Add any other context about the problem here.
@@ -0,0 +1,17 @@
1
+ ---
2
+ name: Documentation request
3
+ about: Suggest documentation
4
+ title: ''
5
+ labels: documentation
6
+ assignees: ''
7
+
8
+ ---
9
+
10
+ **Is your documentation related to a problem? Please describe.**
11
+ A clear and concise description of what the problem is. Ex. I'm confused by [...]
12
+
13
+ **Describe the article you'd like**
14
+ A clear and concise description of what would be in the documentation article.
15
+
16
+ **Additional context**
17
+ Add any other context or screenshots about the feature request here.
@@ -0,0 +1,20 @@
1
+ ---
2
+ name: Feature request
3
+ about: Suggest an idea for Workarea
4
+ title: ''
5
+ labels: enhancement
6
+ assignees: ''
7
+
8
+ ---
9
+
10
+ **Is your feature request related to a problem? Please describe.**
11
+ A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
12
+
13
+ **Describe the solution you'd like**
14
+ A clear and concise description of what you want to happen.
15
+
16
+ **Describe alternatives you've considered**
17
+ A clear and concise description of any alternative solutions or features you've considered.
18
+
19
+ **Additional context**
20
+ Add any other context or screenshots about the feature request here.
data/.gitignore ADDED
@@ -0,0 +1,23 @@
1
+ .bundle/
2
+ log/*.log
3
+ pkg/
4
+ test/dummy/db/*.sqlite3
5
+ test/dummy/db/*.sqlite3-journal
6
+ test/dummy/log/*.log
7
+ test/dummy/tmp/
8
+ .DS_Store
9
+ .byebug_history
10
+ .bundle/
11
+ .sass-cache/
12
+ Gemfile.lock
13
+ pkg/
14
+ test/dummy/tmp/
15
+ test/dummy/public/
16
+ log/*.log
17
+ test/dummy/log/*.log
18
+ test/dummy/db/*.sqlite3
19
+ test/dummy/db/*.sqlite3-journal
20
+ node_modules
21
+ test/reports
22
+ package.json
23
+ yarn.lock
data/CHANGELOG.md ADDED
@@ -0,0 +1,34 @@
1
+ Workarea Gift Wrapping 1.2.1 (2018-10-03)
2
+ --------------------------------------------------------------------------------
3
+
4
+ * Open Source!
5
+
6
+
7
+
8
+ Workarea Gift Wrapping 1.2.0 (2018-10-03)
9
+ --------------------------------------------------------------------------------
10
+
11
+ * Allow disabling gift wrapping per product
12
+
13
+ GIFTWRAP-10
14
+ Ben Crouse
15
+
16
+
17
+
18
+ Workarea Gift Wrapping 1.1.0 (2018-05-24)
19
+ --------------------------------------------------------------------------------
20
+
21
+ * Support Bulk Action Items UI
22
+
23
+ ECOMMERCE-6012
24
+ Curt Howard
25
+
26
+ * Leverage Workarea Changelog task
27
+
28
+ ECOMMERCE-5355
29
+ Curt Howard
30
+
31
+
32
+
33
+ Workarea Gift Wrapping 1.0.0 (2018-02-06)
34
+ --------------------------------------------------------------------------------
@@ -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>
data/CONTRIBUTING.md ADDED
@@ -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,9 @@
1
+ source 'https://rubygems.org'
2
+ git_source(:github) { |repo| "git@github.com:#{repo}.git" }
3
+
4
+ gemspec
5
+
6
+ # To use a debugger
7
+ # gem 'byebug', group: [:development, :test]
8
+
9
+ gem 'workarea', github: 'workarea-commerce/workarea'
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.
data/README.md ADDED
@@ -0,0 +1,41 @@
1
+ Workarea Gift Wrapping
2
+ ================================================================================
3
+
4
+ A Workarea Commerce plugin that enables customers to add a gift message and/or select gift wrapping for products in their cart during checkout.
5
+
6
+ Overview
7
+ --------------------------------------------------------------------------------
8
+
9
+ * Adds gift wrapping options for each product in the cart during the shipping step of checkout
10
+ * Adds a gift message field for the order during the shipping step of checkout
11
+ * Enables admin users to add gift wrapping types and set pricing for each type
12
+ * Allows enabling/disabling gift wrapping per product in the catalog
13
+ * Uses `config.gift_message_max_length` to limit the length of gift messages
14
+
15
+ Getting Started
16
+ --------------------------------------------------------------------------------
17
+
18
+ Add the gem to your application's Gemfile:
19
+
20
+ ```ruby
21
+ # ...
22
+ gem 'workarea-gift_wrapping'
23
+ # ...
24
+ ```
25
+
26
+ Update your application's bundle.
27
+
28
+ ```bash
29
+ cd path/to/application
30
+ bundle
31
+ ```
32
+
33
+ Workarea Commerce Documentation
34
+ --------------------------------------------------------------------------------
35
+
36
+ See [https://developer.workarea.com](https://developer.workarea.com) for Workarea Commerce documentation.
37
+
38
+ License
39
+ --------------------------------------------------------------------------------
40
+
41
+ Workarea Gift Wrapping is released under the [Business Software License](LICENSE)
data/Rakefile ADDED
@@ -0,0 +1,60 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'rdoc/task'
8
+ RDoc::Task.new(:rdoc) do |rdoc|
9
+ rdoc.rdoc_dir = 'rdoc'
10
+ rdoc.title = 'Gift Wrapping'
11
+ rdoc.options << '--line-numbers'
12
+ rdoc.rdoc_files.include('README.md')
13
+ rdoc.rdoc_files.include('lib/**/*.rb')
14
+ end
15
+
16
+ APP_RAKEFILE = File.expand_path('../test/dummy/Rakefile', __FILE__)
17
+ load 'rails/tasks/engine.rake'
18
+ load 'rails/tasks/statistics.rake'
19
+ load 'workarea/changelog.rake'
20
+
21
+ require 'rake/testtask'
22
+ Rake::TestTask.new(:test) do |t|
23
+ t.libs << 'lib'
24
+ t.libs << 'test'
25
+ t.pattern = 'test/**/*_test.rb'
26
+ t.verbose = false
27
+ end
28
+ task default: :test
29
+
30
+ $LOAD_PATH.unshift File.expand_path('../lib', __FILE__)
31
+ require 'workarea/gift_wrapping/version'
32
+
33
+ desc "Release version #{Workarea::GiftWrapping::VERSION} of the gem"
34
+ task :release do
35
+ host = "https://#{ENV['BUNDLE_GEMS__WEBLINC__COM']}@gems.weblinc.com"
36
+
37
+ #Rake::Task['workarea:changelog'].execute
38
+ #system 'git add CHANGELOG.md'
39
+ #system 'git commit -m "Update CHANGELOG"'
40
+ #system 'git push origin HEAD'
41
+
42
+ system "git tag -a v#{Workarea::GiftWrapping::VERSION} -m 'Tagging #{Workarea::GiftWrapping::VERSION}'"
43
+ system 'git push --tags'
44
+
45
+ system 'gem build workarea-gift_wrapping.gemspec'
46
+ system "gem push workarea-gift_wrapping-#{Workarea::GiftWrapping::VERSION}.gem"
47
+ system "gem push workarea-gift_wrapping-#{Workarea::GiftWrapping::VERSION}.gem --host #{host}"
48
+ system "rm workarea-gift_wrapping-#{Workarea::GiftWrapping::VERSION}.gem"
49
+ end
50
+
51
+ desc 'Run the JavaScript tests'
52
+ ENV['TEASPOON_RAILS_ENV'] = File.expand_path('../test/dummy/config/environment', __FILE__)
53
+ task teaspoon: 'app:teaspoon'
54
+
55
+ desc 'Start a server at http://localhost:3000/teaspoon for JavaScript tests'
56
+ task :teaspoon_server do
57
+ Dir.chdir('test/dummy')
58
+ teaspoon_env = File.expand_path('../test/teaspoon_env.rb', __FILE__)
59
+ system "RAILS_ENV=test TEASPOON_ENV=#{teaspoon_env} rails s"
60
+ end
@@ -0,0 +1,77 @@
1
+ module Workarea
2
+ module Admin
3
+ class CatalogGiftWrapsController < ApplicationController
4
+ before_action :find_gift_wrap, except: :index
5
+
6
+ def index
7
+ @gift_wraps =
8
+ Catalog::GiftWrap.page(params[:page]).per(Workarea.config.per_page)
9
+ end
10
+
11
+ def new; end
12
+
13
+ def create
14
+ if @gift_wrap.save && save_pricing_sku
15
+ flash[:success] =
16
+ t('workarea.admin.catalog_gift_wraps.flash_messages.success')
17
+ redirect_to catalog_gift_wraps_path
18
+ else
19
+ flash[:error] =
20
+ t('workarea.admin.catalog_gift_wraps.flash_messages.error')
21
+ render :new
22
+ end
23
+ end
24
+
25
+ def edit
26
+ @pricing = Pricing::Sku.find(@gift_wrap.sku) rescue nil
27
+ end
28
+
29
+ def update
30
+ if @gift_wrap.update_attributes(params[:gift_wrap])
31
+ flash[:success] =
32
+ t('workarea.admin.catalog_gift_wraps.flash_messages.success')
33
+ redirect_to catalog_gift_wraps_path
34
+ else
35
+ flash[:error] =
36
+ t('workarea.admin.catalog_gift_wraps.flash_messages.error')
37
+ render :edit
38
+ end
39
+ end
40
+
41
+ def destroy
42
+ @gift_wrap.destroy
43
+
44
+ flash[:success] =
45
+ t('workarea.admin.catalog_gift_wraps.flash_messages.destroyed')
46
+ redirect_to catalog_gift_wraps_path
47
+ end
48
+
49
+ private
50
+
51
+ def save_pricing_sku
52
+ pricing_params = params[:pricing_sku]
53
+ return true unless pricing_params[:regular].present?
54
+
55
+ pricing_sku = Pricing::Sku.find_or_initialize_by(id: @gift_wrap.sku)
56
+
57
+ price = pricing_sku.prices.first || pricing_sku.prices.build
58
+ price.regular = pricing_params[:regular].to_m
59
+
60
+ if pricing_params[:tax_code].present?
61
+ pricing_sku.tax_code = pricing_params[:tax_code]
62
+ end
63
+
64
+ pricing_sku.save
65
+ end
66
+
67
+ def find_gift_wrap
68
+ @gift_wrap =
69
+ if params[:id].present?
70
+ Catalog::GiftWrap.find(params[:id])
71
+ else
72
+ Catalog::GiftWrap.new(params[:gift_wrap])
73
+ end
74
+ end
75
+ end
76
+ end
77
+ end
@@ -0,0 +1,10 @@
1
+ module Workarea
2
+ module Catalog
3
+ class GiftWrap
4
+ include ApplicationDocument
5
+
6
+ field :name, type: String, localize: true
7
+ field :sku, type: String
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,7 @@
1
+ module Workarea
2
+ decorate Catalog::Product, with: :gift_wrapping do
3
+ decorated do
4
+ field :allow_gift_wrapping, type: Boolean, default: true
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,57 @@
1
+ module Workarea
2
+ decorate Checkout::Steps::Shipping, with: :gift_wrapping do
3
+ # Update the shipping step of checkout. This includes:
4
+ # * shipping service
5
+ # * gift message
6
+ # * gift wrapping
7
+ #
8
+ # A default shipping service will probably be set before getting
9
+ # to this point of the checkout.
10
+ #
11
+ # @param [Hash] params
12
+ # @option params [String] :shipping_service
13
+ # @option params [String] :gift_message
14
+ # @option params [String] :gift_wrapping
15
+ #
16
+ # @raise [Checkout::Steps::Shipping::NoAvailableShippingOption]
17
+ #
18
+ # @return [Boolean] whether the update succeeded
19
+ #
20
+ def update(params = {})
21
+ super
22
+ return true unless order.requires_shipping?
23
+
24
+ apply_gift_message(params)
25
+ update_gift_wrapping(params)
26
+ persist_update
27
+ end
28
+
29
+ private
30
+
31
+ def apply_gift_message(params)
32
+ return unless params[:gift_message].present?
33
+ shipping.gift_message = params[:gift_message]
34
+ end
35
+
36
+ def update_gift_wrapping(params)
37
+ return unless params[:gift_wrapping].present?
38
+
39
+ items = order.items.to_a
40
+ gift_wraps = Catalog::GiftWrap.all.to_a
41
+
42
+ items.each(&:reset_gift_wrapping)
43
+
44
+ params[:gift_wrapping].each do |item_id, options|
45
+ next unless options[:gift_wrap].present?
46
+
47
+ gift_wrap = gift_wraps.detect { |gw| gw.id.to_s == options[:gift_wrap] }
48
+ next unless gift_wrap.present?
49
+
50
+ item = items.detect { |item| item.id.to_s == item_id }
51
+ next unless item.present? && item.allow_gift_wrapping?
52
+
53
+ item.add_gift_wrap(gift_wrap.as_document, options[:quantity])
54
+ end
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,53 @@
1
+ module Workarea
2
+ decorate Order::Item, with: :gift_wrapping do
3
+ decorated do
4
+ field :gift_wrap_quantities, type: Hash, default: {}
5
+ field :gift_wraps_attributes, type: Array, default: []
6
+ end
7
+
8
+ def allow_gift_wrapping?
9
+ !!product_attributes.with_indifferent_access[:allow_gift_wrapping]
10
+ end
11
+
12
+ # Adjusts gift_wrap_quantities whenever quantity changes
13
+ # NOTE: this would need to be modified when supporting multiple gift
14
+ # wrap options across the quantity of a single item.
15
+ #
16
+ # @param [Integer] quantity the new quantity
17
+ #
18
+ # @return [Integer]
19
+ #
20
+ def quantity=(quantity)
21
+ super.tap do
22
+ return unless quantity_changed? && gift_wrap_quantities.present?
23
+
24
+ gift_wrap_quantities.each_key do |sku|
25
+ gift_wrap_quantities[sku] = quantity
26
+ end
27
+ end
28
+ end
29
+
30
+ def gift_wrap_skus
31
+ gift_wrap_quantities.keys
32
+ end
33
+
34
+ def reset_gift_wrapping
35
+ self.gift_wrap_quantities = {}
36
+ self.gift_wraps_attributes = []
37
+ end
38
+
39
+ def add_gift_wrap(attributes, qty = nil)
40
+ sku = attributes['sku']
41
+
42
+ gift_wrap_quantities[sku] ||= 0
43
+ gift_wrap_quantities[sku] += (qty || quantity).to_i
44
+
45
+ if gift_wrap_quantities[sku] > quantity
46
+ gift_wrap_quantities[sku] = quantity
47
+ end
48
+
49
+ gift_wraps_attributes << attributes
50
+ gift_wraps_attributes.uniq! { |a| a['_id'] }
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,38 @@
1
+ module Workarea
2
+ module Pricing
3
+ module Calculators
4
+ class GiftWrappingCalculator
5
+ include Calculator
6
+
7
+ def adjust
8
+ order.items.each do |item|
9
+ next unless item.gift_wrap_quantities.present?
10
+
11
+ item.gift_wrap_quantities
12
+ .each { |sku, quantity| adjust_for_wrap(item, sku, quantity) }
13
+ end
14
+ end
15
+
16
+ def adjust_for_wrap(item, wrap_sku, quantity)
17
+ price = pricing.for_sku(wrap_sku, quantity: quantity)
18
+
19
+ total = price.sell * quantity
20
+ return unless total > 0
21
+
22
+ item.adjust_pricing(
23
+ price: 'item',
24
+ quantity: quantity,
25
+ description: I18n.t('workarea.gift_wrap.price_adjustment'),
26
+ calculator: self.class.name,
27
+ amount: total,
28
+ data: {
29
+ 'on_sale' => price.on_sale?,
30
+ 'original_price' => price.regular.to_f,
31
+ 'tax_code' => price.tax_code
32
+ }
33
+ )
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,9 @@
1
+ module Workarea
2
+ decorate Pricing::Request, with: :gift_wrap do
3
+ private
4
+
5
+ def all_skus
6
+ super + order.items.flat_map(&:gift_wrap_skus)
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,10 @@
1
+ module Workarea
2
+ decorate Shipping, with: :gift_wrapping do
3
+ decorated do
4
+ field :gift_message, type: String
5
+
6
+ validates :gift_message,
7
+ length: { maximum: Workarea.config.gift_message_max_length }
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,19 @@
1
+ module Workarea
2
+ class GiftWrappingSeeds
3
+ def perform
4
+ puts 'Adding gift wrapping options...'
5
+
6
+ Workarea::Pricing::Sku.create!(
7
+ id: 'GIFT_WRAP_1',
8
+ prices: [{ regular: 1.to_m }]
9
+ )
10
+ Workarea::Catalog::GiftWrap.create!(name: 'Basic', sku: 'GIFT_WRAP_1')
11
+
12
+ Workarea::Pricing::Sku.create!(
13
+ id: 'GIFT_WRAP_2',
14
+ prices: [{ regular: 2.to_m }]
15
+ )
16
+ Workarea::Catalog::GiftWrap.create!(name: 'Fancy', sku: 'GIFT_WRAP_2')
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,19 @@
1
+ module Workarea
2
+ decorate Storefront::OrderItemViewModel,
3
+ Admin::OrderItemViewModel, with: :gift_wrapping do
4
+
5
+ def gift_wrap_id
6
+ gift_wraps.first.try(:id).to_s
7
+ end
8
+
9
+ def gift_wraps
10
+ @gift_wraps ||= gift_wraps_attributes.map do |attr|
11
+ Mongoid::Factory.from_db(Catalog::GiftWrap, attr)
12
+ end
13
+ end
14
+
15
+ def gift_wrapped?
16
+ gift_wrap_quantities.present?
17
+ end
18
+ end
19
+ end