My favorites
▼
|
Sign in
substruct
Open-source Ruby on Rails E-Commerce
Project Home
Downloads
Wiki
Issues
Source
READ-ONLY: This project has been
archived
. For more information see
this post
.
Search
Search within:
All issues
Open issues
New issues
Issues to verify
for
Advanced search
Search tips
Subscriptions
Issue
173
attachment: add_shipping_only_discounts.diff
(2.8 KB)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
Index: plugins/substruct/app/models/promotion.rb
===================================================================
--- plugins/substruct/app/models/promotion.rb (revision 178)
+++ plugins/substruct/app/models/promotion.rb (working copy)
@@ -6,7 +6,10 @@
TYPES = {
'Dollars' => 0,
'Percent of total order' => 1,
- 'Buy [n] get 1 free' => 2
+ 'Buy [n] get 1 free' => 2,
+ 'Dollar discount from shipping' => 3,
+ 'Dollar discount from cheapest shipping available' => 4
+
}
# Associations
has_many :orders
@@ -80,4 +83,4 @@
end
end
-end
\ No newline at end of file
+end
Index: plugins/substruct/app/models/order.rb
===================================================================
--- plugins/substruct/app/models/order.rb (revision 178)
+++ plugins/substruct/app/models/order.rb (working copy)
@@ -89,6 +89,7 @@
return if !promo || !promo.is_active?
# Don't allow more than one promotion?
+ # Prevents them also from using the same promotion over and over
# This destroys any line items created previously.
self.order_line_items.delete(self.promotion_line_item) if self.promotion_line_item
@@ -129,6 +130,10 @@
else
return
end
+ when 3,4 then
+ # do nothing, we'll apply shipping discounts for them later
+ else
+ raise 'unknown discount_type'
end
self.order_line_items << oli
@@ -571,12 +576,25 @@
else
shipping_types = OrderShippingType.get_foreign
end
-
for type in shipping_types
type.calculate_price(self.weight)
prices << type
end
+ if(self.promotion)
+ if([3,4].include? self.promotion.discount_type )
+ shipping_prices_to_discount = prices
+ if(self.promotion.discount_type == 4)
+ shipping_prices_to_discount = prices.sort{|p1, p2| p1.price - p2.price}[0..0]
+ end
+
+ for type in shipping_prices_to_discount
+ type.price-= self.promotion.discount_amount
+ type.calculated_price -= self.promotion.discount_amount
+ end
+ end
+ end
+
return prices
end
Index: plugins/substruct/app/views/admin/promotions/_help.rhtml
===================================================================
--- plugins/substruct/app/views/admin/promotions/_help.rhtml (revision 178)
+++ plugins/substruct/app/views/admin/promotions/_help.rhtml (working copy)
@@ -28,4 +28,14 @@
<h3>Percent of total order</h3>
<p>
A percentage of the total cart is discounted.
-</p>
\ No newline at end of file
+</p>
+
+<h3>Dollar discount from shipping</h3>
+<p>
+ This many dollars will be subtracted from the shipping figures shown to the client.
+<p>
+<h3>Dollar discount from cheapest shipping</h3>
+<p>
+ This many dollars will be subtracted from the cheapest available shipping figure that the client qualifies for.
+<p>
+
Powered by
Google Project Hosting