workarea-package_products 3.3.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (128) 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 +15 -0
  7. data/CHANGELOG.md +343 -0
  8. data/CODE_OF_CONDUCT.md +3 -0
  9. data/CONTRIBUTING.md +3 -0
  10. data/Gemfile +16 -0
  11. data/LICENSE +52 -0
  12. data/README.md +40 -0
  13. data/Rakefile +52 -0
  14. data/app/assets/javascripts/workarea/storefront/package_products/modules/family_product_add_to_cart.js +83 -0
  15. data/app/assets/javascripts/workarea/storefront/package_products/templates/family_add_to_cart_checkbox.jst.ejs +1 -0
  16. data/app/assets/stylesheets/workarea/admin/package_products/components/_product_cards.scss +7 -0
  17. data/app/assets/stylesheets/workarea/storefront/package_products/components/_product_detail_packaged_products.scss +11 -0
  18. data/app/controllers/workarea/admin/create_catalog_package_products_controller.rb +150 -0
  19. data/app/controllers/workarea/admin/create_catalog_products_controller.decorator +25 -0
  20. data/app/controllers/workarea/storefront/cart_items_controller.decorator +29 -0
  21. data/app/controllers/workarea/storefront/products_controller.decorator +8 -0
  22. data/app/models/workarea/catalog/product.decorator +44 -0
  23. data/app/models/workarea/search/admin/catalog_product.decorator +20 -0
  24. data/app/models/workarea/search/storefront/package_product.rb +40 -0
  25. data/app/queries/workarea/search/product_entries.decorator +8 -0
  26. data/app/seeds/workarea/package_product_seeds.rb +41 -0
  27. data/app/services/workarea/add_package_to_cart.rb +79 -0
  28. data/app/view_models/workarea/admin/product_view_model.decorator +35 -0
  29. data/app/view_models/workarea/storefront/product_templates/family_view_model.rb +6 -0
  30. data/app/view_models/workarea/storefront/product_templates/package_view_model.rb +33 -0
  31. data/app/view_models/workarea/storefront/product_view_model.decorator +13 -0
  32. data/app/views/workarea/admin/catalog_products/_create_package_button.html.haml +1 -0
  33. data/app/views/workarea/admin/catalog_products/_packaged_products_card.html.haml +26 -0
  34. data/app/views/workarea/admin/create_catalog_package_products/categorization.html.haml +64 -0
  35. data/app/views/workarea/admin/create_catalog_package_products/content.html.haml +54 -0
  36. data/app/views/workarea/admin/create_catalog_package_products/details.html.haml +87 -0
  37. data/app/views/workarea/admin/create_catalog_package_products/images.html.haml +57 -0
  38. data/app/views/workarea/admin/create_catalog_package_products/packaged_products.html.haml +79 -0
  39. data/app/views/workarea/admin/create_catalog_package_products/publish.html.haml +61 -0
  40. data/app/views/workarea/admin/create_catalog_package_products/setup.html.haml +68 -0
  41. data/app/views/workarea/admin/create_catalog_products/select.html.haml +34 -0
  42. data/app/views/workarea/storefront/cart_items/package.html.haml +59 -0
  43. data/app/views/workarea/storefront/products/package_show.html.haml +49 -0
  44. data/app/views/workarea/storefront/products/templates/_family.html.haml +42 -0
  45. data/app/views/workarea/storefront/products/templates/_package.html.haml +36 -0
  46. data/app/workers/workarea/update_package_products.rb +21 -0
  47. data/bin/rails +16 -0
  48. data/config/initializers/appends.rb +31 -0
  49. data/config/initializers/configuration.rb +6 -0
  50. data/config/initializers/seeds.rb +1 -0
  51. data/config/locales/en.yml +45 -0
  52. data/config/routes.rb +30 -0
  53. data/lib/tasks/sample_data.rake +16 -0
  54. data/lib/workarea/package_products.rb +10 -0
  55. data/lib/workarea/package_products/engine.rb +8 -0
  56. data/lib/workarea/package_products/version.rb +5 -0
  57. data/test/dummy/Rakefile +6 -0
  58. data/test/dummy/app/assets/config/manifest.js +4 -0
  59. data/test/dummy/app/assets/images/.keep +0 -0
  60. data/test/dummy/app/assets/javascripts/application.js +13 -0
  61. data/test/dummy/app/assets/stylesheets/application.css +15 -0
  62. data/test/dummy/app/controllers/application_controller.rb +3 -0
  63. data/test/dummy/app/controllers/concerns/.keep +0 -0
  64. data/test/dummy/app/helpers/application_helper.rb +2 -0
  65. data/test/dummy/app/jobs/application_job.rb +2 -0
  66. data/test/dummy/app/mailers/application_mailer.rb +4 -0
  67. data/test/dummy/app/models/concerns/.keep +0 -0
  68. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  69. data/test/dummy/app/views/layouts/mailer.html.erb +13 -0
  70. data/test/dummy/app/views/layouts/mailer.text.erb +1 -0
  71. data/test/dummy/bin/bundle +3 -0
  72. data/test/dummy/bin/rails +4 -0
  73. data/test/dummy/bin/rake +4 -0
  74. data/test/dummy/bin/setup +34 -0
  75. data/test/dummy/bin/update +29 -0
  76. data/test/dummy/config.ru +5 -0
  77. data/test/dummy/config/application.rb +18 -0
  78. data/test/dummy/config/boot.rb +5 -0
  79. data/test/dummy/config/cable.yml +9 -0
  80. data/test/dummy/config/environment.rb +5 -0
  81. data/test/dummy/config/environments/development.rb +54 -0
  82. data/test/dummy/config/environments/production.rb +83 -0
  83. data/test/dummy/config/environments/test.rb +43 -0
  84. data/test/dummy/config/initializers/application_controller_renderer.rb +6 -0
  85. data/test/dummy/config/initializers/assets.rb +11 -0
  86. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  87. data/test/dummy/config/initializers/cookies_serializer.rb +5 -0
  88. data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  89. data/test/dummy/config/initializers/inflections.rb +16 -0
  90. data/test/dummy/config/initializers/mime_types.rb +4 -0
  91. data/test/dummy/config/initializers/session_store.rb +3 -0
  92. data/test/dummy/config/initializers/workarea.rb +5 -0
  93. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  94. data/test/dummy/config/locales/en.yml +23 -0
  95. data/test/dummy/config/puma.rb +47 -0
  96. data/test/dummy/config/routes.rb +5 -0
  97. data/test/dummy/config/secrets.yml +22 -0
  98. data/test/dummy/db/seeds.rb +2 -0
  99. data/test/dummy/lib/assets/.keep +0 -0
  100. data/test/dummy/log/.keep +0 -0
  101. data/test/dummy/public/404.html +67 -0
  102. data/test/dummy/public/422.html +67 -0
  103. data/test/dummy/public/500.html +66 -0
  104. data/test/dummy/public/apple-touch-icon-precomposed.png +0 -0
  105. data/test/dummy/public/apple-touch-icon.png +0 -0
  106. data/test/dummy/public/favicon.ico +1 -0
  107. data/test/integration/workarea/admin/create_catalog_package_products_integration_test.rb +139 -0
  108. data/test/integration/workarea/storefront/package_cart_items_integration_test.rb +47 -0
  109. data/test/integration/workarea/storefront/products_integration_test.decorator +19 -0
  110. data/test/models/workarea/catalog/package_product_test.rb +68 -0
  111. data/test/models/workarea/search/storefront/package_product_test.rb +44 -0
  112. data/test/queries/workarea/search/product_entries_test.decorator +15 -0
  113. data/test/services/workarea/add_package_to_cart_test.rb +46 -0
  114. data/test/system/workarea/admin/activity_system_test.decorator +53 -0
  115. data/test/system/workarea/admin/package_product_copy_system_test.rb +27 -0
  116. data/test/system/workarea/admin/package_products_system_test.rb +101 -0
  117. data/test/system/workarea/admin/product_copy_system_test.decorator +28 -0
  118. data/test/system/workarea/admin/products_system_test.decorator +69 -0
  119. data/test/system/workarea/storefront/categories_with_packages_system_test.rb +172 -0
  120. data/test/system/workarea/storefront/family_product_system_test.rb +58 -0
  121. data/test/system/workarea/storefront/package_product_system_test.rb +42 -0
  122. data/test/test_helper.rb +10 -0
  123. data/test/view_models/workarea/admin/package_product_view_model_test.rb +41 -0
  124. data/test/view_models/workarea/storefront/package_product_view_model_test.rb +27 -0
  125. data/test/view_models/workarea/storefront/package_templates/package_view_model_test.rb +34 -0
  126. data/test/workers/workarea/update_package_products_test.rb +27 -0
  127. data/workarea-package_products.gemspec +24 -0
  128. metadata +189 -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,16 @@
1
+ source 'https://rubygems.org'
2
+ git_source(:github) { |repo| "git@github.com:#{repo}.git" }
3
+
4
+ # Declare your gem's dependencies in content_search.gemspec.
5
+ # Bundler will treat runtime dependencies like base dependencies, and
6
+ # development dependencies will be added by default to the :development group.
7
+ gemspec
8
+ # Declare any dependencies that are still in development here instead of in
9
+ # your gemspec. These might include edge Rails or gems from your path or
10
+ # Git. Remember to move these dependencies to your gemspec before releasing
11
+ # your gem to rubygems.org.
12
+
13
+ # To use a debugger
14
+ # gem 'byebug', group: [:development, :test]
15
+ #
16
+ gem 'workarea', '>= 3.4.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,40 @@
1
+ Workarea Package Products
2
+ ================================================================================
3
+
4
+ A Workarea Commerce plugin that adds support for package products. Package products are a group of products grouped together and displayed on a single product detail page. This enables your storefront to display related items together and offer an easy way to quickly add all the items to cart.
5
+
6
+ Overview
7
+ --------------------------------------------------------------------------------
8
+
9
+ * Adds the ability to associate products through a package product in the admin
10
+ * Adds a custom package product creation workflow to the admin
11
+ * Adds a `package` product template for the storefront that displays all the packaged products together while still allowing separate add to cart buttons for each product
12
+ * Adds a `family` product template for the storefront that displays all the packaged products together, allows selecting multiple products, and adding them all to a cart at the same time
13
+
14
+ Getting Started
15
+ --------------------------------------------------------------------------------
16
+
17
+ Add the gem to your application's Gemfile:
18
+
19
+ ```ruby
20
+ # ...
21
+ gem 'workarea-package_products'
22
+ # ...
23
+ ```
24
+
25
+ Update your application's bundle.
26
+
27
+ ```bash
28
+ cd path/to/application
29
+ bundle
30
+ ```
31
+
32
+ Workarea Commerce Documentation
33
+ --------------------------------------------------------------------------------
34
+
35
+ See [https://developer.workarea.com](https://developer.workarea.com) for Workarea Commerce documentation.
36
+
37
+ License
38
+ --------------------------------------------------------------------------------
39
+
40
+ Workarea Package Products is released under the [Business Software License](LICENSE)
@@ -0,0 +1,52 @@
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
+
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = 'rdoc'
11
+ rdoc.title = 'Tasker'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.md')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+ APP_RAKEFILE = File.expand_path('../test/dummy/Rakefile', __FILE__)
18
+ load 'rails/tasks/engine.rake'
19
+ load 'rails/tasks/statistics.rake'
20
+ load 'workarea/changelog.rake'
21
+
22
+ require 'rake/testtask'
23
+
24
+ Rake::TestTask.new(:test) do |t|
25
+ t.libs << 'lib'
26
+ t.libs << 'test'
27
+ t.pattern = 'test/**/*_test.rb'
28
+ t.verbose = false
29
+ end
30
+
31
+ task default: :test
32
+
33
+ $LOAD_PATH.unshift File.expand_path('../lib', __FILE__)
34
+ require 'workarea/package_products/version'
35
+
36
+ desc "Release version #{Workarea::PackageProducts::VERSION} of the gem"
37
+ task :release do
38
+ host = "https://#{ENV['BUNDLE_GEMS__WEBLINC__COM']}@gems.weblinc.com"
39
+
40
+ #Rake::Task['workarea:changelog'].execute
41
+ #system 'git add CHANGELOG.md'
42
+ #system 'git commit -m "Update CHANGELOG"'
43
+ #system 'git push origin HEAD'
44
+
45
+ system "git tag -a v#{Workarea::PackageProducts::VERSION} -m 'Tagging #{Workarea::PackageProducts::VERSION}'"
46
+ system 'git push --tags'
47
+
48
+ system 'gem build workarea-package_products.gemspec'
49
+ system "gem push workarea-package_products-#{Workarea::PackageProducts::VERSION}.gem"
50
+ system "gem push workarea-package_products-#{Workarea::PackageProducts::VERSION}.gem --host #{host}"
51
+ system "rm workarea-package_products-#{Workarea::PackageProducts::VERSION}.gem"
52
+ end
@@ -0,0 +1,83 @@
1
+ /**
2
+ * @namespace WORKAREA.familyProductAddToCart
3
+ */
4
+ WORKAREA.registerModule('familyProductAddToCart', (function () {
5
+ 'use strict';
6
+
7
+ var sendRequest = function($form, $products) {
8
+ var payload = {
9
+ 'product_id': $form.find('[name="product_id"]').val()
10
+ };
11
+
12
+ payload.items = _.map($products, function(product) {
13
+ var $productForm = $(product).find('form');
14
+
15
+ return _.reduce($productForm.find(':input'), function(inputs, input){
16
+ var $input = $(input),
17
+ name = $input.attr('name');
18
+
19
+ if (name !== 'authenticity_token' && name !== 'utf8') {
20
+ inputs[name] = $input.val();
21
+ }
22
+
23
+ return inputs;
24
+ }, {});
25
+ });
26
+
27
+ return $.post($form.attr('action'), payload);
28
+ },
29
+
30
+ addItemsToCart = function($form, event) {
31
+ var promise = null,
32
+ options = $form.data('dialog'),
33
+ $selectedProducts = $('[id^="family_product_"]:checked').next('[data-packaged-product-id]'),
34
+ isValid = _.reduce($selectedProducts, function(valid, product) {
35
+ var $product = $(product),
36
+ result = $product.find('form').valid();
37
+
38
+ return valid ? result : valid;
39
+ }, true);
40
+
41
+ event.preventDefault();
42
+
43
+ if (isValid && !_.isEmpty($selectedProducts)) {
44
+ promise = sendRequest($form, $selectedProducts);
45
+ WORKAREA.dialog.createFromPromise(promise, options.dialogOptions);
46
+ }
47
+ },
48
+
49
+ initFamilyProducts = function($products) {
50
+ $products.each(function(index, product) {
51
+ var $product = $(product),
52
+ productId = $product.data('packagedProductId'),
53
+ checkboxTemplate = JST['workarea/storefront/package_products/templates/family_add_to_cart_checkbox'];
54
+
55
+ $(checkboxTemplate({ id: productId })).insertBefore($product);
56
+ });
57
+ },
58
+
59
+ bindAddToCart = function($form) {
60
+ $form.on('submit', _.partial(addItemsToCart, $form));
61
+ },
62
+
63
+ /**
64
+ * @method
65
+ * @name init
66
+ * @memberof WORKAREA.familyProductAddToCart
67
+ */
68
+ init = function ($scope) {
69
+ var $addToCartForm = $('.product-details--family .product-details__add-to-cart-form', $scope),
70
+ $products = $('[data-packaged-product-id]', $scope);
71
+
72
+ if (_.isEmpty($addToCartForm) || _.isEmpty($products)) {
73
+ return;
74
+ }
75
+
76
+ initFamilyProducts($products);
77
+ bindAddToCart($addToCartForm);
78
+ };
79
+
80
+ return {
81
+ init: init
82
+ };
83
+ }()));
@@ -0,0 +1 @@
1
+ <input type="checkbox" id="family_product_<%= id %>" value="1" />
@@ -0,0 +1,7 @@
1
+ /*------------------------------------*\
2
+ #PRODUCT-CARDS
3
+ \*------------------------------------*/
4
+
5
+ .product-cards--family, .product-cards--package {
6
+ .card--variants { display: none; }
7
+ }
@@ -0,0 +1,11 @@
1
+ /*------------------------------------*\
2
+ #PRODUCT-DETAIL-PACKAGED-PRODUCTS
3
+ \*------------------------------------*/
4
+
5
+ .product-detail-packaged-products {}
6
+
7
+ .product-detail-packaged-products--family {
8
+ .product-details__add-to-cart-action {
9
+ display: none;
10
+ }
11
+ }
@@ -0,0 +1,150 @@
1
+ module Workarea
2
+ module Admin
3
+ class CreateCatalogPackageProductsController < CreateCatalogProductsController
4
+ required_permissions :catalog
5
+ before_action :find_product
6
+
7
+ def index
8
+ @product.template = 'package'
9
+ render :setup
10
+ end
11
+
12
+ def create
13
+ @product.attributes = params[:product]
14
+
15
+ if @product.save
16
+ flash[:success] = t('workarea.admin.create_catalog_products.flash_messages.saved')
17
+ redirect_to packaged_products_create_catalog_package_product_path(@product)
18
+ else
19
+ render :setup, status: :unprocessable_entity
20
+ end
21
+ end
22
+
23
+ def edit
24
+ render :setup
25
+ end
26
+
27
+ def packaged_products
28
+ options = view_model_options
29
+ options[:q] ||= ''
30
+ options[:q] += " -#{Workarea.config.package_product_templates.join(',')}"
31
+
32
+ search = Search::AdminProducts.new(options)
33
+ @search = SearchViewModel.new(search, options)
34
+ end
35
+
36
+ def images
37
+ end
38
+
39
+ def save_images
40
+ if params[:updates].present?
41
+ params[:updates].each do |id, attrs|
42
+ image = @product.images.find(id)
43
+ image.attributes = attrs
44
+ image.save!
45
+ end
46
+ end
47
+
48
+ if params[:images].present?
49
+ params[:images].each do |attrs|
50
+ @product.images.create!(attrs) if attrs[:image].present?
51
+ end
52
+ end
53
+
54
+ flash[:success] = t('workarea.admin.create_catalog_products.flash_messages.saved')
55
+ redirect_to details_create_catalog_package_product_path(@product)
56
+ end
57
+
58
+ def details
59
+ @filters = @product.filters.presence || build_filters_from_products
60
+ @details = @product.details.presence || build_details_from_products
61
+ end
62
+
63
+ def save_details
64
+ HashUpdate.new(updates: params[:filters]).apply(@product.filters)
65
+ HashUpdate.new(updates: params[:details]).apply(@product.details)
66
+ @product.save!
67
+
68
+ flash[:success] = t('workarea.admin.create_catalog_products.flash_messages.saved')
69
+ redirect_to content_create_catalog_package_product_path(@product)
70
+ end
71
+
72
+ def content
73
+ end
74
+
75
+ def save_content
76
+ @product.update_attributes!(params[:product])
77
+ flash[:success] = t('workarea.admin.content_blocks.flash_messages.saved')
78
+ redirect_to categorization_create_catalog_package_product_path(@product)
79
+ end
80
+
81
+ def categorization
82
+ end
83
+
84
+ def save_categorization
85
+ params[:category_ids].reject(&:blank?).each do |id|
86
+ Catalog::Category.find(id).add_product(@product.id)
87
+ end
88
+
89
+ flash[:success] = t('workarea.admin.create_catalog_products.flash_messages.saved')
90
+ render :categorization
91
+ end
92
+
93
+ def publish
94
+ end
95
+
96
+ def save_publish
97
+ publish = SavePublishing.new(@product, params)
98
+
99
+ if publish.perform
100
+ flash[:success] = t('workarea.admin.create_catalog_products.flash_messages.product_created')
101
+ redirect_to catalog_product_path(@product)
102
+ else
103
+ flash[:error] = publish.errors.full_messages
104
+ render :publish
105
+ end
106
+ end
107
+
108
+ private
109
+
110
+ def find_product
111
+ model = if params[:id].present?
112
+ Catalog::Product.find_by(slug: params[:id])
113
+ else
114
+ Catalog::Product.new(params[:product])
115
+ end
116
+
117
+ @product = ProductViewModel.new(model, view_model_options)
118
+ end
119
+
120
+ def standard_template_types
121
+ Workarea.config.product_templates -
122
+ Workarea.config.package_product_templates
123
+ end
124
+
125
+ def build_filters_from_products
126
+ @product.packaged_products.each_with_object({}) do |product, result|
127
+ product.variants.each do |variant|
128
+ variant.details.each do |name, value|
129
+ result[name] ||= []
130
+ result[name] << value unless result[name].include?(value)
131
+ end
132
+ end
133
+
134
+ result
135
+ end
136
+ end
137
+
138
+ def build_details_from_products
139
+ @product.packaged_products.reduce({}) do |result, product|
140
+ product.details.each do |name, value|
141
+ result[name] ||= []
142
+ result[name] += Array.wrap(value)
143
+ result[name].uniq!
144
+ result
145
+ end
146
+ end
147
+ end
148
+ end
149
+ end
150
+ end
@@ -0,0 +1,25 @@
1
+ module Workarea
2
+ decorate Admin::CreateCatalogProductsController, with: :package_products do
3
+ def index
4
+ if params[:product_type] == 'package'
5
+ redirect_to create_catalog_package_products_path
6
+ elsif params[:product_type] == 'standard'
7
+ super
8
+ else
9
+ render :select
10
+ end
11
+ end
12
+
13
+ def edit
14
+ if @product.package?
15
+ flash.keep
16
+ redirect_to edit_create_catalog_package_product_path(
17
+ @product,
18
+ continue: params[:continue]
19
+ )
20
+ else
21
+ super
22
+ end
23
+ end
24
+ end
25
+ end