product_rails 0.1.4 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 43590aca3c2fb88a3fe895cf4ab0876ce356aa36
4
- data.tar.gz: 9b4d1f25cf355132959e4ffb0911797d40ee8e6e
3
+ metadata.gz: 5445440be14686d89a73474e75f3f76f242c3090
4
+ data.tar.gz: 890ce73e04692414d3cd262f8244988f7b30c08d
5
5
  SHA512:
6
- metadata.gz: 08f5abb42dd0620b965be3dd3f8cd24a857adb6cb1fcaa44e47e9332b2b620bebd8e53f74242504ab45de333eba8707b2d3228eb35aec3b235aea18286882c83
7
- data.tar.gz: cc759e7a65f96df257b91790b4bc8fdcf5278494dba73ec516e67700ae4b2dde3b956ccc71ae0c818d8142646b948d7f4691725c75dff6984870c8ffcc492ea9
6
+ metadata.gz: 8e220fbda29f31a2168cb8aef44b476e0ce3a6f5182b1364764ed8e812f205fc014841a83bba2049b96fe8e8d952089e9dbba7a5188efd7a2b0ab07e65b02088
7
+ data.tar.gz: 3f24d70a59ba0799afee90ffd432b6cfe4956140d38d7d2269cb9833848922bb933950ae69306c8300fe8dd30cbd46d432bf90130bb93ec1cc3205c60caf86e6
@@ -7,13 +7,28 @@ class Product < ActiveRecord::Base
7
7
  validates :sku, uniqueness: true
8
8
  validates :stock, :min_stock, numericality: {only_integer: true}
9
9
  validates :price, numericality: {greater_than_or_equal_to: 0}, allow_nil: true
10
+ validates :promotional_price, numericality: {greater_than_or_equal_to: 0}, allow_nil: true
10
11
  validates :tax, numericality: {greater_than_or_equal_to: 0}, allow_nil: true
11
12
  validates :weight, numericality: {greater_than_or_equal_to: 0}, allow_nil: true
12
13
 
13
14
  friendly_id :slug_candidates, use: [:slugged, :finders]
14
15
 
16
+ scope :promotional, -> { where('promotional_price is not null and promotional_price > 0') }
17
+
15
18
  def slug_candidates
16
19
  [[:name, :sku]]
17
20
  end
18
21
 
22
+ def current_price
23
+ promotional_price? ? promotional_price : price
24
+ end
25
+
26
+ def promotional_price?
27
+ promotional_price.present? && promotional_price.to_i > 0
28
+ end
29
+
30
+ def promotional_discount
31
+ promotional_price? ? (1 - promotional_price / price) * 100 : 0
32
+ end
33
+
19
34
  end
@@ -0,0 +1,7 @@
1
+ class AddPromotionalPriceToProduct < ActiveRecord::Migration
2
+ def change
3
+ unless column_exists? :products, :promotional_price
4
+ add_column :products, :promotional_price, :decimal, precision: 12, scale: 2
5
+ end
6
+ end
7
+ end
@@ -1,3 +1,3 @@
1
1
  module ProductRails
2
- VERSION = "0.1.4"
2
+ VERSION = "0.2.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: product_rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Orgânica Digital
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-02-23 00:00:00.000000000 Z
11
+ date: 2016-06-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -67,6 +67,7 @@ files:
67
67
  - db/migrate/20150209192603_rename_product_wheight_to_weight.rb
68
68
  - db/migrate/20150210130905_change_product_decription_column_to_text.rb
69
69
  - db/migrate/20150210155118_change_product_weight_and_description_to_allow_null.rb
70
+ - db/migrate/20160613143706_add_promotional_price_to_product.rb
70
71
  - lib/product_rails.rb
71
72
  - lib/product_rails/engine.rb
72
73
  - lib/product_rails/version.rb
@@ -91,7 +92,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
91
92
  version: '0'
92
93
  requirements: []
93
94
  rubyforge_project:
94
- rubygems_version: 2.4.5
95
+ rubygems_version: 2.4.3
95
96
  signing_key:
96
97
  specification_version: 4
97
98
  summary: A simple product representation for Rails applications.