shoppe 0.0.11 → 0.0.12
Sign up to get free protection for your applications and to get access to all the features.
- data/app/assets/stylesheets/shoppe/application.scss +3 -2
- data/app/assets/stylesheets/shoppe/chosen.css +8 -8
- data/app/assets/stylesheets/shoppe/elements.scss +1 -1
- data/app/controllers/shoppe/delivery_service_prices_controller.rb +1 -1
- data/app/controllers/shoppe/tax_rates_controller.rb +1 -1
- data/app/models/shoppe/delivery_service_price.rb +3 -0
- data/app/models/shoppe/order.rb +10 -3
- data/app/models/shoppe/order_item.rb +27 -13
- data/app/models/shoppe/tax_rate.rb +11 -0
- data/app/views/shoppe/delivery_service_prices/_form.html.haml +6 -0
- data/app/views/shoppe/delivery_services/edit.html.haml +3 -1
- data/app/views/shoppe/products/edit.html.haml +1 -1
- data/app/views/shoppe/products/new.html.haml +1 -1
- data/app/views/shoppe/products/stock_levels.html.haml +2 -2
- data/app/views/shoppe/tax_rates/form.html.haml +7 -2
- data/db/migrate/20131020204719_add_countries_to_tax_rates_and_delivery_prices.rb +6 -0
- data/db/seeds.rb +17 -17
- data/lib/shoppe/associated_countries.rb +20 -0
- data/lib/shoppe/version.rb +1 -1
- data/test/dummy/db/schema.rb +23 -4
- data/test/dummy/log/development.log +24 -0
- metadata +6 -4
@@ -41,7 +41,7 @@ nav.sidebar {
|
|
41
41
|
|
42
42
|
ul {
|
43
43
|
li {
|
44
|
-
span.pending { float:right; font-size:0.9em; font-weight:bold;background:#5B6270; color:#fff;padding:2px
|
44
|
+
span.pending { float:right; font-size:0.9em; font-weight:bold;background:#5B6270; color:#fff; padding:2px 10px; border-radius:16px; margin-top:9px; margin-right:10px;}
|
45
45
|
a {
|
46
46
|
display:block;
|
47
47
|
border-bottom:1px solid rgba(255,255,255,0.05);
|
@@ -50,11 +50,12 @@ nav.sidebar {
|
|
50
50
|
padding:10px 20px;
|
51
51
|
font-size:1.1em;
|
52
52
|
&:hover {
|
53
|
-
background:rgba(0,0,0,0.
|
53
|
+
background:rgba(0,0,0,0.05);
|
54
54
|
}
|
55
55
|
&.active {
|
56
56
|
font-weight:bold;
|
57
57
|
color:#fff;
|
58
|
+
background:rgba(0,0,0,0.08);
|
58
59
|
}
|
59
60
|
}
|
60
61
|
}
|
@@ -19,7 +19,7 @@
|
|
19
19
|
-moz-box-sizing: border-box;
|
20
20
|
box-sizing: border-box;
|
21
21
|
width: 100%;
|
22
|
-
border: 1px solid #
|
22
|
+
border: 1px solid #ccc;
|
23
23
|
border-top: 0;
|
24
24
|
background: #fff;
|
25
25
|
box-shadow: 0 4px 5px rgba(0, 0, 0, 0.15);
|
@@ -39,7 +39,7 @@
|
|
39
39
|
overflow: hidden;
|
40
40
|
padding: 0 0 0 8px;
|
41
41
|
height: 23px;
|
42
|
-
border: 1px solid #
|
42
|
+
border: 1px solid #ccc;
|
43
43
|
border-radius: 5px;
|
44
44
|
background-color: #fff;
|
45
45
|
background: -webkit-gradient(linear, 50% 0%, 50% 100%, color-stop(20%, #ffffff), color-stop(50%, #f6f6f6), color-stop(52%, #eeeeee), color-stop(100%, #f4f4f4));
|
@@ -113,7 +113,7 @@
|
|
113
113
|
width: 100%;
|
114
114
|
height: auto;
|
115
115
|
outline: 0;
|
116
|
-
border: 1px solid #
|
116
|
+
border: 1px solid #ccc;
|
117
117
|
background: white url('chosen-sprite.png') no-repeat 100% -20px;
|
118
118
|
background: url('chosen-sprite.png') no-repeat 100% -20px, -webkit-gradient(linear, 50% 0%, 50% 100%, color-stop(1%, #eeeeee), color-stop(15%, #ffffff));
|
119
119
|
background: url('chosen-sprite.png') no-repeat 100% -20px, -webkit-linear-gradient(#eeeeee 1%, #ffffff 15%);
|
@@ -201,7 +201,7 @@
|
|
201
201
|
width: 100%;
|
202
202
|
height: auto !important;
|
203
203
|
height: 1%;
|
204
|
-
border: 1px solid #
|
204
|
+
border: 1px solid #ccc;
|
205
205
|
background-color: #fff;
|
206
206
|
background-image: -webkit-gradient(linear, 50% 0%, 50% 100%, color-stop(1%, #eeeeee), color-stop(15%, #ffffff));
|
207
207
|
background-image: -webkit-linear-gradient(#eeeeee 1%, #ffffff 15%);
|
@@ -240,7 +240,7 @@
|
|
240
240
|
position: relative;
|
241
241
|
margin: 3px 0 3px 5px;
|
242
242
|
padding: 3px 20px 3px 5px;
|
243
|
-
border: 1px solid #
|
243
|
+
border: 1px solid #ccc;
|
244
244
|
border-radius: 3px;
|
245
245
|
background-color: #e4e4e4;
|
246
246
|
background-image: -webkit-gradient(linear, 50% 0%, 50% 100%, color-stop(20%, #f4f4f4), color-stop(50%, #f0f0f0), color-stop(52%, #e8e8e8), color-stop(100%, #eeeeee));
|
@@ -297,11 +297,11 @@
|
|
297
297
|
/* @end */
|
298
298
|
/* @group Active */
|
299
299
|
.chosen-container-active .chosen-single {
|
300
|
-
border: 1px solid #
|
300
|
+
border: 1px solid #9AC835;
|
301
301
|
box-shadow: 0 0 5px rgba(0, 0, 0, 0.3);
|
302
302
|
}
|
303
303
|
.chosen-container-active.chosen-with-drop .chosen-single {
|
304
|
-
border: 1px solid #
|
304
|
+
border: 1px solid #ccc;
|
305
305
|
-moz-border-radius-bottomright: 0;
|
306
306
|
border-bottom-right-radius: 0;
|
307
307
|
-moz-border-radius-bottomleft: 0;
|
@@ -321,7 +321,7 @@
|
|
321
321
|
background-position: -18px 2px;
|
322
322
|
}
|
323
323
|
.chosen-container-active .chosen-choices {
|
324
|
-
border: 1px solid #
|
324
|
+
border: 1px solid #9AC835;
|
325
325
|
box-shadow: 0 0 5px rgba(0, 0, 0, 0.3);
|
326
326
|
}
|
327
327
|
.chosen-container-active .chosen-choices li.search-field input[type="text"] {
|
@@ -36,7 +36,7 @@ class Shoppe::DeliveryServicePricesController < Shoppe::ApplicationController
|
|
36
36
|
private
|
37
37
|
|
38
38
|
def safe_params
|
39
|
-
params[:delivery_service_price].permit(:price, :cost_price, :tax_rate_id, :min_weight, :max_weight, :code)
|
39
|
+
params[:delivery_service_price].permit(:price, :cost_price, :tax_rate_id, :min_weight, :max_weight, :code, :country_ids => [])
|
40
40
|
end
|
41
41
|
|
42
42
|
end
|
@@ -3,6 +3,9 @@ class Shoppe::DeliveryServicePrice < ActiveRecord::Base
|
|
3
3
|
# Set the table name
|
4
4
|
self.table_name = 'shoppe_delivery_service_prices'
|
5
5
|
|
6
|
+
# Tax rates are associated with countries
|
7
|
+
include Shoppe::AssociatedCountries
|
8
|
+
|
6
9
|
# Relationships
|
7
10
|
belongs_to :delivery_service, :class_name => 'Shoppe::DeliveryService'
|
8
11
|
belongs_to :tax_rate, :class_name => "Shoppe::TaxRate"
|
data/app/models/shoppe/order.rb
CHANGED
@@ -36,6 +36,11 @@ class Shoppe::Order < ActiveRecord::Base
|
|
36
36
|
order.validates :email_address, :format => {:with => /\A\b[A-Z0-9\.\_\%\-\+]+@(?:[A-Z0-9\-]+\.)+[A-Z]{2,6}\b\z/i}
|
37
37
|
order.validates :phone_number, :format => {:with => /\A[\d\ ]{7,}\z/}
|
38
38
|
end
|
39
|
+
validate do
|
40
|
+
unless available_delivery_services.include?(self.delivery_service)
|
41
|
+
errors.add :delivery_service_id, "is not suitable for this order"
|
42
|
+
end
|
43
|
+
end
|
39
44
|
|
40
45
|
# Scopes
|
41
46
|
scope :received, -> {where("received_at is not null")}
|
@@ -153,7 +158,9 @@ class Shoppe::Order < ActiveRecord::Base
|
|
153
158
|
# An array of all the delivery service prices which can be applied to this order.
|
154
159
|
def delivery_service_prices
|
155
160
|
@delivery_service_prices ||= begin
|
156
|
-
Shoppe::DeliveryServicePrice.joins(:delivery_service).where(:shoppe_delivery_services => {:active => true}).order("`default` desc, price asc").for_weight(total_weight)
|
161
|
+
prices = Shoppe::DeliveryServicePrice.joins(:delivery_service).where(:shoppe_delivery_services => {:active => true}).order("`default` desc, price asc").for_weight(total_weight)
|
162
|
+
prices = prices.select { |p| p.countries.empty? || p.country?(self.country) }
|
163
|
+
prices
|
157
164
|
end
|
158
165
|
end
|
159
166
|
|
@@ -189,7 +196,7 @@ class Shoppe::Order < ActiveRecord::Base
|
|
189
196
|
def delivery_tax_amount
|
190
197
|
@delivery_tax_amount ||= begin
|
191
198
|
read_attribute(:delivery_tax_amount) ||
|
192
|
-
|
199
|
+
delivery_price / BigDecimal(100) * delivery_tax_rate ||
|
193
200
|
0.0
|
194
201
|
end
|
195
202
|
end
|
@@ -198,7 +205,7 @@ class Shoppe::Order < ActiveRecord::Base
|
|
198
205
|
def delivery_tax_rate
|
199
206
|
@delivery_tax_rate ||= begin
|
200
207
|
read_attribute(:delivery_tax_rate) ||
|
201
|
-
delivery_service_price.try(:tax_rate).try(:
|
208
|
+
delivery_service_price.try(:tax_rate).try(:rate_for, self) ||
|
202
209
|
0.0
|
203
210
|
end
|
204
211
|
end
|
@@ -13,19 +13,7 @@ class Shoppe::OrderItem < ActiveRecord::Base
|
|
13
13
|
|
14
14
|
# Set some values based on the selected product on validation
|
15
15
|
before_validation do
|
16
|
-
|
17
|
-
self.unit_price = self.product.price if self.unit_price.blank?
|
18
|
-
self.unit_cost_price = self.product.cost_price if self.unit_cost_price.blank?
|
19
|
-
self.tax_rate = self.product.tax_rate.rate if self.tax_rate.blank? && self.product.tax_rate
|
20
|
-
|
21
|
-
if unit_price_changed? || quantity_changed? || tax_rate_changed?
|
22
|
-
self.tax_amount = (self.sub_total / BigDecimal(100)) * self.tax_rate
|
23
|
-
end
|
24
|
-
|
25
|
-
if product_id_changed? || quantity_changed?
|
26
|
-
self.weight = self.quantity * self.product.weight
|
27
|
-
end
|
28
|
-
end
|
16
|
+
self.weight = self.quantity * self.product.weight
|
29
17
|
end
|
30
18
|
|
31
19
|
# This allows you to add a product to the scoped order. For example Order.first.order_items.add_product(...).
|
@@ -75,6 +63,26 @@ class Shoppe::OrderItem < ActiveRecord::Base
|
|
75
63
|
end
|
76
64
|
end
|
77
65
|
|
66
|
+
# Return the unit price for the item
|
67
|
+
def unit_price
|
68
|
+
@unit_price ||= read_attribute(:unit_price) || product.try(:price) || 0.0
|
69
|
+
end
|
70
|
+
|
71
|
+
# Return the cost price for the item
|
72
|
+
def unit_cost_price
|
73
|
+
@unit_cost_price ||= read_attribute(:unit_cost_price) || product.try(:cost_price) || 0.0
|
74
|
+
end
|
75
|
+
|
76
|
+
# Return the tax rate for the item
|
77
|
+
def tax_rate
|
78
|
+
@tax_rate ||= read_attribute(:tax_rate) || product.try(:tax_rate).try(:rate_for, self.order) || 0.0
|
79
|
+
end
|
80
|
+
|
81
|
+
# Return the total tax for the item
|
82
|
+
def tax_amount
|
83
|
+
@tax_amount ||= read_attribute(:tax_amount) || (self.sub_total / BigDecimal(100)) * self.tax_rate
|
84
|
+
end
|
85
|
+
|
78
86
|
# Return the total cost for the product
|
79
87
|
def total_cost
|
80
88
|
quantity * unit_cost_price
|
@@ -93,6 +101,12 @@ class Shoppe::OrderItem < ActiveRecord::Base
|
|
93
101
|
# This method will be triggered when the parent order is confirmed. This should automatically
|
94
102
|
# update the stock levels on the source product.
|
95
103
|
def confirm!
|
104
|
+
write_attribute :unit_price, self.unit_price
|
105
|
+
write_attribute :unit_cost_price, self.unit_cost_price
|
106
|
+
write_attribute :tax_rate, self.tax_rate
|
107
|
+
write_attribute :tax_amount, self.tax_amount
|
108
|
+
save!
|
109
|
+
|
96
110
|
if self.product.stock_control?
|
97
111
|
self.product.stock_level_adjustments.create(:parent => self, :adjustment => 0 - self.quantity, :description => "Order ##{self.order.number} deduction")
|
98
112
|
end
|
@@ -4,6 +4,9 @@ module Shoppe
|
|
4
4
|
# Set the table name
|
5
5
|
self.table_name = 'shoppe_tax_rates'
|
6
6
|
|
7
|
+
# Tax rates are associated with countries
|
8
|
+
include Shoppe::AssociatedCountries
|
9
|
+
|
7
10
|
# Validations
|
8
11
|
validates :name, :presence => true
|
9
12
|
validates :rate, :numericality => true
|
@@ -19,5 +22,13 @@ module Shoppe
|
|
19
22
|
"#{name} (#{rate}%)"
|
20
23
|
end
|
21
24
|
|
25
|
+
def rate_for(order)
|
26
|
+
if countries.empty? || order.country.nil? || country?(order.country)
|
27
|
+
self.rate
|
28
|
+
else
|
29
|
+
0.0
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
22
33
|
end
|
23
34
|
end
|
@@ -25,6 +25,12 @@
|
|
25
25
|
%dt= f.label :tax_rate_id
|
26
26
|
%dd= f.collection_select :tax_rate_id, Shoppe::TaxRate.ordered, :id, :description, {:include_blank => true}, {:class => 'chosen-with-deselect', :data => {:placeholder => "No tax"}}
|
27
27
|
|
28
|
+
= field_set_tag "Countries" do
|
29
|
+
%dl
|
30
|
+
%dd
|
31
|
+
= f.collection_select :country_ids, Shoppe::Country.ordered, :id, :name, {}, {:class => 'chosen', :multiple => true, :data => {:placeholder => "All countries"}}
|
32
|
+
%p.help This delivery rate will only be available to orders where the country selected is listed here.
|
33
|
+
|
28
34
|
%p.submit
|
29
35
|
- unless @delivery_service_price.new_record?
|
30
36
|
%span.right= link_to "Delete", [@delivery_service, @delivery_service_price], :class => 'button purple', :method => :delete, :data => {:confirm => "Are you sure you wish to remove this price?"}
|
@@ -1,5 +1,7 @@
|
|
1
1
|
- @page_title = "Delivery Services"
|
2
2
|
= content_for :header do
|
3
|
-
%p.buttons
|
3
|
+
%p.buttons
|
4
|
+
= link_to "Prices", [@delivery_service, :delivery_service_prices], :class => 'button'
|
5
|
+
= link_to "Back to delivery services", :delivery_services, :class => 'button'
|
4
6
|
%h2.delivery_services Delivery Services
|
5
7
|
= render 'form'
|
@@ -2,6 +2,6 @@
|
|
2
2
|
= content_for :header do
|
3
3
|
%p.buttons
|
4
4
|
= link_to "Stock levels", [:stock_levels, @product], :class => 'button'
|
5
|
-
= link_to "Back to
|
5
|
+
= link_to "Back to product list", :products, :class => 'button'
|
6
6
|
%h2.products Products
|
7
7
|
= render 'form'
|
@@ -1,8 +1,8 @@
|
|
1
1
|
- @page_title = "Stock Levels - #{@product.title}"
|
2
2
|
= content_for :header do
|
3
3
|
%p.buttons
|
4
|
-
= link_to "Edit", [:edit, @product], :class => 'button'
|
5
|
-
= link_to "Back to list", :products, :class => 'button'
|
4
|
+
= link_to "Edit product", [:edit, @product], :class => 'button'
|
5
|
+
= link_to "Back to product list", :products, :class => 'button'
|
6
6
|
%h2.products= @product.title
|
7
7
|
|
8
8
|
.table
|
@@ -13,8 +13,13 @@
|
|
13
13
|
%dl.half
|
14
14
|
%dt= f.label :rate
|
15
15
|
%dd= f.text_field :rate
|
16
|
-
|
17
|
-
|
16
|
+
|
17
|
+
= field_set_tag "Countries" do
|
18
|
+
%dl
|
19
|
+
%dd
|
20
|
+
= f.collection_select :country_ids, Shoppe::Country.ordered, :id, :name, {}, {:class => 'chosen', :multiple => true, :data => {:placeholder => "All countries"}}
|
21
|
+
%p.help This tax rate will only apply to orders which are billed to addresses of the countries listed above.
|
22
|
+
|
18
23
|
%p.submit
|
19
24
|
- unless @tax_rate.new_record?
|
20
25
|
%span.right= link_to "Delete", @tax_rate, :class => 'button purple', :method => :delete, :data => {:confirm => "Are you sure you wish to remove this tax_rate?"}
|
data/db/seeds.rb
CHANGED
@@ -1,36 +1,36 @@
|
|
1
1
|
# encoding: UTF-8
|
2
2
|
|
3
3
|
# tax rates
|
4
|
-
tax_rate = Shoppe::TaxRate.create(:name => "Standard UK VAT", :rate => 20.0)
|
5
|
-
exempt_tax = Shoppe::TaxRate.create(:name => "Exempt VAT", :rate => 0.0)
|
4
|
+
tax_rate = Shoppe::TaxRate.create(:name => "Standard UK VAT", :rate => 20.0, :country_ids => Shoppe::Country.where(:eu_member => true).pluck(:id))
|
5
|
+
exempt_tax = Shoppe::TaxRate.create(:name => "Exempt VAT", :rate => 0.0, :country_ids => Shoppe::Country.where(:eu_member => true).pluck(:id))
|
6
6
|
|
7
7
|
# delivery services
|
8
8
|
|
9
9
|
ds = Shoppe::DeliveryService.create!(:name => "Royal Mail (1st class)", :code => 'RMFC', :courier => 'Royal Mail', :tracking_url => 'http://royalmail.com/track/{{consignment_number}}')
|
10
|
-
ds.delivery_service_prices.create!(:min_weight => 0, :max_weight => 0.050, :price => 0.60, :cost_price => 0.55, :tax_rate => exempt_tax)
|
10
|
+
ds.delivery_service_prices.create!(:min_weight => 0, :max_weight => 0.050, :price => 0.60, :cost_price => 0.55, :tax_rate => exempt_tax, :country_ids => Shoppe::Country.where(:name => 'United Kingdom').pluck(:id))
|
11
11
|
|
12
12
|
|
13
13
|
ds = Shoppe::DeliveryService.create!(:name => "Royal Mail (signed for)", :code => 'RMSF', :courier => 'Royal Mail', :tracking_url => 'http://royalmail.com/track/{{consignment_number}}')
|
14
|
-
ds.delivery_service_prices.create!(:min_weight => 0, :max_weight => 1, :price => 5.0, :cost_price => 4.5, :tax_rate => tax_rate)
|
15
|
-
ds.delivery_service_prices.create!(:min_weight => 1, :max_weight => 5, :price => 8.0, :cost_price => 7.5, :tax_rate => tax_rate)
|
16
|
-
ds.delivery_service_prices.create!(:min_weight => 5, :max_weight => 10, :price => 10.0, :cost_price => 9.5, :tax_rate => tax_rate)
|
17
|
-
ds.delivery_service_prices.create!(:min_weight => 10, :max_weight => 25, :price => 12.0, :cost_price => 11.5, :tax_rate => tax_rate)
|
18
|
-
ds.delivery_service_prices.create!(:min_weight => 25, :max_weight => 50, :price => 16.25, :cost_price => 13.5, :tax_rate => tax_rate)
|
14
|
+
ds.delivery_service_prices.create!(:min_weight => 0, :max_weight => 1, :price => 5.0, :cost_price => 4.5, :tax_rate => tax_rate, :country_ids => Shoppe::Country.where(:name => 'United Kingdom').pluck(:id))
|
15
|
+
ds.delivery_service_prices.create!(:min_weight => 1, :max_weight => 5, :price => 8.0, :cost_price => 7.5, :tax_rate => tax_rate, :country_ids => Shoppe::Country.where(:name => 'United Kingdom').pluck(:id))
|
16
|
+
ds.delivery_service_prices.create!(:min_weight => 5, :max_weight => 10, :price => 10.0, :cost_price => 9.5, :tax_rate => tax_rate, :country_ids => Shoppe::Country.where(:name => 'United Kingdom').pluck(:id))
|
17
|
+
ds.delivery_service_prices.create!(:min_weight => 10, :max_weight => 25, :price => 12.0, :cost_price => 11.5, :tax_rate => tax_rate, :country_ids => Shoppe::Country.where(:name => 'United Kingdom').pluck(:id))
|
18
|
+
ds.delivery_service_prices.create!(:min_weight => 25, :max_weight => 50, :price => 16.25, :cost_price => 13.5, :tax_rate => tax_rate, :country_ids => Shoppe::Country.where(:name => 'United Kingdom').pluck(:id))
|
19
19
|
|
20
20
|
ds = Shoppe::DeliveryService.create!(:name => "Next Day Delivery (before 4pm)", :default => true, :code => 'ND16', :courier => 'UPS', :tracking_url => 'http://trackingurl.com/track/{{consignment_number}}')
|
21
|
-
ds.delivery_service_prices.create!(:min_weight => 0, :max_weight => 1, :price => 7.0, :cost_price => 5.5, :tax_rate => tax_rate)
|
22
|
-
ds.delivery_service_prices.create!(:min_weight => 1, :max_weight => 5, :price => 9.0, :cost_price => 7.6, :tax_rate => tax_rate)
|
23
|
-
ds.delivery_service_prices.create!(:min_weight => 5, :max_weight => 20, :price => 11.50, :cost_price => 8.9, :tax_rate => tax_rate)
|
21
|
+
ds.delivery_service_prices.create!(:min_weight => 0, :max_weight => 1, :price => 7.0, :cost_price => 5.5, :tax_rate => tax_rate, :country_ids => Shoppe::Country.where(:name => 'United Kingdom').pluck(:id))
|
22
|
+
ds.delivery_service_prices.create!(:min_weight => 1, :max_weight => 5, :price => 9.0, :cost_price => 7.6, :tax_rate => tax_rate, :country_ids => Shoppe::Country.where(:name => 'United Kingdom').pluck(:id))
|
23
|
+
ds.delivery_service_prices.create!(:min_weight => 5, :max_weight => 20, :price => 11.50, :cost_price => 8.9, :tax_rate => tax_rate, :country_ids => Shoppe::Country.where(:name => 'United Kingdom').pluck(:id))
|
24
24
|
|
25
25
|
ds = Shoppe::DeliveryService.create!(:name => "Next Day Delivery (before 10am)", :code => 'NS10', :courier => 'UPS', :tracking_url => 'http://trackingurl.com/track/{{consignment_number}}')
|
26
|
-
ds.delivery_service_prices.create!(:min_weight => 0, :max_weight => 1, :price => 17.0, :cost_price => 14.00, :tax_rate => tax_rate)
|
27
|
-
ds.delivery_service_prices.create!(:min_weight => 1, :max_weight => 5, :price => 19.0, :cost_price => 16.00, :tax_rate => tax_rate)
|
28
|
-
ds.delivery_service_prices.create!(:min_weight => 5, :max_weight => 20, :price => 27.0, :cost_price => 22.00, :tax_rate => tax_rate)
|
26
|
+
ds.delivery_service_prices.create!(:min_weight => 0, :max_weight => 1, :price => 17.0, :cost_price => 14.00, :tax_rate => tax_rate, :country_ids => Shoppe::Country.where(:name => 'United Kingdom').pluck(:id))
|
27
|
+
ds.delivery_service_prices.create!(:min_weight => 1, :max_weight => 5, :price => 19.0, :cost_price => 16.00, :tax_rate => tax_rate, :country_ids => Shoppe::Country.where(:name => 'United Kingdom').pluck(:id))
|
28
|
+
ds.delivery_service_prices.create!(:min_weight => 5, :max_weight => 20, :price => 27.0, :cost_price => 22.00, :tax_rate => tax_rate, :country_ids => Shoppe::Country.where(:name => 'United Kingdom').pluck(:id))
|
29
29
|
|
30
30
|
ds = Shoppe::DeliveryService.create!(:name => "Saturday Delivery", :code => 'NDSA16', :courier => 'UPS', :tracking_url => 'http://trackingurl.com/track/{{consignment_number}}')
|
31
|
-
ds.delivery_service_prices.create!(:min_weight => 0, :max_weight => 1, :price => 27.0, :cost_price => 24.00, :tax_rate => tax_rate)
|
32
|
-
ds.delivery_service_prices.create!(:min_weight => 1, :max_weight => 5, :price => 29.0, :cost_price => 20.00, :tax_rate => tax_rate)
|
33
|
-
ds.delivery_service_prices.create!(:min_weight => 5, :max_weight => 20, :price => 37.0, :cost_price => 32.00,:tax_rate => tax_rate)
|
31
|
+
ds.delivery_service_prices.create!(:min_weight => 0, :max_weight => 1, :price => 27.0, :cost_price => 24.00, :tax_rate => tax_rate, :country_ids => Shoppe::Country.where(:name => 'United Kingdom').pluck(:id))
|
32
|
+
ds.delivery_service_prices.create!(:min_weight => 1, :max_weight => 5, :price => 29.0, :cost_price => 20.00, :tax_rate => tax_rate, :country_ids => Shoppe::Country.where(:name => 'United Kingdom').pluck(:id))
|
33
|
+
ds.delivery_service_prices.create!(:min_weight => 5, :max_weight => 20, :price => 37.0, :cost_price => 32.00,:tax_rate => tax_rate, :country_ids => Shoppe::Country.where(:name => 'United Kingdom').pluck(:id))
|
34
34
|
|
35
35
|
# categories
|
36
36
|
cat1 = Shoppe::ProductCategory.create!(:name => 'VoIP Phones')
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Shoppe
|
2
|
+
module AssociatedCountries
|
3
|
+
|
4
|
+
def self.included(base)
|
5
|
+
base.serialize :country_ids, Array
|
6
|
+
base.before_validation { self.country_ids = self.country_ids.map(&:to_i).select { |i| i > 0} if self.country_ids.is_a?(Array) }
|
7
|
+
end
|
8
|
+
|
9
|
+
def country?(id)
|
10
|
+
id = id.id if id.is_a?(Shoppe::Country)
|
11
|
+
self.country_ids.is_a?(Array) && self.country_ids.include?(id.to_i)
|
12
|
+
end
|
13
|
+
|
14
|
+
def countries
|
15
|
+
return [] unless self.country_ids.is_a?(Array) && !self.country_ids.empty?
|
16
|
+
Shoppe::Country.where(:id => self.country_ids)
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
end
|
data/lib/shoppe/version.rb
CHANGED
data/test/dummy/db/schema.rb
CHANGED
@@ -11,7 +11,7 @@
|
|
11
11
|
#
|
12
12
|
# It's strongly recommended that you check this file into your version control system.
|
13
13
|
|
14
|
-
ActiveRecord::Schema.define(version:
|
14
|
+
ActiveRecord::Schema.define(version: 20131020204719) do
|
15
15
|
|
16
16
|
create_table "nifty_attachments", force: true do |t|
|
17
17
|
t.integer "parent_id"
|
@@ -34,16 +34,27 @@ ActiveRecord::Schema.define(version: 20131017165222) do
|
|
34
34
|
t.string "value"
|
35
35
|
end
|
36
36
|
|
37
|
+
create_table "shoppe_countries", force: true do |t|
|
38
|
+
t.string "name"
|
39
|
+
t.string "code2"
|
40
|
+
t.string "code3"
|
41
|
+
t.string "continent"
|
42
|
+
t.string "tld"
|
43
|
+
t.string "currency"
|
44
|
+
t.boolean "eu_member", default: false
|
45
|
+
end
|
46
|
+
|
37
47
|
create_table "shoppe_delivery_service_prices", force: true do |t|
|
38
48
|
t.integer "delivery_service_id"
|
39
49
|
t.string "code"
|
40
50
|
t.decimal "price", precision: 8, scale: 2
|
41
|
-
t.
|
51
|
+
t.integer "tax_rate_id"
|
42
52
|
t.decimal "min_weight", precision: 8, scale: 2
|
43
53
|
t.decimal "max_weight", precision: 8, scale: 2
|
44
54
|
t.datetime "created_at"
|
45
55
|
t.datetime "updated_at"
|
46
56
|
t.decimal "cost_price", precision: 8, scale: 2
|
57
|
+
t.text "country_ids"
|
47
58
|
end
|
48
59
|
|
49
60
|
create_table "shoppe_delivery_services", force: true do |t|
|
@@ -80,6 +91,7 @@ ActiveRecord::Schema.define(version: 20131017165222) do
|
|
80
91
|
t.string "address3"
|
81
92
|
t.string "address4"
|
82
93
|
t.string "postcode"
|
94
|
+
t.integer "country_id"
|
83
95
|
t.string "email_address"
|
84
96
|
t.string "phone_number"
|
85
97
|
t.string "status"
|
@@ -99,7 +111,6 @@ ActiveRecord::Schema.define(version: 20131017165222) do
|
|
99
111
|
t.datetime "rejected_at"
|
100
112
|
t.integer "rejected_by"
|
101
113
|
t.string "ip_address"
|
102
|
-
t.string "country"
|
103
114
|
t.string "payment_reference"
|
104
115
|
t.string "payment_method"
|
105
116
|
t.decimal "delivery_cost_price", precision: 8, scale: 2
|
@@ -134,7 +145,7 @@ ActiveRecord::Schema.define(version: 20131017165222) do
|
|
134
145
|
t.boolean "active", default: true
|
135
146
|
t.decimal "weight", precision: 8, scale: 3, default: 0.0
|
136
147
|
t.decimal "price", precision: 8, scale: 2, default: 0.0
|
137
|
-
t.
|
148
|
+
t.integer "tax_rate_id"
|
138
149
|
t.datetime "created_at"
|
139
150
|
t.datetime "updated_at"
|
140
151
|
t.boolean "featured", default: false
|
@@ -153,6 +164,14 @@ ActiveRecord::Schema.define(version: 20131017165222) do
|
|
153
164
|
t.datetime "updated_at"
|
154
165
|
end
|
155
166
|
|
167
|
+
create_table "shoppe_tax_rates", force: true do |t|
|
168
|
+
t.string "name"
|
169
|
+
t.decimal "rate", precision: 8, scale: 2
|
170
|
+
t.datetime "created_at"
|
171
|
+
t.datetime "updated_at"
|
172
|
+
t.text "country_ids"
|
173
|
+
end
|
174
|
+
|
156
175
|
create_table "shoppe_users", force: true do |t|
|
157
176
|
t.string "first_name"
|
158
177
|
t.string "last_name"
|
@@ -1054,3 +1054,27 @@ Migrating to CreateShoppeCountries (20131017180920)
|
|
1054
1054
|
[1m[36m (0.8ms)[0m [1mDROP TABLE `shoppe_countries`[0m
|
1055
1055
|
[1m[35mSQL (1.6ms)[0m DELETE FROM `schema_migrations` WHERE `schema_migrations`.`version` = '20131017180920'
|
1056
1056
|
[1m[36mActiveRecord::SchemaMigration Load (0.2ms)[0m [1mSELECT `schema_migrations`.* FROM `schema_migrations`[0m
|
1057
|
+
[1m[36mActiveRecord::SchemaMigration Load (0.7ms)[0m [1mSELECT `schema_migrations`.* FROM `schema_migrations`[0m
|
1058
|
+
Migrating to CreateShoppeCountries (20131017180920)
|
1059
|
+
[1m[35m (16.5ms)[0m CREATE TABLE `shoppe_countries` (`id` int(11) DEFAULT NULL auto_increment PRIMARY KEY, `name` varchar(255), `code2` varchar(255), `code3` varchar(255), `continent` varchar(255), `tld` varchar(255), `currency` varchar(255), `eu_member` tinyint(1) DEFAULT 0) ENGINE=InnoDB
|
1060
|
+
[1m[36m (24.1ms)[0m [1mALTER TABLE `shoppe_orders` ADD `country_id` int(11) AFTER `postcode`[0m
|
1061
|
+
[1m[35m (20.5ms)[0m ALTER TABLE `shoppe_orders` DROP `country`
|
1062
|
+
[1m[36m (0.1ms)[0m [1mBEGIN[0m
|
1063
|
+
[1m[35mSQL (1.9ms)[0m INSERT INTO `schema_migrations` (`version`) VALUES ('20131017180920')
|
1064
|
+
[1m[36m (0.3ms)[0m [1mCOMMIT[0m
|
1065
|
+
Migrating to CreateShoppeTaxRates (20131017183211)
|
1066
|
+
[1m[35m (8.9ms)[0m CREATE TABLE `shoppe_tax_rates` (`id` int(11) DEFAULT NULL auto_increment PRIMARY KEY, `name` varchar(255), `rate` decimal(8,2), `created_at` datetime, `updated_at` datetime) ENGINE=InnoDB
|
1067
|
+
[1m[36m (24.2ms)[0m [1mALTER TABLE `shoppe_products` ADD `tax_rate_id` int(11) AFTER `tax_rate`[0m
|
1068
|
+
[1m[35m (17.3ms)[0m ALTER TABLE `shoppe_products` DROP `tax_rate`
|
1069
|
+
[1m[36m (14.6ms)[0m [1mALTER TABLE `shoppe_delivery_service_prices` ADD `tax_rate_id` int(11) AFTER `tax_rate`[0m
|
1070
|
+
[1m[35m (16.9ms)[0m ALTER TABLE `shoppe_delivery_service_prices` DROP `tax_rate`
|
1071
|
+
[1m[36m (0.1ms)[0m [1mBEGIN[0m
|
1072
|
+
[1m[35mSQL (0.2ms)[0m INSERT INTO `schema_migrations` (`version`) VALUES ('20131017183211')
|
1073
|
+
[1m[36m (0.3ms)[0m [1mCOMMIT[0m
|
1074
|
+
Migrating to AddCountriesToTaxRatesAndDeliveryPrices (20131020204719)
|
1075
|
+
[1m[35m (19.4ms)[0m ALTER TABLE `shoppe_delivery_service_prices` ADD `country_ids` text
|
1076
|
+
[1m[36m (19.5ms)[0m [1mALTER TABLE `shoppe_tax_rates` ADD `country_ids` text[0m
|
1077
|
+
[1m[35m (0.1ms)[0m BEGIN
|
1078
|
+
[1m[36mSQL (0.2ms)[0m [1mINSERT INTO `schema_migrations` (`version`) VALUES ('20131020204719')[0m
|
1079
|
+
[1m[35m (0.3ms)[0m COMMIT
|
1080
|
+
[1m[36mActiveRecord::SchemaMigration Load (0.2ms)[0m [1mSELECT `schema_migrations`.* FROM `schema_migrations`[0m
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: shoppe
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.12
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-10-
|
12
|
+
date: 2013-10-21 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
@@ -378,6 +378,7 @@ files:
|
|
378
378
|
- db/migrate/20131017144430_create_shoppe_stock_level_adjustments.rb
|
379
379
|
- db/migrate/20131017180920_create_shoppe_countries.rb
|
380
380
|
- db/migrate/20131017183211_create_shoppe_tax_rates.rb
|
381
|
+
- db/migrate/20131020204719_add_countries_to_tax_rates_and_delivery_prices.rb
|
381
382
|
- db/seeds.rb
|
382
383
|
- db/seeds_data/poe400.jpg
|
383
384
|
- db/seeds_data/snom-870-blk.jpg
|
@@ -392,6 +393,7 @@ files:
|
|
392
393
|
- db/seeds_data/t46gn.jpg
|
393
394
|
- db/seeds_data/w52p.jpg
|
394
395
|
- db/seeds_data/yhs32.jpg
|
396
|
+
- lib/shoppe/associated_countries.rb
|
395
397
|
- lib/shoppe/country_importer.rb
|
396
398
|
- lib/shoppe/engine.rb
|
397
399
|
- lib/shoppe/errors/inappropriate_delivery_service.rb
|
@@ -462,7 +464,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
462
464
|
version: '0'
|
463
465
|
segments:
|
464
466
|
- 0
|
465
|
-
hash:
|
467
|
+
hash: -2288796444690138098
|
466
468
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
467
469
|
none: false
|
468
470
|
requirements:
|
@@ -471,7 +473,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
471
473
|
version: '0'
|
472
474
|
segments:
|
473
475
|
- 0
|
474
|
-
hash:
|
476
|
+
hash: -2288796444690138098
|
475
477
|
requirements: []
|
476
478
|
rubyforge_project:
|
477
479
|
rubygems_version: 1.8.23
|