solidus_core 2.0.3 → 2.1.0.beta1

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.
Files changed (187) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +62 -3
  3. data/app/assets/javascripts/spree.js.coffee.erb +4 -1
  4. data/app/helpers/spree/base_helper.rb +7 -48
  5. data/app/models/spree/address.rb +5 -1
  6. data/app/models/spree/adjustment.rb +3 -3
  7. data/app/models/spree/app_configuration.rb +13 -0
  8. data/app/models/spree/calculator.rb +3 -2
  9. data/app/models/spree/calculator/default_tax.rb +6 -10
  10. data/app/models/spree/calculator/flat_percent_item_total.rb +0 -4
  11. data/app/models/spree/calculator/flat_rate.rb +0 -4
  12. data/app/models/spree/calculator/flexi_rate.rb +0 -4
  13. data/app/models/spree/calculator/free_shipping.rb +0 -3
  14. data/app/models/spree/calculator/percent_on_line_item.rb +0 -4
  15. data/app/models/spree/calculator/percent_per_item.rb +0 -4
  16. data/app/models/spree/calculator/price_sack.rb +0 -4
  17. data/app/models/spree/calculator/returns/default_refund_amount.rb +0 -3
  18. data/app/models/spree/calculator/shipping/flat_percent_item_total.rb +0 -4
  19. data/app/models/spree/calculator/shipping/flat_rate.rb +0 -4
  20. data/app/models/spree/calculator/shipping/flexi_rate.rb +0 -4
  21. data/app/models/spree/calculator/shipping/per_item.rb +0 -4
  22. data/app/models/spree/calculator/shipping/price_sack.rb +0 -4
  23. data/app/models/spree/calculator/tiered_flat_rate.rb +0 -4
  24. data/app/models/spree/calculator/tiered_percent.rb +0 -4
  25. data/app/models/spree/credit_card.rb +27 -14
  26. data/app/models/spree/gateway.rb +4 -0
  27. data/app/models/spree/inventory_unit.rb +2 -0
  28. data/app/models/spree/line_item.rb +31 -26
  29. data/app/models/spree/option_type.rb +0 -3
  30. data/app/models/spree/order.rb +28 -31
  31. data/app/models/spree/order/checkout.rb +0 -2
  32. data/app/models/spree/order_contents.rb +0 -45
  33. data/app/models/spree/order_merger.rb +6 -6
  34. data/app/models/spree/order_update_attributes.rb +0 -2
  35. data/app/models/spree/order_updater.rb +91 -13
  36. data/app/models/spree/payment.rb +9 -2
  37. data/app/models/spree/payment/processing.rb +15 -9
  38. data/app/models/spree/payment_method.rb +48 -5
  39. data/app/models/spree/price.rb +7 -9
  40. data/app/models/spree/product.rb +1 -25
  41. data/app/models/spree/promotion.rb +22 -14
  42. data/app/models/spree/promotion/actions/create_adjustment.rb +12 -1
  43. data/app/models/spree/promotion/actions/create_item_adjustments.rb +15 -1
  44. data/app/models/spree/promotion/actions/create_quantity_adjustments.rb +5 -3
  45. data/app/models/spree/promotion/actions/free_shipping.rb +14 -0
  46. data/app/models/spree/promotion/rules/taxon.rb +7 -2
  47. data/app/models/spree/promotion/rules/user_role.rb +43 -0
  48. data/app/models/spree/promotion_action.rb +19 -2
  49. data/app/models/spree/promotion_handler/coupon.rb +1 -4
  50. data/app/models/spree/promotion_handler/free_shipping.rb +22 -17
  51. data/app/models/spree/promotion_rule_role.rb +6 -0
  52. data/app/models/spree/property.rb +0 -3
  53. data/app/models/spree/return_authorization.rb +2 -0
  54. data/app/models/spree/shipment.rb +5 -21
  55. data/app/models/spree/shipping_method.rb +23 -2
  56. data/app/models/spree/shipping_rate.rb +3 -0
  57. data/app/models/spree/stock/estimator.rb +1 -1
  58. data/app/models/spree/stock_location.rb +3 -0
  59. data/app/models/spree/store.rb +7 -0
  60. data/app/models/spree/tax/item_adjuster.rb +27 -12
  61. data/app/models/spree/tax/order_adjuster.rb +2 -5
  62. data/app/models/spree/tax/tax_helpers.rb +4 -8
  63. data/app/models/spree/tax_rate.rb +1 -15
  64. data/app/models/spree/taxon.rb +0 -3
  65. data/app/models/spree/transfer_item.rb +1 -1
  66. data/app/models/spree/user_class_handle.rb +14 -9
  67. data/app/models/spree/variant/pricing_options.rb +1 -1
  68. data/app/models/spree/wallet/add_payment_sources_to_wallet.rb +1 -1
  69. data/app/models/spree/zone.rb +20 -13
  70. data/config/locales/en.yml +144 -62
  71. data/db/migrate/20120831092320_spree_one_two.rb +0 -7
  72. data/db/migrate/20150723224133_remove_unnecessary_indexes.rb +0 -2
  73. data/db/migrate/20160924135758_remove_is_default_from_prices.rb +5 -0
  74. data/db/migrate/20161009141333_remove_currency_from_line_items.rb +5 -0
  75. data/db/migrate/20161014221052_add_available_to_columns_and_remove_display_on_from_payment_methods.rb +28 -0
  76. data/db/migrate/20161123154034_add_available_to_users_and_remove_display_on_from_shipping_methods.rb +20 -0
  77. data/lib/generators/spree/custom_user/templates/authentication_helpers.rb.tt +4 -0
  78. data/lib/generators/spree/dummy/dummy_generator.rb +0 -2
  79. data/lib/spree/core.rb +0 -5
  80. data/lib/spree/core/controller_helpers/pricing.rb +2 -1
  81. data/lib/spree/core/engine.rb +14 -0
  82. data/lib/spree/core/version.rb +1 -1
  83. data/lib/spree/deprecation.rb +1 -1
  84. data/lib/spree/localized_number.rb +3 -2
  85. data/lib/spree/permission_sets/configuration_display.rb +0 -1
  86. data/lib/spree/permission_sets/configuration_management.rb +0 -1
  87. data/lib/spree/permission_sets/product_display.rb +0 -1
  88. data/lib/spree/permission_sets/product_management.rb +0 -1
  89. data/lib/spree/permission_sets/user_management.rb +2 -4
  90. data/lib/spree/permitted_attributes.rb +3 -2
  91. data/lib/spree/testing_support/capybara_ext.rb +0 -12
  92. data/lib/spree/testing_support/factories/address_factory.rb +1 -1
  93. data/lib/spree/testing_support/factories/line_item_factory.rb +0 -1
  94. data/lib/spree/testing_support/factories/payment_factory.rb +4 -0
  95. data/lib/spree/testing_support/factories/payment_method_factory.rb +8 -1
  96. data/lib/spree/testing_support/factories/user_factory.rb +2 -2
  97. data/solidus_core.gemspec +4 -3
  98. data/spec/helpers/base_helper_spec.rb +0 -40
  99. data/spec/lib/spree/core/controller_helpers/pricing_spec.rb +16 -0
  100. data/spec/lib/spree/core/importer/order_spec.rb +27 -18
  101. data/spec/lib/spree/core/price_migrator_spec.rb +3 -1
  102. data/spec/lib/spree/core/testing_support/factories/order_factory_spec.rb +16 -0
  103. data/spec/lib/spree/core/unreturned_item_charger_spec.rb +0 -2
  104. data/spec/lib/tasks/exchanges_spec.rb +4 -2
  105. data/spec/lib/tasks/migrations/create_vat_prices_spec.rb +5 -3
  106. data/spec/models/spree/adjustment_spec.rb +136 -0
  107. data/spec/models/spree/calculator/default_tax_spec.rb +13 -7
  108. data/spec/models/spree/calculator/flat_percent_item_total_spec.rb +3 -0
  109. data/spec/models/spree/calculator/flat_rate_spec.rb +3 -0
  110. data/spec/models/spree/calculator/flexi_rate_spec.rb +3 -0
  111. data/spec/models/spree/calculator/free_shipping_spec.rb +6 -0
  112. data/spec/models/spree/calculator/percent_on_line_item_spec.rb +9 -4
  113. data/spec/models/spree/calculator/percent_per_item_spec.rb +10 -0
  114. data/spec/models/spree/calculator/price_sack_spec.rb +3 -0
  115. data/spec/models/spree/calculator/refunds/default_refund_amount_spec.rb +3 -0
  116. data/spec/models/spree/calculator/shipping/flat_percent_item_total_spec.rb +3 -0
  117. data/spec/models/spree/calculator/shipping/flat_rate_spec.rb +3 -0
  118. data/spec/models/spree/calculator/shipping/flexi_rate_spec.rb +3 -0
  119. data/spec/models/spree/calculator/shipping/per_item_spec.rb +3 -0
  120. data/spec/models/spree/calculator/shipping/price_sack_spec.rb +4 -1
  121. data/spec/models/spree/calculator/tiered_flat_rate_spec.rb +3 -0
  122. data/spec/models/spree/calculator/tiered_percent_spec.rb +3 -0
  123. data/spec/models/spree/credit_card_spec.rb +27 -1
  124. data/spec/models/spree/line_item_spec.rb +58 -65
  125. data/spec/models/spree/order/checkout_spec.rb +2 -1
  126. data/spec/models/spree/order/payment_spec.rb +9 -10
  127. data/spec/models/spree/order/tax_spec.rb +22 -7
  128. data/spec/models/spree/order/updating_spec.rb +1 -3
  129. data/spec/models/spree/order_cancellations_spec.rb +6 -4
  130. data/spec/models/spree/order_contents_spec.rb +34 -50
  131. data/spec/models/spree/order_inventory_spec.rb +3 -5
  132. data/spec/models/spree/order_merger_spec.rb +20 -0
  133. data/spec/models/spree/order_spec.rb +28 -64
  134. data/spec/models/spree/order_update_attributes_spec.rb +1 -5
  135. data/spec/models/spree/order_updater_spec.rb +251 -0
  136. data/spec/models/spree/payment_method_spec.rb +178 -28
  137. data/spec/models/spree/payment_spec.rb +35 -19
  138. data/spec/models/spree/permission_sets/configuration_display.rb +0 -4
  139. data/spec/models/spree/permission_sets/configuration_management_spec.rb +0 -2
  140. data/spec/models/spree/permission_sets/product_display_spec.rb +0 -4
  141. data/spec/models/spree/permission_sets/product_management_spec.rb +0 -2
  142. data/spec/models/spree/permission_sets/user_management_spec.rb +9 -2
  143. data/spec/models/spree/price_spec.rb +16 -1
  144. data/spec/models/spree/product_spec.rb +0 -75
  145. data/spec/models/spree/promotion/actions/create_adjustment_spec.rb +20 -0
  146. data/spec/models/spree/promotion/actions/create_item_adjustments_spec.rb +39 -15
  147. data/spec/models/spree/promotion/actions/create_quantity_adjustments_spec.rb +203 -22
  148. data/spec/models/spree/promotion/actions/free_shipping_spec.rb +22 -3
  149. data/spec/models/spree/promotion/rules/taxon_spec.rb +26 -0
  150. data/spec/models/spree/promotion/rules/user_role_spec.rb +86 -0
  151. data/spec/models/spree/promotion_action_spec.rb +38 -0
  152. data/spec/models/spree/promotion_handler/coupon_spec.rb +36 -33
  153. data/spec/models/spree/promotion_handler/free_shipping_spec.rb +21 -22
  154. data/spec/models/spree/promotion_spec.rb +46 -6
  155. data/spec/models/spree/reimbursement_spec.rb +1 -1
  156. data/spec/models/spree/reimbursement_tax_calculator_spec.rb +2 -2
  157. data/spec/models/spree/shipment_spec.rb +68 -50
  158. data/spec/models/spree/shipping_method_spec.rb +41 -0
  159. data/spec/models/spree/shipping_rate_spec.rb +9 -3
  160. data/spec/models/spree/stock/estimator_spec.rb +4 -2
  161. data/spec/models/spree/store_credit_spec.rb +3 -3
  162. data/spec/models/spree/tax/item_adjuster_spec.rb +31 -21
  163. data/spec/models/spree/tax/order_adjuster_spec.rb +6 -10
  164. data/spec/models/spree/tax/taxation_integration_spec.rb +19 -0
  165. data/spec/models/spree/tax_rate_spec.rb +5 -26
  166. data/spec/models/spree/transfer_item_spec.rb +11 -0
  167. data/spec/models/spree/variant/pricing_options_spec.rb +7 -17
  168. data/spec/models/spree/variant_spec.rb +2 -4
  169. data/spec/models/spree/zone_spec.rb +60 -20
  170. data/spec/shared_examples/calculator_shared_examples.rb +8 -0
  171. metadata +19 -24
  172. data/app/models/spree/item_adjustments.rb +0 -89
  173. data/app/models/spree/option_type_prototype.rb +0 -6
  174. data/app/models/spree/property_prototype.rb +0 -6
  175. data/app/models/spree/prototype.rb +0 -14
  176. data/app/models/spree/prototype_taxon.rb +0 -6
  177. data/app/models/spree/tracker.rb +0 -8
  178. data/db/migrate/20150128032538_remove_environment_from_tracker.rb +0 -6
  179. data/lib/generators/spree/dummy/templates/initializers/custom_user.rb +0 -1
  180. data/lib/spree/core/delegate_belongs_to.rb +0 -94
  181. data/lib/spree/testing_support/factories/prototype_factory.rb +0 -8
  182. data/lib/spree/testing_support/factories/tracker_factory.rb +0 -6
  183. data/spec/lib/spree/core/delegate_belongs_to_spec.rb +0 -24
  184. data/spec/lib/spree/core/testing_support/factories/prototype_factory_spec.rb +0 -12
  185. data/spec/lib/spree/core/testing_support/factories/tracker_factory_spec.rb +0 -12
  186. data/spec/models/spree/item_adjustments_spec.rb +0 -306
  187. data/spec/models/spree/tracker_spec.rb +0 -21
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5a6f386d4b02423363675c20943ec411a624d36d
4
- data.tar.gz: c651d02f3bed317f62d21268d60f90981897fc0f
3
+ metadata.gz: d27a7b1fb09b6aa81702049ad833916e12b1aa1b
4
+ data.tar.gz: 6ece03114b6598ab2dc3bebe5469f48d442e8e2e
5
5
  SHA512:
6
- metadata.gz: 1018c8b201487476b9684120b094bc414bc0dfebb49a29fb768b855c16462cae88d6224e54964eb307a36f28be21cef04311ee15c93faf302065c39aff8929f3
7
- data.tar.gz: 2c1499844ad3177827d67dbf554eccb46d228c1a5142207b5ce66e84bb06a74fd477fbbb83bb8efe4793ab49d8155f87157ad1352de7dd2c97e49de649bf3314
6
+ metadata.gz: c100bab17654d3fabdf7fe3534f7a98881a9a177033b576cd3fe5fa1cf575bf2610b87e8dc8348dfa616566e3e32fa5b8795484fada7dc7c3e376890fb3d3345
7
+ data.tar.gz: ef65a5ccb1f92b9c9d7695db45cc98bada5b2343f70d6dc9435c9eb32e4110eea34c80dcb4db5ef0fde1bcb29f3584bbbdd0bf2e4dbb851bb0f4493aa2a121a3
data/README.md CHANGED
@@ -1,9 +1,68 @@
1
- # solidus\_core
1
+ Summary
2
+ ------
3
+ Solidus Core provides the essential e-commerce data models upon which the
4
+ Solidus system depends.
2
5
 
3
- Core contains all the models and the majority of the logic for the Solidus
4
- ecommerce system.
6
+ Core Models
7
+ -----------
8
+ Solidus implements over 200 [models](https://github.com/solidusio/solidus/tree/master/core/app/models/spree),
9
+ and thus a deep inspection of each in this README would be overkill. Instead,
10
+ let's take a quick look at the fundamental models upon which all else depend.
11
+ Currently, these models remain in the Spree namespace as part of the legacy of
12
+ [forking Spree](https://solidus.io/blog/2015/10/28/future-of-spree.html).
5
13
 
14
+ ## NOTE: Documentation is a work in progress
15
+ The documentation of Solidus Core is still in progress. Contributions following
16
+ this form are welcome and encouraged!
6
17
 
18
+ * [The Order Sub-System](#the-order-sub-system)
19
+ * [The User Sub-System](#the-user-sub-system)
20
+ * [The Payment Sub-System](#the-payment-sub-system)
21
+ * [The Inventory Sub-System](#the-inventory-sub-system)
22
+ * [The Shipments Sub-System](#the-shipments-sub-system)
23
+
24
+ ## The Order Sub-System
25
+ * `Spree::Store` - Records store specific configuration such as store name and URL.
26
+ * `Spree::Order` - The customers cart until completed, then acts as
27
+ permenent record of the transaction.
28
+ * `Spree::LineItem` - Variants placed in the order at a particular price.
29
+
30
+ ## The User Sub-System
31
+ * `Spree::LegacyUser` - Default implementation of User.
32
+ * `Spree::UserClassHandle` - Configuration point for User model implementation.
33
+ * [solidus_auth_devise](https://github.com/solidusio/solidus_auth_devise) -
34
+ An offical, more robust implementation of a User class with Devise
35
+ integration.
36
+
37
+ ## The Payment Sub-System
38
+ * `Spree::Payment` - Manage and process a payment for an order, from a specific
39
+ source (e.g. `Spree::CreditCard`) using a specific payment method (e.g
40
+ `Solidus::Gateway::Braintree`).
41
+ * `Spree::PaymentMethod` - An abstract class which is implemented most commonly
42
+ as a `Spree::Gateway`.
43
+ * `Spree::Gateway` - A concrete implementation of `Spree::PaymentMethod`
44
+ intended to provide a base for extension. See
45
+ https://github.com/solidusio/solidus_gateway/ for offically supported payment
46
+ gateway implementations.
47
+ * `Spree::CreditCard` - The default `source` of a `Spree::Payment`.
48
+
49
+ ## The Inventory Sub-System
50
+ * `Spree::ReturnAuthorization` - Models the return of Inventory Units to
51
+ a Stock Location for an Order.
52
+ * `Spree::StockLocation` - Records the name and addresses from which stock items
53
+ are fulfilled in cartons.
54
+ * `Spree::InventoryUnit` - Tracks the state of line items' fulfillment.
55
+ * `Spree::ShippingRate` - Records the costs of different shipping methods for a
56
+ shipment and which method has been selected to deliver the shipment.
57
+ * `Spree::ShippingMethod` - Represents a means of having a shipment delivered,
58
+ such as FedEx or UPS.
59
+
60
+ ## The Shipments Sub-System
61
+ * `Spree::Shipment` - An order's planned shipments including
62
+ tracking and cost. Shipments are fulfilled from Stock Locations.
63
+
64
+ Developer Notes
65
+ ---------------
7
66
  ## Testing
8
67
 
9
68
  Create the test site
@@ -1,7 +1,10 @@
1
1
  #= require jsuri
2
2
  class window.Spree
3
3
  @ready: (callback) ->
4
- jQuery(document).ready(callback)
4
+ if typeof Turbolinks isnt 'undefined' and Turbolinks.supported
5
+ jQuery(document).on 'turbolinks:load', -> callback(jQuery)
6
+ else
7
+ jQuery(document).ready(callback)
5
8
 
6
9
  @mountedAt: ->
7
10
  "<%= Rails.application.routes.url_helpers.spree_path(trailing_slash: true) %>"
@@ -66,8 +66,8 @@ module Spree
66
66
  nil
67
67
  end
68
68
 
69
- def taxon_breadcrumbs(taxon, separator = "&nbsp;&raquo;&nbsp;", breadcrumb_class = "inline")
70
- return "" if current_page?("/") || taxon.nil?
69
+ def taxon_breadcrumbs(taxon, separator = '&nbsp;&raquo;&nbsp;', breadcrumb_class = 'inline')
70
+ return '' if current_page?('/') || taxon.nil?
71
71
 
72
72
  crumbs = [[Spree.t(:home), spree.root_path]]
73
73
 
@@ -81,15 +81,15 @@ module Spree
81
81
 
82
82
  separator = raw(separator)
83
83
 
84
- crumbs.map! do |crumb|
85
- content_tag(:li, itemscope: "itemscope", itemtype: "http://data-vocabulary.org/Breadcrumb") do
86
- link_to(crumb.last, itemprop: "url") do
87
- content_tag(:span, crumb.first, itemprop: "title")
84
+ items = crumbs.each_with_index.collect do |crumb, i|
85
+ content_tag(:li, itemprop: 'itemListElement', itemscope: '', itemtype: 'https://schema.org/ListItem') do
86
+ link_to(crumb.last, itemprop: 'item') do
87
+ content_tag(:span, crumb.first, itemprop: 'name') + tag('meta', { itemprop: 'position', content: (i+1).to_s }, false, false)
88
88
  end + (crumb == crumbs.last ? '' : separator)
89
89
  end
90
90
  end
91
91
 
92
- content_tag(:nav, content_tag(:ul, raw(crumbs.map(&:mb_chars).join), class: breadcrumb_class), id: 'breadcrumbs', class: 'sixteen columns')
92
+ content_tag(:nav, content_tag(:ol, raw(items.map(&:mb_chars).join), class: breadcrumb_class, itemscope: '', itemtype: 'https://schema.org/BreadcrumbList'), id: 'breadcrumbs', class: 'sixteen columns')
93
93
  end
94
94
 
95
95
  def taxons_tree(root_taxon, current_taxon, max_level = 1)
@@ -134,15 +134,6 @@ module Spree
134
134
  time.strftime("%l:%M %p")].join(" ")
135
135
  end
136
136
 
137
- def method_missing(method_name, *args, &block)
138
- if image_style = image_style_from_method_name(method_name)
139
- define_image_method(image_style)
140
- send(method_name, *args)
141
- else
142
- super
143
- end
144
- end
145
-
146
137
  def link_to_tracking(shipment, options = {})
147
138
  return unless shipment.tracking && shipment.shipping_method
148
139
 
@@ -157,37 +148,5 @@ module Spree
157
148
  resource_class.model_name.human(count: Spree::I18N_GENERIC_PLURAL)
158
149
  end
159
150
 
160
- private
161
-
162
- # Returns style of image or nil
163
- def image_style_from_method_name(method_name)
164
- if method_name.to_s.match(/_image$/) && style = method_name.to_s.sub(/_image$/, '')
165
- possible_styles = Spree::Image.attachment_definitions[:attachment][:styles]
166
- style if style.in? possible_styles.with_indifferent_access
167
- end
168
- end
169
-
170
- def create_product_image_tag(image, product, options, style)
171
- options.reverse_merge! alt: image.alt.blank? ? product.name : image.alt
172
- image_tag image.attachment.url(style), options
173
- end
174
-
175
- def define_image_method(style)
176
- self.class.send :define_method, "#{style}_image" do |product, *options|
177
- Spree::Deprecation.warn "Spree image helpers will be deprecated in the near future. Use the provided resource to access the intendend image directly.", caller
178
- options = options.first || {}
179
- if product.images.empty?
180
- if !product.is_a?(Spree::Variant) && !product.variant_images.empty?
181
- create_product_image_tag(product.variant_images.first, product, options, style)
182
- elsif product.is_a?(Variant) && !product.product.variant_images.empty?
183
- create_product_image_tag(product.product.variant_images.first, product, options, style)
184
- else
185
- image_tag "noimage/#{style}.png", options
186
- end
187
- else
188
- create_product_image_tag(product.images.first, product, options, style)
189
- end
190
- end
191
- end
192
151
  end
193
152
  end
@@ -1,13 +1,17 @@
1
1
  require 'twitter_cldr'
2
2
 
3
3
  module Spree
4
+ # `Spree::Address` provides the foundational ActiveRecord model for recording and
5
+ # validating address information for `Spree::Order`, `Spree::Shipment`,
6
+ # `Spree::UserAddress`, and `Spree::Carton`.
7
+ #
4
8
  class Address < Spree::Base
5
9
  extend ActiveModel::ForbiddenAttributesProtection
6
10
 
7
11
  belongs_to :country, class_name: "Spree::Country"
8
12
  belongs_to :state, class_name: "Spree::State"
9
13
 
10
- validates :firstname, :lastname, :address1, :city, :country_id, presence: true
14
+ validates :firstname, :address1, :city, :country_id, presence: true
11
15
  validates :zipcode, presence: true, if: :require_zipcode?
12
16
  validates :phone, presence: true, if: :require_phone?
13
17
 
@@ -184,15 +184,15 @@ module Spree
184
184
  end
185
185
 
186
186
  def repair_adjustments_associations_on_create
187
- if adjustable.adjustments.loaded? && !adjustable.adjustments.include?(self)
188
- Spree::Deprecation.warn("Adjustment was not added to #{adjustable.class}. Add adjustments via `adjustable.adjustments.create!`. Partial call stack: #{caller.select { |line| line =~ %r(/(app|spec)/) }}.", caller)
187
+ if adjustable.adjustments.loaded? && !adjustable.adjustments.include?(self) && !destroyed?
188
+ Spree::Deprecation.warn("Adjustment #{id} was not added to #{adjustable.class} #{adjustable.id}. Add adjustments via `adjustable.adjustments.create!`. Partial call stack: #{caller.select { |line| line =~ %r(/(app|spec)/) }}.", caller)
189
189
  adjustable.adjustments.proxy_association.add_to_target(self)
190
190
  end
191
191
  end
192
192
 
193
193
  def repair_adjustments_associations_on_destroy
194
194
  if adjustable.adjustments.loaded? && adjustable.adjustments.include?(self)
195
- Spree::Deprecation.warn("Adjustment was not removed from #{adjustable.class}. Remove adjustments via `adjustable.adjustments.destroy`. Partial call stack: #{caller.select { |line| line =~ %r(/(app|spec)/) }}.", caller)
195
+ Spree::Deprecation.warn("Adjustment #{id} was not removed from #{adjustable.class} #{adjustable.id}. Remove adjustments via `adjustable.adjustments.destroy`. Partial call stack: #{caller.select { |line| line =~ %r(/(app|spec)/) }}.", caller)
196
196
  adjustable.adjustments.proxy_association.target.delete(self)
197
197
  end
198
198
  end
@@ -371,6 +371,19 @@ module Spree
371
371
  @add_payment_sources_to_wallet_class ||= Spree::Wallet::AddPaymentSourcesToWallet
372
372
  end
373
373
 
374
+ # Allows providing your own class for calculating taxes on an order.
375
+ #
376
+ # This extension point is under development and may change in a future minor release.
377
+ #
378
+ # @!attribute [rw] tax_adjuster_class
379
+ # @return [Class] a class with the same public interfaces as
380
+ # Spree::Tax::OrderAdjuster
381
+ # @api experimental
382
+ attr_writer :tax_adjuster_class
383
+ def tax_adjuster_class
384
+ @tax_adjuster_class ||= Spree::Tax::OrderAdjuster
385
+ end
386
+
374
387
  def static_model_preferences
375
388
  @static_model_preferences ||= Spree::Preferences::StaticModelPreferences.new
376
389
  end
@@ -17,9 +17,10 @@ module Spree
17
17
  end
18
18
  end
19
19
 
20
- # overwrite to provide description for your calculators
20
+ # A description for this calculator in few words
21
+ # @return [String] A description for the calculator
21
22
  def self.description
22
- 'Base Calculator'
23
+ model_name.human
23
24
  end
24
25
 
25
26
  ###################################################################
@@ -4,10 +4,6 @@ module Spree
4
4
  class Calculator::DefaultTax < Calculator
5
5
  include Spree::Tax::TaxHelpers
6
6
 
7
- def self.description
8
- Spree.t(:default_tax)
9
- end
10
-
11
7
  # Default tax calculator still needs to support orders for legacy reasons
12
8
  # Orders created before Spree 2.1 had tax adjustments applied to the order, as a whole.
13
9
  # Orders created with Spree 2.2 and after, have them applied to the line items individually.
@@ -19,7 +15,7 @@ module Spree
19
15
  line_items_total = matched_line_items.sum(&:discounted_amount)
20
16
  if rate.included_in_price
21
17
  order_tax_amount = round_to_two_places(line_items_total - ( line_items_total / (1 + rate.amount) ) )
22
- refund_if_necessary(order_tax_amount, order.tax_zone)
18
+ refund_if_necessary(order_tax_amount, order.tax_address)
23
19
  else
24
20
  round_to_two_places(line_items_total * rate.amount)
25
21
  end
@@ -52,20 +48,20 @@ module Spree
52
48
  unrounded_net_amount = item.discounted_amount / (1 + sum_of_included_tax_rates(item))
53
49
  refund_if_necessary(
54
50
  round_to_two_places(unrounded_net_amount * rate.amount),
55
- item.order.tax_zone
51
+ item.order.tax_address
56
52
  )
57
53
  end
58
54
 
59
- def refund_if_necessary(amount, order_tax_zone)
60
- if default_zone_or_zone_match?(order_tax_zone)
55
+ def refund_if_necessary(amount, order_tax_address)
56
+ if default_zone_or_zone_match?(order_tax_address)
61
57
  amount
62
58
  else
63
59
  amount * -1
64
60
  end
65
61
  end
66
62
 
67
- def default_zone_or_zone_match?(order_tax_zone)
68
- Zone.default_tax.try!(:contains?, order_tax_zone) || rate.zone.contains?(order_tax_zone)
63
+ def default_zone_or_zone_match?(order_tax_address)
64
+ Zone.default_tax.try!(:include?, order_tax_address) || rate.zone.include?(order_tax_address)
69
65
  end
70
66
  end
71
67
  end
@@ -4,10 +4,6 @@ module Spree
4
4
  class Calculator::FlatPercentItemTotal < Calculator
5
5
  preference :flat_percent, :decimal, default: 0
6
6
 
7
- def self.description
8
- Spree.t(:flat_percent)
9
- end
10
-
11
7
  def compute(object)
12
8
  computed_amount = (object.amount * preferred_flat_percent / 100).round(2)
13
9
 
@@ -5,10 +5,6 @@ module Spree
5
5
  preference :amount, :decimal, default: 0
6
6
  preference :currency, :string, default: ->{ Spree::Config[:currency] }
7
7
 
8
- def self.description
9
- Spree.t(:flat_rate_per_order)
10
- end
11
-
12
8
  def compute(object = nil)
13
9
  if object && preferred_currency.casecmp(object.currency).zero?
14
10
  preferred_amount
@@ -7,10 +7,6 @@ module Spree
7
7
  preference :max_items, :integer, default: 0
8
8
  preference :currency, :string, default: ->{ Spree::Config[:currency] }
9
9
 
10
- def self.description
11
- Spree.t(:flexible_rate)
12
- end
13
-
14
10
  def self.available?(_object)
15
11
  true
16
12
  end
@@ -3,9 +3,6 @@ module Spree
3
3
  # The only case where it was used was for Free Shipping Promotions. There is
4
4
  # now a Promotion Action which deals with these types of promotions instead.
5
5
  class Calculator::FreeShipping < Calculator
6
- def self.description
7
- Spree.t(:free_shipping)
8
- end
9
6
 
10
7
  def compute(object)
11
8
  if object.is_a?(Array)
@@ -3,10 +3,6 @@ module Spree
3
3
  class PercentOnLineItem < Calculator
4
4
  preference :percent, :decimal, default: 0
5
5
 
6
- def self.description
7
- Spree.t(:percent_per_item)
8
- end
9
-
10
6
  def compute(object)
11
7
  (object.amount * preferred_percent) / 100
12
8
  end
@@ -10,10 +10,6 @@ module Spree
10
10
  class Calculator::PercentPerItem < Calculator
11
11
  preference :percent, :decimal, default: 0
12
12
 
13
- def self.description
14
- Spree.t(:percent_per_item)
15
- end
16
-
17
13
  def compute(object = nil)
18
14
  return 0 if object.nil?
19
15
  object.line_items.map { |line_item|
@@ -7,10 +7,6 @@ module Spree
7
7
  preference :discount_amount, :decimal, default: 0
8
8
  preference :currency, :string, default: ->{ Spree::Config[:currency] }
9
9
 
10
- def self.description
11
- Spree.t(:price_sack)
12
- end
13
-
14
10
  # as object we always get line items, as calculable we have Coupon, ShippingMethod
15
11
  def compute(object)
16
12
  if object.is_a?(Array)
@@ -3,9 +3,6 @@ require_dependency 'spree/returns_calculator'
3
3
  module Spree
4
4
  module Calculator::Returns
5
5
  class DefaultRefundAmount < ReturnsCalculator
6
- def self.description
7
- Spree.t(:default_refund_amount)
8
- end
9
6
 
10
7
  def compute(return_item)
11
8
  return 0.0.to_d if return_item.part_of_exchange?
@@ -5,10 +5,6 @@ module Spree
5
5
  class FlatPercentItemTotal < ShippingCalculator
6
6
  preference :flat_percent, :decimal, default: 0
7
7
 
8
- def self.description
9
- Spree.t(:flat_percent)
10
- end
11
-
12
8
  def compute_package(package)
13
9
  compute_from_price(total(package.contents))
14
10
  end
@@ -6,10 +6,6 @@ module Spree
6
6
  preference :amount, :decimal, default: 0
7
7
  preference :currency, :string, default: ->{ Spree::Config[:currency] }
8
8
 
9
- def self.description
10
- Spree.t(:shipping_flat_rate_per_order)
11
- end
12
-
13
9
  def compute_package(_package)
14
10
  preferred_amount
15
11
  end
@@ -8,10 +8,6 @@ module Spree
8
8
  preference :max_items, :integer, default: 0
9
9
  preference :currency, :string, default: ->{ Spree::Config[:currency] }
10
10
 
11
- def self.description
12
- Spree.t(:shipping_flexible_rate)
13
- end
14
-
15
11
  def compute_package(package)
16
12
  compute_from_quantity(package.contents.sum(&:quantity))
17
13
  end
@@ -6,10 +6,6 @@ module Spree
6
6
  preference :amount, :decimal, default: 0
7
7
  preference :currency, :string, default: ->{ Spree::Config[:currency] }
8
8
 
9
- def self.description
10
- Spree.t(:shipping_flat_rate_per_item)
11
- end
12
-
13
9
  def compute_package(package)
14
10
  compute_from_quantity(package.contents.sum(&:quantity))
15
11
  end