radiant-shop_discounts-extension 0.0.10 → 0.0.11
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/app/models/shop_discount.rb +9 -4
- data/app/models/shop_discountable.rb +0 -2
- data/app/models/{category_shop_discountable.rb → shop_discountable_category.rb} +3 -1
- data/app/models/{order_shop_discountable.rb → shop_discountable_order.rb} +3 -1
- data/lib/shop_discounts/models/category_discountable.rb +1 -1
- data/lib/shop_discounts/models/order_discountable.rb +1 -1
- data/lib/shop_discounts/models/shop_product.rb +1 -1
- data/radiant-shop_discounts-extension.gemspec +3 -3
- metadata +5 -5
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.11
|
data/app/models/shop_discount.rb
CHANGED
@@ -9,13 +9,18 @@ class ShopDiscount < ActiveRecord::Base
|
|
9
9
|
belongs_to :created_by, :class_name => 'User'
|
10
10
|
belongs_to :updated_by, :class_name => 'User'
|
11
11
|
|
12
|
-
has_many :discountables,
|
12
|
+
has_many :discountables, :class_name => 'ShopDiscountable', :foreign_key => :discount_id
|
13
13
|
|
14
|
-
has_many :categories, :through => :discountables, :source => :category, :conditions => "shop_discountables.discounted_type = 'ShopCategory'"
|
15
14
|
has_many :products, :through => :discountables, :source => :product, :conditions => "shop_discountables.discounted_type = 'ShopProduct'"
|
16
|
-
has_many :orders, :through => :discountables, :source => :order, :conditions => "shop_discountables.discounted_type = 'ShopOrder'"
|
17
|
-
has_many :line_items, :through => :discountables, :source => :line_item,:conditions => "shop_discountables.discounted_type = 'ShopLineItem'"
|
18
15
|
has_many :users, :through => :discountables, :source => :user, :conditions => "shop_discountables.discounted_type = 'User'"
|
16
|
+
has_many :line_items, :through => :discountables, :source => :line_item,:conditions => "shop_discountables.discounted_type = 'ShopLineItem'"
|
17
|
+
|
18
|
+
has_many :discountables_categories, :class_name => 'ShopDiscountableCategory', :foreign_key => :discount_id
|
19
|
+
has_many :categories, :through => :discountables_categories, :source => :category, :conditions => "shop_discountables.discounted_type = 'ShopCategory'"
|
20
|
+
|
21
|
+
has_many :discountables_orders, :class_name => 'ShopDiscountableOrder', :foreign_key => :discount_id
|
22
|
+
has_many :orders, :through => :discountable_orders, :source => :order, :conditions => "shop_discountables.discounted_type = 'ShopOrder'"
|
23
|
+
|
19
24
|
|
20
25
|
validates_presence_of :name, :code, :amount
|
21
26
|
validates_uniqueness_of :name, :code
|
@@ -3,9 +3,7 @@ class ShopDiscountable < ActiveRecord::Base
|
|
3
3
|
belongs_to :discount, :class_name => 'ShopDiscount', :foreign_key => :discount_id
|
4
4
|
belongs_to :discounted, :foreign_key => :discounted_id, :polymorphic => true
|
5
5
|
|
6
|
-
belongs_to :category, :class_name => 'ShopCategory', :foreign_key => :discounted_id
|
7
6
|
belongs_to :product, :class_name => 'ShopProduct', :foreign_key => :discounted_id
|
8
|
-
belongs_to :order, :class_name => 'ShopOrder', :foreign_key => :discounted_id
|
9
7
|
belongs_to :line_item, :class_name => 'ShopLineItem', :foreign_key => :discounted_id
|
10
8
|
belongs_to :user, :class_name => 'User', :foreign_key => :discounted_id
|
11
9
|
|
@@ -1,8 +1,10 @@
|
|
1
|
-
class
|
1
|
+
class ShopDiscountableCategory < ShopDiscountable
|
2
2
|
|
3
3
|
before_validation :create_shop_products
|
4
4
|
before_destroy :destroy_shop_products
|
5
5
|
|
6
|
+
belongs_to :category, :class_name => 'ShopCategory', :foreign_key => :discounted_id
|
7
|
+
|
6
8
|
# Adds discount to a category's products
|
7
9
|
def create_shop_products
|
8
10
|
discounted.products.each do |product|
|
@@ -1,8 +1,10 @@
|
|
1
|
-
class
|
1
|
+
class ShopDiscountableOrder < ShopDiscountable
|
2
2
|
|
3
3
|
before_validation :create_shop_line_items
|
4
4
|
before_destroy :destroy_shop_line_items
|
5
5
|
|
6
|
+
belongs_to :order, :class_name => 'ShopOrder', :foreign_key => :discounted_id
|
7
|
+
|
6
8
|
# Adds discount to an order's line_items
|
7
9
|
def create_shop_line_items
|
8
10
|
discounted.line_items.each do |line_item|
|
@@ -4,7 +4,7 @@ module ShopDiscounts
|
|
4
4
|
|
5
5
|
def self.included(base)
|
6
6
|
base.class_eval do
|
7
|
-
has_many :discountables, :class_name => '
|
7
|
+
has_many :discountables, :class_name => 'ShopDiscountableCategory', :foreign_key => :discounted_id, :dependent => :destroy
|
8
8
|
has_many :discounts, :class_name => 'ShopDiscount', :through => :discountables
|
9
9
|
end
|
10
10
|
end
|
@@ -4,7 +4,7 @@ module ShopDiscounts
|
|
4
4
|
|
5
5
|
def self.included(base)
|
6
6
|
base.class_eval do
|
7
|
-
has_many :discountables, :class_name => '
|
7
|
+
has_many :discountables, :class_name => 'ShopDiscountableOrder', :foreign_key => :discounted_id, :dependent => :destroy
|
8
8
|
has_many :discounts, :class_name => 'ShopDiscount', :through => :discountables
|
9
9
|
end
|
10
10
|
end
|
@@ -8,7 +8,7 @@ module ShopDiscounts
|
|
8
8
|
|
9
9
|
# Assigns discounts based off categories discounts
|
10
10
|
def assign_discounts
|
11
|
-
category.discounts.each do |discount|
|
11
|
+
category.discounts.each do |discount|
|
12
12
|
ShopDiscountable.create(:discount => discount, :discounted => self)
|
13
13
|
end
|
14
14
|
end
|
@@ -5,7 +5,7 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{radiant-shop_discounts-extension}
|
8
|
-
s.version = "0.0.
|
8
|
+
s.version = "0.0.11"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Dirk Kelly"]
|
@@ -22,11 +22,11 @@ Gem::Specification.new do |s|
|
|
22
22
|
"VERSION",
|
23
23
|
"app/controllers/admin/shop/discounts/discountables_controller.rb",
|
24
24
|
"app/controllers/admin/shop/discounts_controller.rb",
|
25
|
-
"app/models/category_shop_discountable.rb",
|
26
25
|
"app/models/form_discount.rb",
|
27
|
-
"app/models/order_shop_discountable.rb",
|
28
26
|
"app/models/shop_discount.rb",
|
29
27
|
"app/models/shop_discountable.rb",
|
28
|
+
"app/models/shop_discountable_category.rb",
|
29
|
+
"app/models/shop_discountable_order.rb",
|
30
30
|
"app/views/admin/shop/discounts/edit.html.haml",
|
31
31
|
"app/views/admin/shop/discounts/edit/_foot.html.haml",
|
32
32
|
"app/views/admin/shop/discounts/edit/_form.html.haml",
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: radiant-shop_discounts-extension
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 9
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 11
|
10
|
+
version: 0.0.11
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Dirk Kelly
|
@@ -49,11 +49,11 @@ files:
|
|
49
49
|
- VERSION
|
50
50
|
- app/controllers/admin/shop/discounts/discountables_controller.rb
|
51
51
|
- app/controllers/admin/shop/discounts_controller.rb
|
52
|
-
- app/models/category_shop_discountable.rb
|
53
52
|
- app/models/form_discount.rb
|
54
|
-
- app/models/order_shop_discountable.rb
|
55
53
|
- app/models/shop_discount.rb
|
56
54
|
- app/models/shop_discountable.rb
|
55
|
+
- app/models/shop_discountable_category.rb
|
56
|
+
- app/models/shop_discountable_order.rb
|
57
57
|
- app/views/admin/shop/discounts/edit.html.haml
|
58
58
|
- app/views/admin/shop/discounts/edit/_foot.html.haml
|
59
59
|
- app/views/admin/shop/discounts/edit/_form.html.haml
|