solidus_core 1.3.0.beta1 → 1.3.0.rc1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of solidus_core might be problematic. Click here for more details.

Files changed (68) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +1 -1
  3. data/app/assets/images/noimage/large.png +0 -0
  4. data/app/assets/images/noimage/mini.png +0 -0
  5. data/app/assets/images/noimage/product.png +0 -0
  6. data/app/assets/images/noimage/small.png +0 -0
  7. data/app/models/spree/app_configuration.rb +9 -9
  8. data/app/models/spree/country.rb +1 -0
  9. data/app/models/spree/line_item.rb +7 -1
  10. data/app/models/spree/payment_method.rb +1 -1
  11. data/app/models/spree/preferences/preferable.rb +1 -0
  12. data/app/models/spree/preferences/statically_configurable.rb +2 -2
  13. data/app/models/spree/price.rb +30 -2
  14. data/app/models/spree/product.rb +4 -1
  15. data/app/models/spree/stock/inventory_unit_builder.rb +2 -2
  16. data/app/models/spree/tax/tax_location.rb +4 -0
  17. data/app/models/spree/tax_rate.rb +2 -11
  18. data/app/models/spree/variant/price_selector.rb +35 -0
  19. data/app/models/spree/variant/pricing_options.rb +69 -4
  20. data/app/models/spree/variant/vat_price_generator.rb +58 -0
  21. data/app/models/spree/variant.rb +38 -16
  22. data/config/locales/en.yml +22 -1
  23. data/db/migrate/20140410141842_add_many_missing_indexes.rb +15 -13
  24. data/db/migrate/20140410150358_correct_some_polymorphic_index_and_add_more_missing.rb +40 -38
  25. data/db/migrate/20141217215630_update_product_slug_index.rb +4 -2
  26. data/db/migrate/20150723224133_remove_unnecessary_indexes.rb +2 -10
  27. data/db/migrate/20151219020209_add_stock_item_unique_index.rb +2 -2
  28. data/db/migrate/20160509181311_add_country_iso_to_prices.rb +8 -0
  29. data/lib/spree/core/class_constantizer.rb +31 -0
  30. data/lib/spree/core/engine.rb +55 -59
  31. data/lib/spree/core/environment/calculators.rb +6 -1
  32. data/lib/spree/core/environment.rb +5 -2
  33. data/lib/spree/core/environment_extension.rb +16 -12
  34. data/lib/spree/core/price_migrator.rb +32 -0
  35. data/lib/spree/core/search/base.rb +2 -2
  36. data/lib/spree/core/version.rb +1 -1
  37. data/lib/spree/core.rb +4 -0
  38. data/lib/spree/migration_helpers.rb +19 -0
  39. data/lib/spree/money.rb +41 -15
  40. data/lib/spree/promo/environment.rb +2 -1
  41. data/lib/spree/testing_support/controller_requests.rb +22 -7
  42. data/lib/spree/testing_support/factories/state_factory.rb +7 -0
  43. data/lib/spree/testing_support/factories/stock_location_factory.rb +4 -1
  44. data/lib/tasks/migrations/create_vat_prices.rake +11 -0
  45. data/lib/tasks/upgrade.rake +2 -1
  46. data/spec/lib/spree/core/class_constantizer_spec.rb +68 -0
  47. data/spec/lib/spree/core/environment_extension_spec.rb +33 -0
  48. data/spec/lib/spree/core/price_migrator_spec.rb +356 -0
  49. data/spec/lib/spree/core/testing_support/factories/state_factory_spec.rb +9 -0
  50. data/spec/lib/spree/core/testing_support/factories/stock_location_factory_spec.rb +9 -0
  51. data/spec/lib/spree/money_spec.rb +75 -0
  52. data/spec/models/spree/app_configuration_spec.rb +5 -5
  53. data/spec/models/spree/country_spec.rb +16 -0
  54. data/spec/models/spree/line_item_spec.rb +6 -2
  55. data/spec/models/spree/preferences/preferable_spec.rb +5 -0
  56. data/spec/models/spree/preferences/statically_configurable_spec.rb +4 -0
  57. data/spec/models/spree/price_spec.rb +89 -0
  58. data/spec/models/spree/stock/coordinator_spec.rb +9 -0
  59. data/spec/models/spree/stock/splitter/shipping_category_spec.rb +30 -32
  60. data/spec/models/spree/tax/tax_location_spec.rb +14 -5
  61. data/spec/models/spree/tax/taxation_integration_spec.rb +15 -42
  62. data/spec/models/spree/variant/{pricer_spec.rb → price_selector_spec.rb} +41 -1
  63. data/spec/models/spree/variant/pricing_options_spec.rb +87 -4
  64. data/spec/models/spree/variant/vat_price_generator_spec.rb +69 -0
  65. data/spec/models/spree/variant_spec.rb +57 -8
  66. metadata +14 -5
  67. data/app/models/spree/product_scope/scopes.rb +0 -47
  68. data/app/models/spree/variant/pricer.rb +0 -19
@@ -4,15 +4,20 @@ describe Spree::Variant::PricingOptions do
4
4
  subject { described_class.new }
5
5
 
6
6
  context '.default_price_attributes' do
7
+ subject { described_class.default_price_attributes }
8
+
9
+ it { is_expected.to have_key(:currency) }
10
+ it { is_expected.to have_key(:country_iso) }
11
+
7
12
  it 'can be passed into a WHERE clause on Spree::Prices' do
8
- expect(Spree::Price.where(described_class.default_price_attributes).to_a).to eq([])
13
+ expect(Spree::Price.where(subject).to_a).to eq([])
9
14
  end
10
15
 
11
16
  context "with a matching price present" do
12
17
  let!(:price) { create(:price) }
13
18
 
14
19
  it 'returns a matching price' do
15
- expect(Spree::Price.where(described_class.default_price_attributes).to_a).to include(price)
20
+ expect(Spree::Price.where(subject).to_a).to include(price)
16
21
  end
17
22
  end
18
23
  end
@@ -25,9 +30,13 @@ describe Spree::Variant::PricingOptions do
25
30
  expect(subject.desired_attributes[:currency]).to eq("USD")
26
31
  end
27
32
 
33
+ it "takes the orders tax address country" do
34
+ expect(subject.desired_attributes[:country_iso]).to eq("US")
35
+ end
36
+
28
37
  context "if line item has no order" do
29
38
  before do
30
- expect(line_item).to receive(:order).and_return(nil)
39
+ expect(line_item).to receive(:order).at_least(:once).and_return(nil)
31
40
  end
32
41
 
33
42
  it "returns the line item's currency" do
@@ -48,7 +57,7 @@ describe Spree::Variant::PricingOptions do
48
57
  context "if neither order nor line item have a currency" do
49
58
  before do
50
59
  expect(line_item).to receive(:currency).and_return(nil)
51
- expect(line_item).to receive(:order).and_return(nil)
60
+ expect(line_item).to receive(:order).at_least(:once).and_return(nil)
52
61
  expect(Spree::Config).to receive(:currency).at_least(:once).and_return("RUB")
53
62
  end
54
63
 
@@ -58,6 +67,17 @@ describe Spree::Variant::PricingOptions do
58
67
  end
59
68
  end
60
69
 
70
+ context ".from_price" do
71
+ let(:country) { create(:country) }
72
+ let(:price) { create(:price, country: country) }
73
+
74
+ subject { described_class.from_price(price) }
75
+ it "gets the currency from the previous price" do
76
+ expect(subject.currency).to eq(price.currency)
77
+ expect(subject.country_iso).to eq(country.iso)
78
+ end
79
+ end
80
+
61
81
  describe '#desired_attributes' do
62
82
  context "when called with no arguments" do
63
83
  it "returns the default pricing options" do
@@ -72,6 +92,14 @@ describe Spree::Variant::PricingOptions do
72
92
  expect(subject.desired_attributes[:currency]).to eq("EUR")
73
93
  end
74
94
  end
95
+
96
+ context "when called with a different country_iso" do
97
+ subject { described_class.new(country_iso: "DE") }
98
+
99
+ it "returns a Hash with the correct country" do
100
+ expect(subject.desired_attributes[:country_iso]).to eq("DE")
101
+ end
102
+ end
75
103
  end
76
104
 
77
105
  describe "#currency" do
@@ -91,6 +119,23 @@ describe Spree::Variant::PricingOptions do
91
119
  end
92
120
  end
93
121
 
122
+ describe "#country_iso" do
123
+ context "when initialized with no country_iso" do
124
+ it "returns the default country_iso" do
125
+ expect(Spree::Config).to receive(:admin_vat_country_iso).and_return("US")
126
+ expect(subject.country_iso).to eq("US")
127
+ end
128
+ end
129
+
130
+ context "when initialized with a different country_iso" do
131
+ subject { described_class.new(country_iso: "DE") }
132
+
133
+ it "returns that country_iso" do
134
+ expect(subject.country_iso).to eq("DE")
135
+ end
136
+ end
137
+ end
138
+
94
139
  describe "#cache_key" do
95
140
  it 'creates a cache key out of the values of the attributes hash' do
96
141
  expect(subject.cache_key).to eq("USD")
@@ -98,9 +143,47 @@ describe Spree::Variant::PricingOptions do
98
143
 
99
144
  context "with another currency" do
100
145
  subject { described_class.new(currency: "EUR") }
146
+
101
147
  it 'creates the correct cache key' do
102
148
  expect(subject.cache_key).to eq("EUR")
103
149
  end
150
+
151
+ context "and another country" do
152
+ subject { described_class.new(currency: "EUR", country_iso: "DE") }
153
+
154
+ it 'creates the correct cache key' do
155
+ expect(subject.cache_key).to eq("EUR/DE")
156
+ end
157
+ end
158
+ end
159
+ end
160
+
161
+ describe "#search_arguments" do
162
+ let!(:price) { create(:price, currency: "EUR") }
163
+ let(:options) { {} }
164
+
165
+ subject { described_class.new(options).search_arguments }
166
+
167
+ context "with a currency given" do
168
+ let(:options) { { currency: "EUR" } }
169
+
170
+ it 'can be passed into a `where` clause' do
171
+ expect(Spree::Price.where(subject)).to eq([price])
172
+ end
173
+ end
174
+
175
+ context "with no country given" do
176
+ it "is an array with only nil inside" do
177
+ expect(subject[:country_iso]).to eq([nil])
178
+ end
179
+ end
180
+
181
+ context "with a country given" do
182
+ let(:options) { { country_iso: "DE" } }
183
+
184
+ it "is an array with the country and nil" do
185
+ expect(subject[:country_iso]).to eq(["DE", nil])
186
+ end
104
187
  end
105
188
  end
106
189
  end
@@ -0,0 +1,69 @@
1
+ require "spec_helper"
2
+
3
+ describe Spree::Variant::VatPriceGenerator do
4
+ let(:tax_category) { create(:tax_category) }
5
+ let(:product) { variant.product }
6
+ let(:variant) { create(:variant, price: 10, tax_category: tax_category) }
7
+
8
+ subject { described_class.new(variant).run }
9
+
10
+ context "with Germany as default admin country" do
11
+ let(:germany) { create(:country, iso: "DE") }
12
+ let(:germany_zone) { create(:zone, countries: [germany]) }
13
+ let!(:german_vat) { create(:tax_rate, included_in_price: true, amount: 0.19, zone: germany_zone, tax_category: tax_category) }
14
+ let(:france) { create(:country, iso: "FR") }
15
+ let(:france_zone) { create(:zone, countries: [france]) }
16
+ let!(:french_vat) { create(:tax_rate, included_in_price: true, amount: 0.20, zone: france_zone, tax_category: tax_category) }
17
+
18
+ before do
19
+ Spree::Config.admin_vat_country_iso = "DE"
20
+ end
21
+
22
+ it "builds a correct price including VAT for all VAT countries" do
23
+ subject
24
+ variant.save
25
+ variant.reload
26
+ expect(variant.default_price.for_any_country?).to be false
27
+ expect(variant.prices.detect { |p| p.country_iso == "DE" }.try!(:amount)).to eq(10.00)
28
+ expect(variant.prices.detect { |p| p.country_iso == "FR" }.try!(:amount)).to eq(10.08)
29
+ expect(variant.prices.detect { |p| p.country_iso.nil? }.try!(:amount)).to eq(8.40)
30
+ end
31
+
32
+ it "will not build prices that are already present" do
33
+ variant.prices.build(amount: 11, country_iso: "FR")
34
+ variant.prices.build(amount: 11, country_iso: nil)
35
+ expect { subject }.not_to change { variant.prices.length }
36
+ end
37
+ end
38
+
39
+ context "with no default admin country" do
40
+ let(:germany) { create(:country, iso: "DE") }
41
+ let(:germany_zone) { create(:zone, countries: [germany]) }
42
+ let!(:german_vat) { create(:tax_rate, included_in_price: true, amount: 0.19, zone: germany_zone, tax_category: tax_category) }
43
+ let(:france) { create(:country, iso: "FR") }
44
+ let(:france_zone) { create(:zone, countries: [france]) }
45
+ let!(:french_vat) { create(:tax_rate, included_in_price: true, amount: 0.20, zone: france_zone, tax_category: tax_category) }
46
+
47
+ it "builds a correct price including VAT for all VAT countries" do
48
+ subject
49
+ variant.save
50
+ variant.reload
51
+ expect(variant.default_price.for_any_country?).to be true
52
+ expect(variant.prices.detect { |p| p.country_iso == "DE" }.try!(:amount)).to eq(11.90)
53
+ expect(variant.prices.detect { |p| p.country_iso == "FR" }.try!(:amount)).to eq(12.00)
54
+ expect(variant.prices.detect { |p| p.country_iso.nil? }.try!(:amount)).to eq(10.00)
55
+ end
56
+ end
57
+
58
+ context "for a variant with not tax category" do
59
+ let(:tax_category) { nil }
60
+
61
+ before do
62
+ product.update(tax_category: nil)
63
+ end
64
+
65
+ it "creates no addditional prices" do
66
+ expect { subject }.not_to change { variant.prices.length }
67
+ end
68
+ end
69
+ end
@@ -52,6 +52,55 @@ describe Spree::Variant, type: :model do
52
52
  it { expect(product.master).to_not be_in_stock }
53
53
  end
54
54
  end
55
+
56
+ context "when several countries have VAT" do
57
+ let(:germany) { create(:country, iso: "DE") }
58
+ let(:denmark) { create(:country, iso: "DK") }
59
+ let(:france) { create(:country, iso: "FR") }
60
+
61
+ let(:high_vat_zone) { create(:zone, countries: [germany, denmark]) }
62
+ let(:low_vat_zone) { create(:zone, countries: [france]) }
63
+
64
+ let(:tax_category) { create(:tax_category) }
65
+
66
+ let!(:high_vat) { create(:tax_rate, included_in_price: true, amount: 0.25, zone: high_vat_zone, tax_category: tax_category) }
67
+ let!(:low_vat) { create(:tax_rate, included_in_price: true, amount: 0.15, zone: low_vat_zone, tax_category: tax_category) }
68
+
69
+ let(:product) { create(:product, tax_category: tax_category) }
70
+
71
+ subject(:new_variant) { create(:variant, price: 15, product: product) }
72
+
73
+ it "creates the appropriate prices for them" do
74
+ # default price + FR, DE, DK
75
+ expect { new_variant }.to change { Spree::Price.count }.by(4)
76
+ expect(new_variant.prices.find_by(country_iso: "FR").amount).to eq(17.25)
77
+ expect(new_variant.prices.find_by(country_iso: "DE").amount).to eq(18.75)
78
+ expect(new_variant.prices.find_by(country_iso: "DK").amount).to eq(18.75)
79
+ expect(new_variant.prices.find_by(country_iso: nil).amount).to eq(15.00)
80
+ end
81
+
82
+ context "when the products price changes" do
83
+ context "and rebuild_vat_prices is set to true" do
84
+ subject { variant.update(price: 99, rebuild_vat_prices: true, tax_category: tax_category) }
85
+
86
+ it "creates new appropriate prices for this variant" do
87
+ expect { subject }.to change { Spree::Price.count }.by(3)
88
+ expect(variant.prices.find_by(country_iso: "FR").amount).to eq(113.85)
89
+ expect(variant.prices.find_by(country_iso: "DE").amount).to eq(123.75)
90
+ expect(variant.prices.find_by(country_iso: "DK").amount).to eq(123.75)
91
+ expect(variant.prices.find_by(country_iso: nil).amount).to eq(99.00)
92
+ end
93
+ end
94
+
95
+ context "and rebuild_vat_prices is not set" do
96
+ subject { variant.update(price: 99, tax_category: tax_category) }
97
+
98
+ it "does not create new prices" do
99
+ expect { subject }.not_to change { Spree::Price.count }
100
+ end
101
+ end
102
+ end
103
+ end
55
104
  end
56
105
 
57
106
  context "product has other variants" do
@@ -182,23 +231,23 @@ describe Spree::Variant, type: :model do
182
231
  end
183
232
  end
184
233
 
185
- context "#pricer" do
186
- subject { variant.pricer }
234
+ context "#price_selector" do
235
+ subject { variant.price_selector }
187
236
 
188
- it "returns an instance of a pricer" do
189
- expect(variant.pricer).to be_a(Spree::Config.variant_pricer_class)
237
+ it "returns an instance of a price selector" do
238
+ expect(variant.price_selector).to be_a(Spree::Config.variant_price_selector_class)
190
239
  end
191
240
 
192
241
  it "is instacached" do
193
- expect(variant.pricer.object_id).to eq(variant.pricer.object_id)
242
+ expect(variant.price_selector.object_id).to eq(variant.price_selector.object_id)
194
243
  end
195
244
  end
196
245
 
197
246
  context "#price_for(price_options)" do
198
- let(:price_options) { Spree::Config.variant_pricer_class.pricing_options_class.new }
247
+ let(:price_options) { Spree::Config.variant_price_selector_class.pricing_options_class.new }
199
248
 
200
- it "calls the pricer with the given options object" do
201
- expect(variant.pricer).to receive(:price_for).with(price_options)
249
+ it "calls the price selector with the given options object" do
250
+ expect(variant.price_selector).to receive(:price_for).with(price_options)
202
251
  variant.price_for(price_options)
203
252
  end
204
253
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: solidus_core
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.0.beta1
4
+ version: 1.3.0.rc1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Solidus Team
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-04-25 00:00:00.000000000 Z
11
+ date: 2016-06-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemerchant
@@ -435,7 +435,6 @@ files:
435
435
  - app/models/spree/product_option_type.rb
436
436
  - app/models/spree/product_promotion_rule.rb
437
437
  - app/models/spree/product_property.rb
438
- - app/models/spree/product_scope/scopes.rb
439
438
  - app/models/spree/promotion.rb
440
439
  - app/models/spree/promotion/actions/create_adjustment.rb
441
440
  - app/models/spree/promotion/actions/create_item_adjustments.rb
@@ -555,9 +554,10 @@ files:
555
554
  - app/models/spree/user_stock_location.rb
556
555
  - app/models/spree/validations/db_maximum_length_validator.rb
557
556
  - app/models/spree/variant.rb
558
- - app/models/spree/variant/pricer.rb
557
+ - app/models/spree/variant/price_selector.rb
559
558
  - app/models/spree/variant/pricing_options.rb
560
559
  - app/models/spree/variant/scopes.rb
560
+ - app/models/spree/variant/vat_price_generator.rb
561
561
  - app/models/spree/variant_property_rule.rb
562
562
  - app/models/spree/variant_property_rule_condition.rb
563
563
  - app/models/spree/variant_property_rule_value.rb
@@ -880,6 +880,7 @@ files:
880
880
  - db/migrate/20160308000300_disallow_adjustment_finalized_nulls.rb
881
881
  - db/migrate/20160318145302_add_timestamps_to_prices.rb
882
882
  - db/migrate/20160330204846_add_missing_timestamp_columns.rb
883
+ - db/migrate/20160509181311_add_country_iso_to_prices.rb
883
884
  - db/seeds.rb
884
885
  - lib/generators/spree/custom_user/custom_user_generator.rb
885
886
  - lib/generators/spree/custom_user/templates/authentication_helpers.rb.tt
@@ -901,6 +902,7 @@ files:
901
902
  - lib/generators/spree/install/templates/vendor/assets/stylesheets/spree/frontend/all.css
902
903
  - lib/solidus_core.rb
903
904
  - lib/spree/core.rb
905
+ - lib/spree/core/class_constantizer.rb
904
906
  - lib/spree/core/controller_helpers/auth.rb
905
907
  - lib/spree/core/controller_helpers/common.rb
906
908
  - lib/spree/core/controller_helpers/order.rb
@@ -920,6 +922,7 @@ files:
920
922
  - lib/spree/core/importer/order.rb
921
923
  - lib/spree/core/importer/product.rb
922
924
  - lib/spree/core/permalinks.rb
925
+ - lib/spree/core/price_migrator.rb
923
926
  - lib/spree/core/product_duplicator.rb
924
927
  - lib/spree/core/product_filters.rb
925
928
  - lib/spree/core/role_configuration.rb
@@ -935,6 +938,7 @@ files:
935
938
  - lib/spree/localized_number.rb
936
939
  - lib/spree/mailer_previews/carton_preview.rb
937
940
  - lib/spree/mailer_previews/order_preview.rb
941
+ - lib/spree/migration_helpers.rb
938
942
  - lib/spree/migrations.rb
939
943
  - lib/spree/money.rb
940
944
  - lib/spree/permission_sets.rb
@@ -1048,6 +1052,7 @@ files:
1048
1052
  - lib/tasks/migrations/assure_store_on_orders.rake
1049
1053
  - lib/tasks/migrations/copy_order_bill_address_to_credit_card.rake
1050
1054
  - lib/tasks/migrations/copy_shipped_shipments_to_cartons.rake
1055
+ - lib/tasks/migrations/create_vat_prices.rake
1051
1056
  - lib/tasks/migrations/migrate_shipping_rate_taxes.rake
1052
1057
  - lib/tasks/migrations/migrate_user_addresses.rake
1053
1058
  - lib/tasks/order_capturing.rake
@@ -1063,6 +1068,7 @@ files:
1063
1068
  - spec/lib/i18n_spec.rb
1064
1069
  - spec/lib/search/base_spec.rb
1065
1070
  - spec/lib/search/variant_spec.rb
1071
+ - spec/lib/spree/core/class_constantizer_spec.rb
1066
1072
  - spec/lib/spree/core/controller_helpers/auth_spec.rb
1067
1073
  - spec/lib/spree/core/controller_helpers/order_spec.rb
1068
1074
  - spec/lib/spree/core/controller_helpers/payment_parameters_spec.rb
@@ -1072,7 +1078,9 @@ files:
1072
1078
  - spec/lib/spree/core/controller_helpers/strong_parameters_spec.rb
1073
1079
  - spec/lib/spree/core/current_store_spec.rb
1074
1080
  - spec/lib/spree/core/delegate_belongs_to_spec.rb
1081
+ - spec/lib/spree/core/environment_extension_spec.rb
1075
1082
  - spec/lib/spree/core/importer/order_spec.rb
1083
+ - spec/lib/spree/core/price_migrator_spec.rb
1076
1084
  - spec/lib/spree/core/role_configuration_spec.rb
1077
1085
  - spec/lib/spree/core/stock_configuration_spec.rb
1078
1086
  - spec/lib/spree/core/testing_support/factories/address_factory_spec.rb
@@ -1342,9 +1350,10 @@ files:
1342
1350
  - spec/models/spree/unit_cancel_spec.rb
1343
1351
  - spec/models/spree/user_spec.rb
1344
1352
  - spec/models/spree/validations/db_maximum_length_validator_spec.rb
1345
- - spec/models/spree/variant/pricer_spec.rb
1353
+ - spec/models/spree/variant/price_selector_spec.rb
1346
1354
  - spec/models/spree/variant/pricing_options_spec.rb
1347
1355
  - spec/models/spree/variant/scopes_spec.rb
1356
+ - spec/models/spree/variant/vat_price_generator_spec.rb
1348
1357
  - spec/models/spree/variant_property_rule_condition_spec.rb
1349
1358
  - spec/models/spree/variant_property_rule_spec.rb
1350
1359
  - spec/models/spree/variant_property_rule_value_spec.rb
@@ -1,47 +0,0 @@
1
- module Spree
2
- class ProductScope < Spree::Base
3
- before_validation(on: :create) do
4
- # Add default empty arguments so scope validates and errors aren't caused when previewing it
5
- if name && args = self.class.arguments_for_scope_name(name)
6
- self.arguments ||= [''] * args.length
7
- end
8
- end
9
-
10
- def self.all_scopes
11
- {
12
- # Scopes for selecting products based on taxon
13
- taxon: {
14
- taxons_name_eq: [:taxon_name],
15
- in_taxons: [:taxon_names]
16
- },
17
- # product selection based on name, or search
18
- search: {
19
- in_name: [:words],
20
- in_name_or_keywords: [:words],
21
- in_name_or_description: [:words],
22
- with_ids: [:ids]
23
- },
24
- # Scopes for selecting products based on option types and properties
25
- values: {
26
- with: [:value],
27
- with_property: [:property],
28
- with_property_value: [:property, :value],
29
- with_option: [:option],
30
- with_option_value: [:option, :value]
31
- },
32
- # product selection based upon master price
33
- price: {
34
- price_between: [:low, :high],
35
- master_price_lte: [:amount],
36
- master_price_gte: [:amount]
37
- }
38
- }
39
- end
40
-
41
- def self.arguments_for_scope_name(name)
42
- if group = all_scopes.detect { |_k, v| v[name.to_sym] }
43
- group[1][name.to_sym]
44
- end
45
- end
46
- end
47
- end
@@ -1,19 +0,0 @@
1
- module Spree
2
- class Variant
3
- class Pricer
4
- def self.pricing_options_class
5
- Spree::Variant::PricingOptions
6
- end
7
-
8
- attr_reader :variant
9
-
10
- def initialize(variant)
11
- @variant = variant
12
- end
13
-
14
- def price_for(price_options)
15
- variant.prices.currently_valid.find_by(price_options.desired_attributes).try!(:money)
16
- end
17
- end
18
- end
19
- end