spree_only_one_line_item_per_order 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: cf0b18f02e744c33735400bee5d469c956be3b10ab93bf6b425e9235daf106a5
4
+ data.tar.gz: d1f04eecfdbb7413460e07833f5bf11849645593e31b217c2973c3dea8333df1
5
+ SHA512:
6
+ metadata.gz: f68b33374cc57a4c3a1e22d259ce8dc3f3762cd789e0d185bd1c87e9af24c37f45321cb1991028a6190e5574b76e40e72ee4232abd10bf12a93a96e6d467c981
7
+ data.tar.gz: 559eee6659e15c7d86f3398bd9ca3f48c5b5a30b90d3a9b77b1fd0c07360e99d914881a55724b67217eccfa8c368f7ee38182f2c85bba94981569da0fdb18a5c
data/.gitignore ADDED
@@ -0,0 +1,23 @@
1
+ \#*
2
+ *~
3
+ .#*
4
+ .DS_Store
5
+ .idea
6
+ .localeapp/locales
7
+ .project
8
+ .vscode
9
+ coverage
10
+ default
11
+ Gemfile.lock
12
+ tmp
13
+ nbproject
14
+ pkg
15
+ *.sw?
16
+ spec/dummy
17
+ .rvmrc
18
+ .sass-cache
19
+ public/spree
20
+ .ruby-version
21
+ .ruby-gemset
22
+ *.gem
23
+ */*.gem
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --color
2
+ -r spec_helper
3
+ -f documentation
data/Gemfile ADDED
@@ -0,0 +1,12 @@
1
+ source 'https://rubygems.org'
2
+
3
+ git_source(:github) do |repo_name|
4
+ repo_name = "#{repo_name}/#{repo_name}" unless repo_name.include?('/')
5
+ "https://github.com/#{repo_name}.git"
6
+ end
7
+
8
+ gem 'spree' # , github: 'spree/spree', branch: 'main'
9
+ # gem 'spree_backend', github: 'spree/spree', branch: 'main'
10
+ gem 'rails-controller-testing'
11
+
12
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,26 @@
1
+ Copyright (c) 2021 ROUTE06, Inc.
2
+ All rights reserved.
3
+
4
+ Redistribution and use in source and binary forms, with or without modification,
5
+ are permitted provided that the following conditions are met:
6
+
7
+ * Redistributions of source code must retain the above copyright notice,
8
+ this list of conditions and the following disclaimer.
9
+ * Redistributions in binary form must reproduce the above copyright notice,
10
+ this list of conditions and the following disclaimer in the documentation
11
+ and/or other materials provided with the distribution.
12
+ * Neither the name Spree nor the names of its contributors may be used to
13
+ endorse or promote products derived from this software without specific
14
+ prior written permission.
15
+
16
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17
+ "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19
+ A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
20
+ CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
21
+ EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
22
+ PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
23
+ PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
24
+ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
25
+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
data/README.md ADDED
@@ -0,0 +1,54 @@
1
+ # SpreeOnlyOneLineItemPerOrder
2
+
3
+ It is a [Spree](https://github.com/spree/spree) extension that realizes "one type and one item can be added to an order".
4
+
5
+ ## Installation
6
+
7
+ 1. Add this extension to your Gemfile with this line:
8
+
9
+ ```ruby
10
+ gem 'spree_only_one_line_item_per_order'
11
+ ```
12
+
13
+ 2. Install the gem using Bundler
14
+
15
+ ```ruby
16
+ bundle install
17
+ ```
18
+
19
+ 3. Copy & run migrations
20
+
21
+ ```ruby
22
+ bundle exec rails g spree_only_one_line_item_per_order:install
23
+ ```
24
+
25
+ 4. Restart your server
26
+
27
+ If your server was running, restart it so that it can find the assets properly.
28
+
29
+ ## Testing
30
+
31
+ First bundle your dependencies, then run `rake`. `rake` will default to building the dummy app if it does not exist, then it will run specs. The dummy app can be regenerated by using `rake test_app`.
32
+
33
+ ```shell
34
+ bundle update
35
+ bundle exec rake
36
+ ```
37
+
38
+ When testing your applications integration with this extension you may use it's factories.
39
+ Simply add this require statement to your spec_helper:
40
+
41
+ ```ruby
42
+ require 'spree_only_one_line_item_per_order/factories'
43
+ ```
44
+
45
+ ## Releasing
46
+
47
+ ```shell
48
+ bundle exec gem bump -p -t
49
+ bundle exec gem release
50
+ ```
51
+
52
+ For more options please see [gem-release REAMDE](https://github.com/svenfuchs/gem-release)
53
+
54
+ Copyright (c) 2021 ROUTE06, Inc., released under the New BSD License
data/Rakefile ADDED
@@ -0,0 +1,21 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
3
+
4
+ require 'rspec/core/rake_task'
5
+ require 'spree/testing_support/extension_rake'
6
+
7
+ RSpec::Core::RakeTask.new
8
+
9
+ task :default do
10
+ if Dir['spec/dummy'].empty?
11
+ Rake::Task[:test_app].invoke
12
+ Dir.chdir('../../')
13
+ end
14
+ Rake::Task[:spec].invoke
15
+ end
16
+
17
+ desc 'Generates a dummy app for testing'
18
+ task :test_app do
19
+ ENV['LIB_NAME'] = 'spree_only_one_line_item_per_order'
20
+ Rake::Task['extension:test_app'].invoke
21
+ end
data/app/.gitkeep ADDED
File without changes
File without changes
@@ -0,0 +1,7 @@
1
+ module SpreeOnlyOneLineItemPerOrder::Api::V2::Storefront::CartControllerDecorator
2
+ def set_quantity
3
+ render json: { error: "Unprocessable entity." }, status: 422
4
+ end
5
+ end
6
+
7
+ Spree::Api::V2::Storefront::CartController.prepend(SpreeOnlyOneLineItemPerOrder::Api::V2::Storefront::CartControllerDecorator) unless Spree::Api::V2::Storefront::CartController.included_modules.include?(SpreeOnlyOneLineItemPerOrder::Api::V2::Storefront::CartControllerDecorator)
File without changes
@@ -0,0 +1,13 @@
1
+ module SpreeOnlyOneLineItemPerOrder
2
+ class Configuration < Spree::Preferences::Configuration
3
+
4
+ # Some example preferences are shown below, for more information visit:
5
+ # https://dev-docs.spreecommerce.org/internals/preferences
6
+
7
+ preference :enabled, :boolean, default: true
8
+ # preference :dark_chocolate, :boolean, default: true
9
+ # preference :color, :string, default: 'Red'
10
+ # preference :favorite_number, :integer
11
+ # preference :supported_locales, :array, default: [:en]
12
+ end
13
+ end
File without changes
File without changes
@@ -0,0 +1,22 @@
1
+ module Spree
2
+ module Cart
3
+ class AddItemIfEmpty < AddItem
4
+ private
5
+
6
+ def add_to_line_item(order:, variant:, quantity: nil, options: {})
7
+ options ||= {}
8
+ quantity = options[:quantity] if options[:quantity]
9
+ if quantity && quantity.to_i != 1
10
+ return failure(order, "line_item quantity allowed only 1")
11
+ end
12
+
13
+ line_item = order.line_items.first
14
+ if line_item
15
+ return failure(order, "#{line_item.product&.name} is already in cart")
16
+ end
17
+
18
+ super
19
+ end
20
+ end
21
+ end
22
+ end
data/bin/rails ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env ruby
2
+ # This command will automatically be run when you run "rails" from the root of your extension
3
+
4
+ ENGINE_ROOT = File.expand_path('../..', __FILE__)
5
+ ENGINE_PATH = File.expand_path('../../lib/spree_only_one_line_item_per_order/engine', __FILE__)
6
+
7
+ require 'rails/all'
8
+ require 'rails/engine/commands'
@@ -0,0 +1,5 @@
1
+ # Sample localization file for English. Add more files in this directory for other locales.
2
+ # See https://github.com/svenfuchs/rails-i18n/tree/master/rails%2Flocale for starting points.
3
+
4
+ en:
5
+ hello: "Hello world"
data/config/routes.rb ADDED
@@ -0,0 +1,3 @@
1
+ Spree::Core::Engine.add_routes do
2
+ # Add your extension routes here
3
+ end
@@ -0,0 +1,20 @@
1
+ module SpreeOnlyOneLineItemPerOrder
2
+ module Generators
3
+ class InstallGenerator < Rails::Generators::Base
4
+ class_option :migrate, type: :boolean, default: true
5
+
6
+ def add_migrations
7
+ run 'bundle exec rake railties:install:migrations FROM=spree_only_one_line_item_per_order'
8
+ end
9
+
10
+ def run_migrations
11
+ run_migrations = options[:migrate] || ['', 'y', 'Y'].include?(ask('Would you like to run the migrations now? [Y/n]'))
12
+ if run_migrations
13
+ run 'bundle exec rails db:migrate'
14
+ else
15
+ puts 'Skipping rails db:migrate, don\'t forget to run it!'
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,26 @@
1
+ module SpreeOnlyOneLineItemPerOrder
2
+ class Engine < Rails::Engine
3
+ require 'spree/core'
4
+ isolate_namespace Spree
5
+ engine_name 'spree_only_one_line_item_per_order'
6
+
7
+ # use rspec for tests
8
+ config.generators do |g|
9
+ g.test_framework :rspec
10
+ end
11
+
12
+ initializer 'spree_only_one_line_item_per_order.environment', before: :load_config_initializers do |_app|
13
+ SpreeOnlyOneLineItemPerOrder::Config = SpreeOnlyOneLineItemPerOrder::Configuration.new
14
+ end
15
+
16
+ def self.activate
17
+ Dir.glob(File.join(File.dirname(__FILE__), '../../app/**/*_decorator*.rb')) do |c|
18
+ Rails.configuration.cache_classes ? require(c) : load(c)
19
+ end
20
+
21
+ Spree::Api::Dependencies.storefront_cart_add_item_service = 'Spree::Cart::AddItemIfEmpty'
22
+ end
23
+
24
+ config.to_prepare(&method(:activate).to_proc)
25
+ end
26
+ end
@@ -0,0 +1,6 @@
1
+ FactoryBot.define do
2
+ # Define your Spree extensions Factories within this file to enable applications, and other extensions to use and override them.
3
+ #
4
+ # Example adding this to your spec_helper will load these Factories for use:
5
+ # require 'spree_only_one_line_item_per_order/factories'
6
+ end
@@ -0,0 +1,11 @@
1
+ module SpreeOnlyOneLineItemPerOrder
2
+ VERSION = '0.0.2'.freeze
3
+
4
+ module_function
5
+
6
+ # Returns the version of the currently loaded SpreeOnlyOneLineItemPerOrder as a
7
+ # <tt>Gem::Version</tt>.
8
+ def version
9
+ Gem::Version.new VERSION
10
+ end
11
+ end
@@ -0,0 +1,4 @@
1
+ require 'spree_core'
2
+ require 'spree_extension'
3
+ require 'spree_only_one_line_item_per_order/engine'
4
+ require 'spree_only_one_line_item_per_order/version'
@@ -0,0 +1,29 @@
1
+ # encoding: UTF-8
2
+ lib = File.expand_path('../lib/', __FILE__)
3
+ $LOAD_PATH.unshift lib unless $LOAD_PATH.include?(lib)
4
+
5
+ require 'spree_only_one_line_item_per_order/version'
6
+
7
+ Gem::Specification.new do |s|
8
+ s.platform = Gem::Platform::RUBY
9
+ s.name = 'spree_only_one_line_item_per_order'
10
+ s.version = SpreeOnlyOneLineItemPerOrder.version
11
+ s.summary = 'It is a Spree extension that realizes "one type and one item can be added to an order"'
12
+ s.description = ''
13
+ s.required_ruby_version = '>= 2.5'
14
+
15
+ s.author = 'ROUTE06'
16
+ s.email = 'development+rubygems@route06.co.jp'
17
+ s.homepage = 'https://github.com/route06/spree_only_one_line_item_per_order'
18
+ s.license = 'BSD-3-Clause'
19
+
20
+ s.files = `git ls-files`.split("\n").reject { |f| f.match(/^spec/) && !f.match(/^spec\/fixtures/) }
21
+ s.require_path = 'lib'
22
+ s.requirements << 'none'
23
+
24
+ s.add_dependency 'spree', '>= 4.3.0'
25
+ s.add_dependency 'spree_extension'
26
+
27
+ s.add_development_dependency 'actionmailer' # needed for running rspec
28
+ s.add_development_dependency 'spree_dev_tools'
29
+ end
metadata ADDED
@@ -0,0 +1,123 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: spree_only_one_line_item_per_order
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - ROUTE06
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2021-12-23 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: spree
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 4.3.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 4.3.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: spree_extension
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: actionmailer
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: spree_dev_tools
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: ''
70
+ email: development+rubygems@route06.co.jp
71
+ executables: []
72
+ extensions: []
73
+ extra_rdoc_files: []
74
+ files:
75
+ - ".gitignore"
76
+ - ".rspec"
77
+ - Gemfile
78
+ - LICENSE
79
+ - README.md
80
+ - Rakefile
81
+ - app/.gitkeep
82
+ - app/controllers/.gitkeep
83
+ - app/controllers/spree_only_one_line_item_per_order/api/v2/storefront/cart_controller_decorator.rb
84
+ - app/models/.gitkeep
85
+ - app/models/spree_only_one_line_item_per_order/configuration.rb
86
+ - app/serializers/.gitkeep
87
+ - app/services/.gitkeep
88
+ - app/services/spree/cart/add_item_if_empty.rb
89
+ - bin/rails
90
+ - config/locales/en.yml
91
+ - config/routes.rb
92
+ - lib/generators/spree_only_one_line_item_per_order/install/install_generator.rb
93
+ - lib/spree_only_one_line_item_per_order.rb
94
+ - lib/spree_only_one_line_item_per_order/engine.rb
95
+ - lib/spree_only_one_line_item_per_order/factories.rb
96
+ - lib/spree_only_one_line_item_per_order/version.rb
97
+ - spree_only_one_line_item_per_order.gemspec
98
+ homepage: https://github.com/route06/spree_only_one_line_item_per_order
99
+ licenses:
100
+ - BSD-3-Clause
101
+ metadata: {}
102
+ post_install_message:
103
+ rdoc_options: []
104
+ require_paths:
105
+ - lib
106
+ required_ruby_version: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '2.5'
111
+ required_rubygems_version: !ruby/object:Gem::Requirement
112
+ requirements:
113
+ - - ">="
114
+ - !ruby/object:Gem::Version
115
+ version: '0'
116
+ requirements:
117
+ - none
118
+ rubygems_version: 3.1.2
119
+ signing_key:
120
+ specification_version: 4
121
+ summary: It is a Spree extension that realizes "one type and one item can be added
122
+ to an order"
123
+ test_files: []