solidus_simple_sale_price 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 5f6b45abb7ef95302cd8514326df022eefee06a726c2d2f867a5f67eef0ba719
4
+ data.tar.gz: 63c92ac7cd485f8b7e4ba6441397abe7114e5461f7e98ead01772b18eba106ed
5
+ SHA512:
6
+ metadata.gz: 5a1811fa669cf1c32d4c3aef88d444712c335f238a0275a03c9a8ba774d60832d091464b7af124cbbdafcd28accf95c835575700d9831278139df698ebb4b4e0
7
+ data.tar.gz: 067a2c21982980c5a0d9d45bba03cd1379836eb83a562a61216948473b0ccc0837cff577d8069a47c6d2b933f1d7f97a12e25d55a1c18b168456aa9d2941cf92
data/LICENSE ADDED
@@ -0,0 +1,26 @@
1
+ Copyright (c) 2018 Renuo AG
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.
@@ -0,0 +1,40 @@
1
+ # Simple Sale Price
2
+
3
+ This gem allows you to have one sale price per `Spree::Price`.
4
+
5
+ [![Build Status](https://semaphoreci.com/api/v1/renuo/solidus_simple_sale_price/branches/master/badge.svg)](https://semaphoreci.com/renuo/solidus_simple_sale_price)
6
+
7
+ Installation
8
+ ------------
9
+
10
+ Add solidus_simple_sale_price to your Gemfile:
11
+
12
+ ```ruby
13
+ gem 'solidus_simple_sale_price'
14
+ ```
15
+
16
+ Bundle your dependencies and run the installation generator:
17
+
18
+ ```shell
19
+ bundle
20
+ bundle exec rails g solidus_simple_sale_price:install
21
+ ```
22
+
23
+ Testing
24
+ -------
25
+
26
+ 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, and [Rubocop](https://github.com/bbatsov/rubocop) static code analysis. The dummy app can be regenerated by using `rake test_app`.
27
+
28
+ ```shell
29
+ bundle
30
+ bundle exec rake
31
+ ```
32
+
33
+ When testing your applications integration with this extension you may use it's factories.
34
+ Simply add this require statement to your spec_helper:
35
+
36
+ ```ruby
37
+ require 'solidus_simple_sale_price/factories'
38
+ ```
39
+
40
+ Copyright (c) 2018 [name of extension creator], released under the New BSD License
@@ -0,0 +1,30 @@
1
+ require 'bundler'
2
+
3
+ Bundler::GemHelper.install_tasks
4
+
5
+ begin
6
+ require 'spree/testing_support/extension_rake'
7
+ require 'rubocop/rake_task'
8
+ require 'rspec/core/rake_task'
9
+
10
+ RSpec::Core::RakeTask.new(:spec)
11
+
12
+ RuboCop::RakeTask.new
13
+
14
+ task default: %i[first_run rubocop spec]
15
+ rescue LoadError
16
+ # no rspec available
17
+ end
18
+
19
+ task :first_run do
20
+ if Dir['spec/dummy'].empty?
21
+ Rake::Task[:test_app].invoke
22
+ Dir.chdir('../../')
23
+ end
24
+ end
25
+
26
+ desc 'Generates a dummy app for testing'
27
+ task :test_app do
28
+ ENV['LIB_NAME'] = 'solidus_simple_sale_price'
29
+ Rake::Task['extension:test_app'].invoke
30
+ end
@@ -0,0 +1,15 @@
1
+ Spree::BaseHelper.class_eval do
2
+ def display_original_price(product_or_variant)
3
+ product_or_variant.original_price_in(current_currency).display_price.to_html
4
+ end
5
+
6
+ def display_discount_percent(product_or_variant, append_text = 'Off')
7
+ discount = product_or_variant.discount_percent_in current_currency
8
+
9
+ if discount.positive?
10
+ "#{number_to_percentage(discount, precision: 0)} #{append_text}"
11
+ else
12
+ ''
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,27 @@
1
+ Spree::Price.class_eval do
2
+ def original_amount
3
+ self[:amount]
4
+ end
5
+
6
+ def original_amount=(value)
7
+ self[:amount] = Spree::LocalizedNumber.parse(value)
8
+ end
9
+
10
+ def on_sale?
11
+ sale_amount.present? && sale_amount < original_amount
12
+ end
13
+
14
+ def amount
15
+ on_sale? ? sale_amount : original_amount
16
+ end
17
+
18
+ def price
19
+ amount
20
+ end
21
+
22
+ def discount_percent
23
+ return 0.0 unless original_amount.positive?
24
+ return 0.0 unless on_sale?
25
+ (1 - (sale_amount / original_amount)) * 100.0
26
+ end
27
+ end
@@ -0,0 +1,4 @@
1
+ Spree::Product.class_eval do
2
+ delegate :on_sale_in?, :sale_price_in, :original_price_in, :discount_percent_in,
3
+ :on_sale?, :sale_price, :original_price, :discount_percent, to: :master
4
+ end
@@ -0,0 +1,33 @@
1
+ Spree::Variant.class_eval do
2
+ delegate :on_sale?, :discount_percent, to: :default_price
3
+
4
+ def on_sale_in?(currency)
5
+ price_in_currency(currency).on_sale?
6
+ end
7
+
8
+ def sale_price
9
+ default_price.sale_amount
10
+ end
11
+
12
+ def original_price
13
+ default_price.original_amount
14
+ end
15
+
16
+ def sale_price_in(currency)
17
+ price = price_in_currency(currency)
18
+ Spree::Price.new variant_id: id, currency: currency, amount: price.sale_amount if price
19
+ end
20
+
21
+ def original_price_in(currency)
22
+ price = price_in_currency(currency)
23
+ Spree::Price.new variant_id: id, currency: currency, amount: price.original_amount if price
24
+ end
25
+
26
+ def discount_percent_in(currency)
27
+ price_in_currency(currency).discount_percent
28
+ end
29
+
30
+ def price_in_currency(currency)
31
+ currently_valid_prices.detect { |price| price.currency == currency }
32
+ end
33
+ end
@@ -0,0 +1,19 @@
1
+ Deface::Override.new(virtual_path: 'spree/admin/prices/_form',
2
+ name: 'edit_price_and_sale_price',
3
+ replace: "[data-hook='admin_product_price_form_amount']",
4
+ partial: 'spree/admin/sale_prices/form_field',
5
+ disabled: false)
6
+
7
+ Deface::Override.new(virtual_path: 'spree/admin/prices/_master_variant_table',
8
+ name: 'extend_price_table_with_original_and_sale_price_title',
9
+ replace: "[data-hook='master_prices_header'] > tr > th:nth-child(3)",
10
+ text: '<th><%= Spree::Price.human_attribute_name(:orginal_price) %></th>'\
11
+ '<th><%= Spree::Price.human_attribute_name(:sale_price) %></th>',
12
+ disabled: false)
13
+
14
+ Deface::Override.new(virtual_path: 'spree/admin/prices/_master_variant_table',
15
+ name: 'extend_price_table_with_original_and_sale_price_columns',
16
+ replace: "[data-hook='prices_row'] > td:nth-child(3)",
17
+ text: '<td><%= price.original_amount %></td>'\
18
+ '<td><%= price.sale_amount %></td>',
19
+ disabled: false)
@@ -0,0 +1,19 @@
1
+ <div data-hook="admin_product_price_form_amount" class="col-8">
2
+ <div class="row">
3
+ <div class="col-6">
4
+ <%= f.field_container :original_amount do %>
5
+ <%= f.label :price %>
6
+ <%= render "spree/admin/shared/number_with_currency", f: f, amount_attr: :original_amount, currency_attr: :currency %>
7
+ <% end %>
8
+ </div>
9
+
10
+ <div class="col-6">
11
+ <%= f.field_container :sale_amount do %>
12
+ <%= f.label :sale %>
13
+ <div>
14
+ <%= f.text_field :sale_amount, class: 'form-control number-with-currency-amount' %>
15
+ </div>
16
+ <% end %>
17
+ </div>
18
+ </div>
19
+ </div>
@@ -0,0 +1,12 @@
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
+ de:
5
+ sale_price: "Aktionspreis"
6
+ original_price: "Originalpreis (Standard Währung)"
7
+ product_sale_prices: "Aktionspreise des Produktes"
8
+ add_product_sale_prices: "Aktionspreise hinzufügen"
9
+ sale_price_amount: 'Wert'
10
+ sale_price_active: 'Aktiv'
11
+ sale_price_currency: "Währung"
12
+ sale_price_enabled: "Aktiviert"
@@ -0,0 +1,12 @@
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
+ sale_price: "Sale Price"
6
+ original_price: "Original Price (Standard Currency)"
7
+ product_sale_prices: "Product Sale Prices"
8
+ add_product_sale_prices: "Add Product Sale Price"
9
+ sale_price_amount: 'Amount'
10
+ sale_price_active: 'Active'
11
+ sale_price_currency: "Currency"
12
+ sale_price_enabled: "Enabled"
@@ -0,0 +1,7 @@
1
+ Spree::Core::Engine.routes.draw do
2
+ namespace :admin do
3
+ resources :products, only: [] do
4
+ resources :sale_prices
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,5 @@
1
+ class AddSaleAmountToPrices < ActiveRecord::Migration[5.1]
2
+ def change
3
+ add_column :spree_prices, :sale_amount, :decimal, precision: 10, scale: 2
4
+ end
5
+ end
@@ -0,0 +1,20 @@
1
+ module SolidusSimpleSalePrice
2
+ module Generators
3
+ class InstallGenerator < Rails::Generators::Base
4
+ class_option :auto_run_migrations, type: :boolean, default: false
5
+
6
+ def add_migrations
7
+ run 'bundle exec rake railties:install:migrations FROM=solidus_simple_sale_price'
8
+ end
9
+
10
+ def run_migrations
11
+ run_migrations = options[:auto_run_migrations] || ['', 'y', 'Y'].include?(ask('Would you like to run the migrations now? [Y/n]'))
12
+ if run_migrations
13
+ run 'bundle exec rake db:migrate'
14
+ else
15
+ puts 'Skipping rake db:migrate, don\'t forget to run it!'
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,2 @@
1
+ require 'solidus_core'
2
+ require 'solidus_simple_sale_price/engine'
@@ -0,0 +1,20 @@
1
+ module SolidusSimpleSalePrice
2
+ class Engine < Rails::Engine
3
+ require 'spree/core'
4
+ isolate_namespace Spree
5
+ engine_name 'solidus_simple_sale_price'
6
+
7
+ # use rspec for tests
8
+ config.generators do |g|
9
+ g.test_framework :rspec
10
+ end
11
+
12
+ def self.activate
13
+ Dir.glob(File.join(File.dirname(__FILE__), '../../app/**/*_decorator*.rb')) do |c|
14
+ Rails.configuration.cache_classes ? require(c) : load(c)
15
+ end
16
+ end
17
+
18
+ config.to_prepare(&method(:activate).to_proc)
19
+ end
20
+ end
@@ -0,0 +1,23 @@
1
+ FactoryBot.define do
2
+ # Define your Spree extensions Factories within this file to enable applications,
3
+ # and other extensions to use and override them.
4
+ #
5
+ # Example adding this to your spec_helper will load these Factories for use:
6
+ # require 'solidus_simple_sale_price/factories'
7
+
8
+ factory :price_on_sale, parent: :price do
9
+ sale_amount 10.90
10
+ end
11
+
12
+ factory :international_variant, parent: :variant do
13
+ transient do
14
+ price_currencies %w[KES UAH AUD]
15
+ end
16
+
17
+ after(:create) do |variant, evaluator|
18
+ evaluator.price_currencies.each do |currency|
19
+ create(:price, variant: variant, currency: currency)
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,3 @@
1
+ module SolidusSimpleSalePrice
2
+ VERSION = '0.0.2'.freeze
3
+ end
metadata ADDED
@@ -0,0 +1,235 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: solidus_simple_sale_price
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Josua Schmid
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-06-21 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: solidus_core
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '3'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ version: '1.3'
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '3'
33
+ - !ruby/object:Gem::Dependency
34
+ name: capybara
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ type: :development
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ - !ruby/object:Gem::Dependency
48
+ name: coffee-rails
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ - !ruby/object:Gem::Dependency
62
+ name: database_cleaner
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ - !ruby/object:Gem::Dependency
76
+ name: factory_bot
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
82
+ type: :development
83
+ prerelease: false
84
+ version_requirements: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ - !ruby/object:Gem::Dependency
90
+ name: poltergeist
91
+ requirement: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ type: :development
97
+ prerelease: false
98
+ version_requirements: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ - !ruby/object:Gem::Dependency
104
+ name: rspec-rails
105
+ requirement: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ type: :development
111
+ prerelease: false
112
+ version_requirements: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - ">="
115
+ - !ruby/object:Gem::Version
116
+ version: '0'
117
+ - !ruby/object:Gem::Dependency
118
+ name: rubocop
119
+ requirement: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - '='
122
+ - !ruby/object:Gem::Version
123
+ version: 0.54.0
124
+ type: :development
125
+ prerelease: false
126
+ version_requirements: !ruby/object:Gem::Requirement
127
+ requirements:
128
+ - - '='
129
+ - !ruby/object:Gem::Version
130
+ version: 0.54.0
131
+ - !ruby/object:Gem::Dependency
132
+ name: rubocop-rspec
133
+ requirement: !ruby/object:Gem::Requirement
134
+ requirements:
135
+ - - '='
136
+ - !ruby/object:Gem::Version
137
+ version: 1.4.0
138
+ type: :development
139
+ prerelease: false
140
+ version_requirements: !ruby/object:Gem::Requirement
141
+ requirements:
142
+ - - '='
143
+ - !ruby/object:Gem::Version
144
+ version: 1.4.0
145
+ - !ruby/object:Gem::Dependency
146
+ name: sass-rails
147
+ requirement: !ruby/object:Gem::Requirement
148
+ requirements:
149
+ - - ">="
150
+ - !ruby/object:Gem::Version
151
+ version: '0'
152
+ type: :development
153
+ prerelease: false
154
+ version_requirements: !ruby/object:Gem::Requirement
155
+ requirements:
156
+ - - ">="
157
+ - !ruby/object:Gem::Version
158
+ version: '0'
159
+ - !ruby/object:Gem::Dependency
160
+ name: simplecov
161
+ requirement: !ruby/object:Gem::Requirement
162
+ requirements:
163
+ - - ">="
164
+ - !ruby/object:Gem::Version
165
+ version: '0'
166
+ type: :development
167
+ prerelease: false
168
+ version_requirements: !ruby/object:Gem::Requirement
169
+ requirements:
170
+ - - ">="
171
+ - !ruby/object:Gem::Version
172
+ version: '0'
173
+ - !ruby/object:Gem::Dependency
174
+ name: sqlite3
175
+ requirement: !ruby/object:Gem::Requirement
176
+ requirements:
177
+ - - ">="
178
+ - !ruby/object:Gem::Version
179
+ version: '0'
180
+ type: :development
181
+ prerelease: false
182
+ version_requirements: !ruby/object:Gem::Requirement
183
+ requirements:
184
+ - - ">="
185
+ - !ruby/object:Gem::Version
186
+ version: '0'
187
+ description: With this plugin its possible to have static sales per product
188
+ email: josua.schmid@renuo.ch
189
+ executables: []
190
+ extensions: []
191
+ extra_rdoc_files: []
192
+ files:
193
+ - LICENSE
194
+ - README.md
195
+ - Rakefile
196
+ - app/helpers/spree/base_helper_decorator.rb
197
+ - app/models/spree/price_decorator.rb
198
+ - app/models/spree/product_decorator.rb
199
+ - app/models/spree/variant_decorator.rb
200
+ - app/overrides/admin_product_tabs.rb
201
+ - app/views/spree/admin/sale_prices/_form_field.html.erb
202
+ - config/locales/de.yml
203
+ - config/locales/en.yml
204
+ - config/routes.rb
205
+ - db/migrate/20180417124320_add_sale_amount_to_prices.rb
206
+ - lib/generators/solidus_simple_sale_price/install/install_generator.rb
207
+ - lib/solidus_simple_sale_price.rb
208
+ - lib/solidus_simple_sale_price/engine.rb
209
+ - lib/solidus_simple_sale_price/factories.rb
210
+ - lib/solidus_simple_sale_price/version.rb
211
+ homepage: http://github.com/renuo/solidus_simple_sale_price
212
+ licenses:
213
+ - BSD-3-Clause
214
+ metadata: {}
215
+ post_install_message:
216
+ rdoc_options: []
217
+ require_paths:
218
+ - lib
219
+ required_ruby_version: !ruby/object:Gem::Requirement
220
+ requirements:
221
+ - - ">="
222
+ - !ruby/object:Gem::Version
223
+ version: '0'
224
+ required_rubygems_version: !ruby/object:Gem::Requirement
225
+ requirements:
226
+ - - ">="
227
+ - !ruby/object:Gem::Version
228
+ version: '0'
229
+ requirements: []
230
+ rubyforge_project:
231
+ rubygems_version: 2.7.3
232
+ signing_key:
233
+ specification_version: 4
234
+ summary: Adds sale price functionality to Solidus
235
+ test_files: []