solidus_core 2.5.2 → 2.6.0.rc1

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


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

Files changed (759) hide show
  1. checksums.yaml +4 -4
  2. data/.yardopts +1 -0
  3. data/Rakefile +5 -0
  4. data/app/controllers/spree/base_controller.rb +2 -0
  5. data/app/helpers/spree/base_helper.rb +12 -8
  6. data/app/helpers/spree/checkout_helper.rb +2 -0
  7. data/app/helpers/spree/products_helper.rb +2 -0
  8. data/app/helpers/spree/store_helper.rb +2 -0
  9. data/app/helpers/spree/taxons_helper.rb +2 -0
  10. data/app/jobs/spree/promotion_code_batch_job.rb +3 -1
  11. data/app/mailers/spree/base_mailer.rb +2 -0
  12. data/app/mailers/spree/carton_mailer.rb +3 -1
  13. data/app/mailers/spree/order_mailer.rb +2 -0
  14. data/app/mailers/spree/promotion_code_batch_mailer.rb +2 -0
  15. data/app/mailers/spree/reimbursement_mailer.rb +2 -0
  16. data/app/mailers/spree/test_mailer.rb +2 -0
  17. data/app/models/concerns/spree/adjustment_source.rb +2 -0
  18. data/app/models/concerns/spree/calculated_adjustments.rb +2 -0
  19. data/app/models/concerns/spree/default_price.rb +2 -0
  20. data/app/models/concerns/spree/display_money.rb +2 -0
  21. data/app/models/concerns/spree/named_type.rb +2 -0
  22. data/app/models/concerns/spree/ordered_property_value_list.rb +2 -0
  23. data/app/models/concerns/spree/ransackable_attributes.rb +2 -0
  24. data/app/models/concerns/spree/user_address_book.rb +2 -0
  25. data/app/models/concerns/spree/user_api_authentication.rb +2 -0
  26. data/app/models/concerns/spree/user_methods.rb +2 -0
  27. data/app/models/concerns/spree/user_payment_source.rb +2 -0
  28. data/app/models/concerns/spree/user_reporting.rb +2 -0
  29. data/app/models/spree/ability.rb +2 -0
  30. data/app/models/spree/address.rb +2 -0
  31. data/app/models/spree/adjustment.rb +2 -0
  32. data/app/models/spree/adjustment_reason.rb +2 -0
  33. data/app/models/spree/asset.rb +2 -0
  34. data/app/models/spree/base.rb +2 -0
  35. data/app/models/spree/billing_integration.rb +2 -0
  36. data/app/models/spree/calculator.rb +2 -0
  37. data/app/models/spree/calculator/default_tax.rb +2 -0
  38. data/app/models/spree/calculator/distributed_amount.rb +16 -7
  39. data/app/models/spree/calculator/flat_percent_item_total.rb +2 -0
  40. data/app/models/spree/calculator/flat_rate.rb +2 -0
  41. data/app/models/spree/calculator/flexi_rate.rb +2 -0
  42. data/app/models/spree/calculator/free_shipping.rb +2 -0
  43. data/app/models/spree/calculator/percent_on_line_item.rb +2 -0
  44. data/app/models/spree/calculator/percent_per_item.rb +2 -0
  45. data/app/models/spree/calculator/price_sack.rb +2 -0
  46. data/app/models/spree/calculator/returns/default_refund_amount.rb +2 -0
  47. data/app/models/spree/calculator/shipping/flat_percent_item_total.rb +2 -0
  48. data/app/models/spree/calculator/shipping/flat_rate.rb +2 -0
  49. data/app/models/spree/calculator/shipping/flexi_rate.rb +2 -0
  50. data/app/models/spree/calculator/shipping/per_item.rb +2 -0
  51. data/app/models/spree/calculator/shipping/price_sack.rb +2 -0
  52. data/app/models/spree/calculator/tiered_flat_rate.rb +2 -0
  53. data/app/models/spree/calculator/tiered_percent.rb +2 -0
  54. data/app/models/spree/carton.rb +2 -0
  55. data/app/models/spree/classification.rb +2 -0
  56. data/app/models/spree/country.rb +2 -0
  57. data/app/models/spree/credit_card.rb +4 -2
  58. data/app/models/spree/customer_return.rb +3 -1
  59. data/app/models/spree/distributed_amounts_handler.rb +30 -26
  60. data/app/models/spree/exchange.rb +2 -0
  61. data/app/models/spree/fulfilment_changer.rb +2 -0
  62. data/app/models/spree/gateway.rb +2 -0
  63. data/app/models/spree/gateway/bogus.rb +2 -0
  64. data/app/models/spree/gateway/bogus_simple.rb +2 -0
  65. data/app/models/spree/image.rb +2 -0
  66. data/app/models/spree/inventory_unit.rb +4 -1
  67. data/app/models/spree/legacy_user.rb +2 -0
  68. data/app/models/spree/line_item.rb +2 -0
  69. data/app/models/spree/line_item_action.rb +2 -0
  70. data/app/models/spree/log_entry.rb +2 -0
  71. data/app/models/spree/option_type.rb +2 -0
  72. data/app/models/spree/option_value.rb +2 -0
  73. data/app/models/spree/option_values_variant.rb +2 -0
  74. data/app/models/spree/order.rb +8 -11
  75. data/app/models/spree/order/checkout.rb +5 -3
  76. data/app/models/spree/order/number_generator.rb +2 -0
  77. data/app/models/spree/order/payments.rb +2 -0
  78. data/app/models/spree/order_cancellations.rb +5 -3
  79. data/app/models/spree/order_capturing.rb +2 -0
  80. data/app/models/spree/order_contents.rb +5 -3
  81. data/app/models/spree/order_inventory.rb +2 -0
  82. data/app/models/spree/order_merger.rb +2 -0
  83. data/app/models/spree/order_mutex.rb +2 -1
  84. data/app/models/spree/order_promotion.rb +2 -0
  85. data/app/models/spree/order_shipping.rb +2 -0
  86. data/app/models/spree/order_taxation.rb +2 -0
  87. data/app/models/spree/order_update_attributes.rb +2 -0
  88. data/app/models/spree/order_updater.rb +3 -0
  89. data/app/models/spree/payment.rb +2 -0
  90. data/app/models/spree/payment/cancellation.rb +2 -0
  91. data/app/models/spree/payment/processing.rb +2 -0
  92. data/app/models/spree/payment_capture_event.rb +2 -0
  93. data/app/models/spree/payment_create.rb +2 -0
  94. data/app/models/spree/payment_method.rb +21 -8
  95. data/app/models/spree/payment_method/bogus_credit_card.rb +2 -0
  96. data/app/models/spree/payment_method/check.rb +2 -0
  97. data/app/models/spree/payment_method/credit_card.rb +2 -0
  98. data/app/models/spree/payment_method/simple_bogus_credit_card.rb +2 -0
  99. data/app/models/spree/payment_method/store_credit.rb +2 -0
  100. data/app/models/spree/payment_source.rb +2 -0
  101. data/app/models/spree/preference.rb +2 -0
  102. data/app/models/spree/price.rb +3 -1
  103. data/app/models/spree/product.rb +3 -1
  104. data/app/models/spree/product/scopes.rb +2 -0
  105. data/app/models/spree/product_option_type.rb +2 -0
  106. data/app/models/spree/product_promotion_rule.rb +2 -0
  107. data/app/models/spree/product_property.rb +2 -0
  108. data/app/models/spree/promotion.rb +2 -0
  109. data/app/models/spree/promotion/actions/create_adjustment.rb +3 -1
  110. data/app/models/spree/promotion/actions/create_item_adjustments.rb +3 -1
  111. data/app/models/spree/promotion/actions/create_quantity_adjustments.rb +138 -132
  112. data/app/models/spree/promotion/actions/free_shipping.rb +3 -1
  113. data/app/models/spree/promotion/rules/first_order.rb +3 -1
  114. data/app/models/spree/promotion/rules/first_repeat_purchase_since.rb +3 -2
  115. data/app/models/spree/promotion/rules/item_total.rb +3 -1
  116. data/app/models/spree/promotion/rules/nth_order.rb +2 -1
  117. data/app/models/spree/promotion/rules/one_use_per_user.rb +3 -1
  118. data/app/models/spree/promotion/rules/option_value.rb +3 -1
  119. data/app/models/spree/promotion/rules/product.rb +5 -3
  120. data/app/models/spree/promotion/rules/store.rb +22 -0
  121. data/app/models/spree/promotion/rules/taxon.rb +6 -5
  122. data/app/models/spree/promotion/rules/user.rb +5 -3
  123. data/app/models/spree/promotion/rules/user_logged_in.rb +3 -1
  124. data/app/models/spree/promotion/rules/user_role.rb +3 -1
  125. data/app/models/spree/promotion_action.rb +2 -0
  126. data/app/models/spree/promotion_category.rb +2 -0
  127. data/app/models/spree/promotion_chooser.rb +2 -0
  128. data/app/models/spree/promotion_code.rb +2 -0
  129. data/app/models/spree/promotion_code/batch_builder.rb +31 -12
  130. data/app/models/spree/promotion_code_batch.rb +2 -0
  131. data/app/models/spree/promotion_handler/cart.rb +2 -0
  132. data/app/models/spree/promotion_handler/coupon.rb +8 -6
  133. data/app/models/spree/promotion_handler/free_shipping.rb +2 -0
  134. data/app/models/spree/promotion_handler/page.rb +2 -0
  135. data/app/models/spree/promotion_handler/shipping.rb +2 -0
  136. data/app/models/spree/promotion_rule.rb +2 -0
  137. data/app/models/spree/promotion_rule_role.rb +2 -0
  138. data/app/models/spree/promotion_rule_store.rb +10 -0
  139. data/app/models/spree/promotion_rule_taxon.rb +2 -0
  140. data/app/models/spree/promotion_rule_user.rb +2 -0
  141. data/app/models/spree/property.rb +2 -0
  142. data/app/models/spree/refund.rb +2 -0
  143. data/app/models/spree/refund_reason.rb +2 -0
  144. data/app/models/spree/reimbursement.rb +2 -0
  145. data/app/models/spree/reimbursement/credit.rb +2 -0
  146. data/app/models/spree/reimbursement/reimbursement_type_engine.rb +2 -0
  147. data/app/models/spree/reimbursement/reimbursement_type_validator.rb +2 -0
  148. data/app/models/spree/reimbursement_performer.rb +2 -0
  149. data/app/models/spree/reimbursement_tax_calculator.rb +2 -0
  150. data/app/models/spree/reimbursement_type.rb +2 -0
  151. data/app/models/spree/reimbursement_type/credit.rb +2 -0
  152. data/app/models/spree/reimbursement_type/exchange.rb +2 -0
  153. data/app/models/spree/reimbursement_type/original_payment.rb +2 -0
  154. data/app/models/spree/reimbursement_type/reimbursement_helpers.rb +2 -0
  155. data/app/models/spree/reimbursement_type/store_credit.rb +2 -0
  156. data/app/models/spree/return_authorization.rb +2 -0
  157. data/app/models/spree/return_item.rb +3 -1
  158. data/app/models/spree/return_item/eligibility_validator/base_validator.rb +2 -0
  159. data/app/models/spree/return_item/eligibility_validator/default.rb +2 -0
  160. data/app/models/spree/return_item/eligibility_validator/inventory_shipped.rb +4 -2
  161. data/app/models/spree/return_item/eligibility_validator/no_reimbursements.rb +4 -3
  162. data/app/models/spree/return_item/eligibility_validator/order_completed.rb +4 -2
  163. data/app/models/spree/return_item/eligibility_validator/rma_required.rb +4 -2
  164. data/app/models/spree/return_item/eligibility_validator/time_since_purchase.rb +4 -2
  165. data/app/models/spree/return_item/exchange_variant_eligibility/same_option_value.rb +2 -0
  166. data/app/models/spree/return_item/exchange_variant_eligibility/same_product.rb +2 -0
  167. data/app/models/spree/return_reason.rb +2 -0
  168. data/app/models/spree/returns_calculator.rb +2 -0
  169. data/app/models/spree/role.rb +2 -0
  170. data/app/models/spree/role_user.rb +2 -0
  171. data/app/models/spree/shipment.rb +10 -6
  172. data/app/models/spree/shipping_calculator.rb +2 -0
  173. data/app/models/spree/shipping_category.rb +2 -0
  174. data/app/models/spree/shipping_manifest.rb +2 -0
  175. data/app/models/spree/shipping_method.rb +10 -0
  176. data/app/models/spree/shipping_method_category.rb +2 -0
  177. data/app/models/spree/shipping_method_stock_location.rb +2 -0
  178. data/app/models/spree/shipping_method_zone.rb +2 -0
  179. data/app/models/spree/shipping_rate.rb +2 -0
  180. data/app/models/spree/shipping_rate_tax.rb +2 -0
  181. data/app/models/spree/state.rb +2 -0
  182. data/app/models/spree/state_change.rb +2 -0
  183. data/app/models/spree/stock/availability.rb +2 -0
  184. data/app/models/spree/stock/availability_validator.rb +2 -0
  185. data/app/models/spree/stock/content_item.rb +2 -0
  186. data/app/models/spree/stock/differentiator.rb +2 -0
  187. data/app/models/spree/stock/estimator.rb +3 -0
  188. data/app/models/spree/stock/inventory_unit_builder.rb +2 -0
  189. data/app/models/spree/stock/inventory_validator.rb +2 -0
  190. data/app/models/spree/stock/package.rb +2 -0
  191. data/app/models/spree/stock/quantifier.rb +2 -0
  192. data/app/models/spree/stock/shipping_rate_selector.rb +2 -0
  193. data/app/models/spree/stock/shipping_rate_sorter.rb +2 -0
  194. data/app/models/spree/stock/simple_coordinator.rb +2 -0
  195. data/app/models/spree/stock/splitter/backordered.rb +2 -0
  196. data/app/models/spree/stock/splitter/base.rb +2 -0
  197. data/app/models/spree/stock/splitter/shipping_category.rb +2 -0
  198. data/app/models/spree/stock/splitter/weight.rb +2 -0
  199. data/app/models/spree/stock/splitter_chain.rb +2 -0
  200. data/app/models/spree/stock_item.rb +2 -0
  201. data/app/models/spree/stock_location.rb +2 -0
  202. data/app/models/spree/stock_movement.rb +2 -0
  203. data/app/models/spree/stock_quantities.rb +2 -0
  204. data/app/models/spree/store.rb +24 -0
  205. data/app/models/spree/store_credit.rb +4 -1
  206. data/app/models/spree/store_credit_category.rb +2 -0
  207. data/app/models/spree/store_credit_event.rb +6 -0
  208. data/app/models/spree/store_credit_type.rb +2 -0
  209. data/app/models/spree/store_credit_update_reason.rb +2 -0
  210. data/app/models/spree/store_payment_method.rb +2 -0
  211. data/app/models/spree/store_selector/by_server_name.rb +2 -0
  212. data/app/models/spree/store_selector/legacy.rb +2 -0
  213. data/app/models/spree/store_shipping_method.rb +8 -0
  214. data/app/models/spree/tax/item_tax.rb +2 -0
  215. data/app/models/spree/tax/order_adjuster.rb +2 -0
  216. data/app/models/spree/tax/order_tax.rb +2 -0
  217. data/app/models/spree/tax/shipping_rate_taxer.rb +2 -0
  218. data/app/models/spree/tax/tax_helpers.rb +2 -0
  219. data/app/models/spree/tax/tax_location.rb +2 -0
  220. data/app/models/spree/tax_calculator/default.rb +2 -0
  221. data/app/models/spree/tax_calculator/shipping_rate.rb +5 -2
  222. data/app/models/spree/tax_category.rb +2 -0
  223. data/app/models/spree/tax_rate.rb +3 -1
  224. data/app/models/spree/tax_rate_tax_category.rb +2 -0
  225. data/app/models/spree/taxon.rb +4 -0
  226. data/app/models/spree/taxonomy.rb +2 -0
  227. data/app/models/spree/unit_cancel.rb +2 -0
  228. data/app/models/spree/user_address.rb +2 -0
  229. data/app/models/spree/user_class_handle.rb +2 -0
  230. data/app/models/spree/user_stock_location.rb +2 -0
  231. data/app/models/spree/validations/db_maximum_length_validator.rb +2 -0
  232. data/app/models/spree/variant.rb +16 -4
  233. data/app/models/spree/variant/price_selector.rb +2 -0
  234. data/app/models/spree/variant/pricing_options.rb +2 -0
  235. data/app/models/spree/variant/scopes.rb +2 -0
  236. data/app/models/spree/variant/vat_price_generator.rb +2 -0
  237. data/app/models/spree/variant_property_rule.rb +2 -0
  238. data/app/models/spree/variant_property_rule_condition.rb +2 -0
  239. data/app/models/spree/variant_property_rule_value.rb +2 -0
  240. data/app/models/spree/wallet.rb +3 -1
  241. data/app/models/spree/wallet/add_payment_sources_to_wallet.rb +2 -0
  242. data/app/models/spree/wallet/default_payment_builder.rb +2 -0
  243. data/app/models/spree/wallet_payment_source.rb +2 -0
  244. data/app/models/spree/zone.rb +3 -1
  245. data/app/models/spree/zone_member.rb +2 -0
  246. data/config/initializers/assets.rb +2 -0
  247. data/config/initializers/friendly_id.rb +2 -0
  248. data/config/locales/en.yml +13 -3
  249. data/db/default/spree/countries.rb +2 -0
  250. data/db/default/spree/refund_reasons.rb +2 -0
  251. data/db/default/spree/return_reasons.rb +2 -0
  252. data/db/default/spree/roles.rb +2 -0
  253. data/db/default/spree/shipping_categories.rb +2 -0
  254. data/db/default/spree/states.rb +2 -0
  255. data/db/default/spree/stock_locations.rb +2 -0
  256. data/db/default/spree/store_credit.rb +2 -0
  257. data/db/default/spree/stores.rb +2 -0
  258. data/db/default/spree/zones.rb +2 -0
  259. data/db/migrate/20160101010000_solidus_one_four.rb +175 -173
  260. data/db/migrate/20160420044191_create_spree_wallet_payment_sources.rb +3 -1
  261. data/db/migrate/20160420181916_migrate_credit_cards_to_wallet_payment_sources.rb +2 -0
  262. data/db/migrate/20160924135758_remove_is_default_from_prices.rb +2 -0
  263. data/db/migrate/20161009141333_remove_currency_from_line_items.rb +2 -0
  264. data/db/migrate/20161014221052_add_available_to_columns_and_remove_display_on_from_payment_methods.rb +2 -0
  265. data/db/migrate/20161017102621_create_spree_promotion_code_batch.rb +3 -1
  266. data/db/migrate/20161123154034_add_available_to_users_and_remove_display_on_from_shipping_methods.rb +2 -0
  267. data/db/migrate/20161129035810_add_index_to_spree_payments_number.rb +2 -0
  268. data/db/migrate/20170223235001_remove_spree_store_credits_column.rb +2 -0
  269. data/db/migrate/20170317035819_add_lft_and_rgt_indexes_to_taxons.rb +2 -0
  270. data/db/migrate/20170319191942_remove_order_id_from_inventory_units.rb +2 -0
  271. data/db/migrate/20170412103617_transform_tax_rate_category_relation.rb +2 -0
  272. data/db/migrate/20170422134804_add_roles_unique_constraints.rb +2 -0
  273. data/db/migrate/20170522143442_add_time_range_to_tax_rate.rb +2 -0
  274. data/db/migrate/20170608074534_rename_bogus_gateways.rb +2 -0
  275. data/db/migrate/20170831201542_remove_default_tax_from_spree_zones.rb +2 -0
  276. data/db/migrate/20180202190713_create_promotion_rule_stores.rb +12 -0
  277. data/db/migrate/20180202222641_create_store_shipping_methods.rb +12 -0
  278. data/db/migrate/20180313220213_add_available_locales_to_stores.rb +9 -0
  279. data/db/migrate/20180322142651_add_amount_remaining_to_store_credit_events.rb +61 -0
  280. data/db/migrate/20180328172631_add_join_characters_to_promotion_code_batch.rb +11 -0
  281. data/db/seeds.rb +1 -2
  282. data/lib/generators/spree/custom_user/custom_user_generator.rb +3 -0
  283. data/lib/generators/spree/dummy/dummy_generator.rb +10 -7
  284. data/lib/generators/spree/dummy/templates/rails/{application.rb → application.rb.tt} +0 -0
  285. data/lib/generators/spree/install/install_generator.rb +18 -15
  286. data/lib/generators/spree/install/templates/config/initializers/{spree.rb → spree.rb.tt} +0 -0
  287. data/lib/solidus_core.rb +2 -0
  288. data/lib/spree/app_configuration.rb +8 -5
  289. data/lib/spree/config.rb +2 -0
  290. data/lib/spree/core.rb +3 -0
  291. data/lib/spree/core/active_merchant_dependencies.rb +2 -0
  292. data/lib/spree/core/class_constantizer.rb +2 -0
  293. data/lib/spree/core/controller_helpers/auth.rb +8 -3
  294. data/lib/spree/core/controller_helpers/common.rb +13 -4
  295. data/lib/spree/core/controller_helpers/order.rb +2 -0
  296. data/lib/spree/core/controller_helpers/payment_parameters.rb +2 -0
  297. data/lib/spree/core/controller_helpers/pricing.rb +2 -0
  298. data/lib/spree/core/controller_helpers/search.rb +2 -0
  299. data/lib/spree/core/controller_helpers/store.rb +2 -0
  300. data/lib/spree/core/controller_helpers/strong_parameters.rb +2 -0
  301. data/lib/spree/core/current_store.rb +2 -0
  302. data/lib/spree/core/engine.rb +2 -0
  303. data/lib/spree/core/environment.rb +2 -0
  304. data/lib/spree/core/environment/calculators.rb +2 -0
  305. data/lib/spree/core/environment_extension.rb +3 -1
  306. data/lib/spree/core/importer.rb +2 -0
  307. data/lib/spree/core/importer/order.rb +2 -0
  308. data/lib/spree/core/importer/product.rb +2 -0
  309. data/lib/spree/core/permalinks.rb +2 -0
  310. data/lib/spree/core/product_duplicator.rb +2 -0
  311. data/lib/spree/core/product_filters.rb +2 -0
  312. data/lib/spree/core/role_configuration.rb +3 -1
  313. data/lib/spree/core/search/base.rb +6 -0
  314. data/lib/spree/core/search/variant.rb +3 -1
  315. data/lib/spree/core/stock_configuration.rb +2 -0
  316. data/lib/spree/core/validators/email.rb +27 -4
  317. data/lib/spree/core/version.rb +3 -1
  318. data/lib/spree/deprecation.rb +2 -0
  319. data/lib/spree/i18n.rb +8 -0
  320. data/lib/spree/localized_number.rb +2 -0
  321. data/lib/spree/mailer_previews/carton_preview.rb +2 -0
  322. data/lib/spree/mailer_previews/order_preview.rb +2 -0
  323. data/lib/spree/mailer_previews/reimbursement_preview.rb +2 -0
  324. data/lib/spree/migration_helpers.rb +2 -0
  325. data/lib/spree/migrations.rb +2 -0
  326. data/lib/spree/money.rb +3 -3
  327. data/lib/spree/paranoia_deprecations.rb +2 -0
  328. data/lib/spree/permission_sets.rb +2 -0
  329. data/lib/spree/permission_sets/base.rb +2 -0
  330. data/lib/spree/permission_sets/configuration_display.rb +2 -0
  331. data/lib/spree/permission_sets/configuration_management.rb +2 -0
  332. data/lib/spree/permission_sets/dashboard_display.rb +2 -0
  333. data/lib/spree/permission_sets/default_customer.rb +2 -0
  334. data/lib/spree/permission_sets/order_display.rb +2 -0
  335. data/lib/spree/permission_sets/order_management.rb +2 -0
  336. data/lib/spree/permission_sets/product_display.rb +2 -0
  337. data/lib/spree/permission_sets/product_management.rb +2 -0
  338. data/lib/spree/permission_sets/promotion_display.rb +2 -0
  339. data/lib/spree/permission_sets/promotion_management.rb +2 -0
  340. data/lib/spree/permission_sets/report_display.rb +2 -0
  341. data/lib/spree/permission_sets/restricted_stock_display.rb +2 -0
  342. data/lib/spree/permission_sets/restricted_stock_management.rb +2 -0
  343. data/lib/spree/permission_sets/stock_display.rb +2 -0
  344. data/lib/spree/permission_sets/stock_management.rb +2 -0
  345. data/lib/spree/permission_sets/super_user.rb +2 -0
  346. data/lib/spree/permission_sets/user_display.rb +2 -0
  347. data/lib/spree/permission_sets/user_management.rb +2 -0
  348. data/lib/spree/permitted_attributes.rb +2 -0
  349. data/lib/spree/preferences/configuration.rb +2 -0
  350. data/lib/spree/preferences/preferable.rb +2 -0
  351. data/lib/spree/preferences/preferable_class_methods.rb +2 -0
  352. data/lib/spree/preferences/scoped_store.rb +2 -0
  353. data/lib/spree/preferences/static_model_preferences.rb +2 -0
  354. data/lib/spree/preferences/statically_configurable.rb +2 -0
  355. data/lib/spree/preferences/store.rb +2 -0
  356. data/lib/spree/promo/environment.rb +2 -0
  357. data/lib/spree/testing_support/ability_helpers.rb +2 -0
  358. data/lib/spree/testing_support/authorization_helpers.rb +2 -0
  359. data/lib/spree/testing_support/bar_ability.rb +5 -0
  360. data/lib/spree/testing_support/caching.rb +2 -16
  361. data/lib/spree/testing_support/capybara_ext.rb +114 -108
  362. data/lib/spree/testing_support/common_rake.rb +2 -0
  363. data/lib/spree/testing_support/controller_requests.rb +2 -0
  364. data/lib/spree/testing_support/dummy_app.rb +17 -8
  365. data/lib/spree/testing_support/dummy_app/database.yml +4 -1
  366. data/lib/spree/testing_support/dummy_app/migrations.rb +14 -2
  367. data/lib/spree/testing_support/dummy_app/rake_tasks.rb +8 -1
  368. data/lib/spree/testing_support/dummy_app/routes.rb +5 -0
  369. data/lib/spree/testing_support/extension_rake.rb +2 -0
  370. data/lib/spree/testing_support/factories.rb +2 -0
  371. data/lib/spree/testing_support/factories/address_factory.rb +14 -12
  372. data/lib/spree/testing_support/factories/adjustment_factory.rb +7 -5
  373. data/lib/spree/testing_support/factories/adjustment_reason_factory.rb +2 -0
  374. data/lib/spree/testing_support/factories/calculator_factory.rb +7 -5
  375. data/lib/spree/testing_support/factories/carton_factory.rb +2 -0
  376. data/lib/spree/testing_support/factories/country_factory.rb +3 -1
  377. data/lib/spree/testing_support/factories/credit_card_factory.rb +7 -5
  378. data/lib/spree/testing_support/factories/customer_return_factory.rb +3 -1
  379. data/lib/spree/testing_support/factories/image_factory.rb +2 -0
  380. data/lib/spree/testing_support/factories/inventory_unit_factory.rb +4 -2
  381. data/lib/spree/testing_support/factories/line_item_factory.rb +4 -2
  382. data/lib/spree/testing_support/factories/option_type_factory.rb +3 -1
  383. data/lib/spree/testing_support/factories/option_value_factory.rb +3 -1
  384. data/lib/spree/testing_support/factories/order_factory.rb +15 -13
  385. data/lib/spree/testing_support/factories/order_promotion_factory.rb +2 -0
  386. data/lib/spree/testing_support/factories/payment_factory.rb +8 -6
  387. data/lib/spree/testing_support/factories/payment_method_factory.rb +17 -15
  388. data/lib/spree/testing_support/factories/price_factory.rb +4 -2
  389. data/lib/spree/testing_support/factories/product_factory.rb +8 -6
  390. data/lib/spree/testing_support/factories/product_option_type_factory.rb +2 -0
  391. data/lib/spree/testing_support/factories/product_property_factory.rb +2 -0
  392. data/lib/spree/testing_support/factories/promotion_category_factory.rb +3 -1
  393. data/lib/spree/testing_support/factories/promotion_code_factory.rb +2 -0
  394. data/lib/spree/testing_support/factories/promotion_factory.rb +7 -5
  395. data/lib/spree/testing_support/factories/property_factory.rb +4 -2
  396. data/lib/spree/testing_support/factories/refund_factory.rb +4 -2
  397. data/lib/spree/testing_support/factories/refund_reason_factory.rb +2 -0
  398. data/lib/spree/testing_support/factories/reimbursement_factory.rb +3 -1
  399. data/lib/spree/testing_support/factories/reimbursement_type_factory.rb +4 -2
  400. data/lib/spree/testing_support/factories/return_authorization_factory.rb +3 -1
  401. data/lib/spree/testing_support/factories/return_item_factory.rb +2 -0
  402. data/lib/spree/testing_support/factories/return_reason_factory.rb +2 -0
  403. data/lib/spree/testing_support/factories/role_factory.rb +3 -1
  404. data/lib/spree/testing_support/factories/shipment_factory.rb +6 -4
  405. data/lib/spree/testing_support/factories/shipping_category_factory.rb +2 -0
  406. data/lib/spree/testing_support/factories/shipping_method_factory.rb +8 -6
  407. data/lib/spree/testing_support/factories/shipping_rate_factory.rb +2 -0
  408. data/lib/spree/testing_support/factories/state_factory.rb +4 -2
  409. data/lib/spree/testing_support/factories/stock_item_factory.rb +3 -1
  410. data/lib/spree/testing_support/factories/stock_location_factory.rb +10 -8
  411. data/lib/spree/testing_support/factories/stock_movement_factory.rb +5 -3
  412. data/lib/spree/testing_support/factories/stock_package_factory.rb +2 -0
  413. data/lib/spree/testing_support/factories/store_credit_category_factory.rb +3 -1
  414. data/lib/spree/testing_support/factories/store_credit_event_factory.rb +2 -0
  415. data/lib/spree/testing_support/factories/store_credit_factory.rb +4 -2
  416. data/lib/spree/testing_support/factories/store_credit_type_factory.rb +2 -0
  417. data/lib/spree/testing_support/factories/store_credit_update_reason_factory.rb +3 -1
  418. data/lib/spree/testing_support/factories/store_factory.rb +3 -1
  419. data/lib/spree/testing_support/factories/tax_category_factory.rb +2 -0
  420. data/lib/spree/testing_support/factories/tax_rate_factory.rb +3 -1
  421. data/lib/spree/testing_support/factories/taxon_factory.rb +4 -2
  422. data/lib/spree/testing_support/factories/taxonomy_factory.rb +3 -1
  423. data/lib/spree/testing_support/factories/user_factory.rb +3 -1
  424. data/lib/spree/testing_support/factories/variant_factory.rb +9 -7
  425. data/lib/spree/testing_support/factories/variant_property_rule_condition_factory.rb +2 -0
  426. data/lib/spree/testing_support/factories/variant_property_rule_factory.rb +3 -1
  427. data/lib/spree/testing_support/factories/variant_property_rule_value_factory.rb +2 -0
  428. data/lib/spree/testing_support/factories/zone_factory.rb +3 -1
  429. data/lib/spree/testing_support/flash.rb +2 -0
  430. data/lib/spree/testing_support/order_walkthrough.rb +72 -63
  431. data/lib/spree/testing_support/preferences.rb +2 -0
  432. data/lib/spree/testing_support/sequences.rb +2 -0
  433. data/lib/spree/testing_support/url_helpers.rb +2 -0
  434. data/lib/spree_core.rb +2 -0
  435. data/lib/tasks/core.rake +4 -4
  436. data/lib/tasks/email.rake +2 -0
  437. data/lib/tasks/migrations/copy_order_bill_address_to_credit_card.rake +2 -0
  438. data/lib/tasks/migrations/migrate_shipping_rate_taxes.rake +2 -0
  439. data/lib/tasks/migrations/migrate_user_addresses.rake +2 -0
  440. data/lib/tasks/migrations/rename_gateways.rake +2 -0
  441. data/lib/tasks/order_capturing.rake +3 -1
  442. data/script/rails +4 -2
  443. data/solidus_core.gemspec +5 -4
  444. data/spec/helpers/base_helper_spec.rb +6 -0
  445. data/spec/helpers/products_helper_spec.rb +1 -1
  446. data/spec/helpers/taxons_helper_spec.rb +2 -0
  447. data/spec/jobs/promotion_code_batch_job_spec.rb +32 -1
  448. data/spec/lib/calculated_adjustments_spec.rb +3 -1
  449. data/spec/lib/i18n_spec.rb +47 -0
  450. data/spec/lib/search/base_spec.rb +2 -0
  451. data/spec/lib/search/variant_spec.rb +2 -0
  452. data/spec/lib/spree/core/class_constantizer_spec.rb +2 -0
  453. data/spec/lib/spree/core/controller_helpers/auth_spec.rb +3 -0
  454. data/spec/lib/spree/core/controller_helpers/order_spec.rb +2 -0
  455. data/spec/lib/spree/core/controller_helpers/payment_parameters_spec.rb +2 -0
  456. data/spec/lib/spree/core/controller_helpers/pricing_spec.rb +2 -0
  457. data/spec/lib/spree/core/controller_helpers/search_spec.rb +2 -0
  458. data/spec/lib/spree/core/controller_helpers/store_spec.rb +2 -0
  459. data/spec/lib/spree/core/controller_helpers/strong_parameters_spec.rb +2 -0
  460. data/spec/lib/spree/core/current_store_spec.rb +2 -0
  461. data/spec/lib/spree/core/environment_extension_spec.rb +2 -0
  462. data/spec/lib/spree/core/importer/order_spec.rb +20 -8
  463. data/spec/lib/spree/core/role_configuration_spec.rb +2 -0
  464. data/spec/lib/spree/core/stock_configuration_spec.rb +2 -0
  465. data/spec/lib/spree/core/testing_support/factories/address_factory_spec.rb +2 -0
  466. data/spec/lib/spree/core/testing_support/factories/adjustment_factory_spec.rb +2 -0
  467. data/spec/lib/spree/core/testing_support/factories/adjustment_reason_factory_spec.rb +2 -0
  468. data/spec/lib/spree/core/testing_support/factories/calculator_factory_spec.rb +2 -0
  469. data/spec/lib/spree/core/testing_support/factories/carton_factory_spec.rb +2 -0
  470. data/spec/lib/spree/core/testing_support/factories/country_factory_spec.rb +2 -0
  471. data/spec/lib/spree/core/testing_support/factories/credit_card_factory_spec.rb +2 -0
  472. data/spec/lib/spree/core/testing_support/factories/customer_return_factory_spec.rb +2 -0
  473. data/spec/lib/spree/core/testing_support/factories/image_factory_spec.rb +2 -0
  474. data/spec/lib/spree/core/testing_support/factories/inventory_unit_factory_spec.rb +2 -0
  475. data/spec/lib/spree/core/testing_support/factories/line_item_factory_spec.rb +2 -0
  476. data/spec/lib/spree/core/testing_support/factories/option_type_factory_spec.rb +2 -0
  477. data/spec/lib/spree/core/testing_support/factories/option_value_factory_spec.rb +2 -0
  478. data/spec/lib/spree/core/testing_support/factories/order_factory_spec.rb +2 -0
  479. data/spec/lib/spree/core/testing_support/factories/order_promotion_factory_spec.rb +2 -0
  480. data/spec/lib/spree/core/testing_support/factories/payment_factory_spec.rb +2 -0
  481. data/spec/lib/spree/core/testing_support/factories/payment_method_factory_spec.rb +2 -0
  482. data/spec/lib/spree/core/testing_support/factories/price_factory_spec.rb +2 -0
  483. data/spec/lib/spree/core/testing_support/factories/product_factory_spec.rb +2 -0
  484. data/spec/lib/spree/core/testing_support/factories/product_option_type_factory_spec.rb +2 -0
  485. data/spec/lib/spree/core/testing_support/factories/product_property_factory_spec.rb +2 -0
  486. data/spec/lib/spree/core/testing_support/factories/promotion_category_factory_spec.rb +2 -0
  487. data/spec/lib/spree/core/testing_support/factories/promotion_code_factory_spec.rb +2 -0
  488. data/spec/lib/spree/core/testing_support/factories/promotion_factory_spec.rb +2 -0
  489. data/spec/lib/spree/core/testing_support/factories/property_factory_spec.rb +2 -0
  490. data/spec/lib/spree/core/testing_support/factories/refund_factory_spec.rb +2 -0
  491. data/spec/lib/spree/core/testing_support/factories/refund_reason_factory_spec.rb +2 -0
  492. data/spec/lib/spree/core/testing_support/factories/reimbursement_factory_spec.rb +2 -0
  493. data/spec/lib/spree/core/testing_support/factories/reimbursement_type_factory_spec.rb +2 -0
  494. data/spec/lib/spree/core/testing_support/factories/return_authorization_factory_spec.rb +2 -0
  495. data/spec/lib/spree/core/testing_support/factories/return_item_factory_spec.rb +2 -0
  496. data/spec/lib/spree/core/testing_support/factories/return_reason_factory_spec.rb +2 -0
  497. data/spec/lib/spree/core/testing_support/factories/role_factory_spec.rb +2 -0
  498. data/spec/lib/spree/core/testing_support/factories/shipment_factory_spec.rb +2 -0
  499. data/spec/lib/spree/core/testing_support/factories/shipping_category_factory_spec.rb +2 -0
  500. data/spec/lib/spree/core/testing_support/factories/shipping_method_factory_spec.rb +2 -0
  501. data/spec/lib/spree/core/testing_support/factories/shipping_rate_factory_spec.rb +2 -0
  502. data/spec/lib/spree/core/testing_support/factories/state_factory_spec.rb +2 -0
  503. data/spec/lib/spree/core/testing_support/factories/stock_item_factory_spec.rb +2 -0
  504. data/spec/lib/spree/core/testing_support/factories/stock_location_factory_spec.rb +2 -0
  505. data/spec/lib/spree/core/testing_support/factories/stock_movement_factory_spec.rb +2 -0
  506. data/spec/lib/spree/core/testing_support/factories/stock_package_factory_spec.rb +2 -0
  507. data/spec/lib/spree/core/testing_support/factories/store_credit_category_factory_spec.rb +2 -0
  508. data/spec/lib/spree/core/testing_support/factories/store_credit_event_factory_spec.rb +2 -0
  509. data/spec/lib/spree/core/testing_support/factories/store_credit_factory_spec.rb +2 -0
  510. data/spec/lib/spree/core/testing_support/factories/store_credit_type_factory_spec.rb +2 -0
  511. data/spec/lib/spree/core/testing_support/factories/store_credit_update_reason_factory_spec.rb +2 -0
  512. data/spec/lib/spree/core/testing_support/factories/store_factory_spec.rb +2 -0
  513. data/spec/lib/spree/core/testing_support/factories/tax_category_factory_spec.rb +2 -0
  514. data/spec/lib/spree/core/testing_support/factories/tax_rate_factory_spec.rb +2 -0
  515. data/spec/lib/spree/core/testing_support/factories/taxon_factory_spec.rb +2 -0
  516. data/spec/lib/spree/core/testing_support/factories/taxonomy_factory_spec.rb +2 -0
  517. data/spec/lib/spree/core/testing_support/factories/user_factory_spec.rb +2 -0
  518. data/spec/lib/spree/core/testing_support/factories/variant_factory_spec.rb +2 -0
  519. data/spec/lib/spree/core/testing_support/factories/variant_property_rule_condition_factory_spec.rb +2 -0
  520. data/spec/lib/spree/core/testing_support/factories/variant_property_rule_factory_spec.rb +2 -0
  521. data/spec/lib/spree/core/testing_support/factories/variant_property_rule_value_factory_spec.rb +2 -0
  522. data/spec/lib/spree/core/testing_support/factories/zone_factory_spec.rb +2 -0
  523. data/spec/lib/spree/core/testing_support/preferences_spec.rb +2 -0
  524. data/spec/lib/spree/core/validators/email_spec.rb +4 -2
  525. data/spec/lib/spree/core/version_spec.rb +2 -0
  526. data/spec/lib/spree/localized_number_spec.rb +2 -0
  527. data/spec/lib/spree/migrations_spec.rb +2 -0
  528. data/spec/lib/spree/money_spec.rb +1 -1
  529. data/spec/lib/spree/permission_sets/default_customer_spec.rb +2 -0
  530. data/spec/lib/tasks/dummy_task.rake +2 -0
  531. data/spec/lib/tasks/dummy_task_spec.rb +2 -0
  532. data/spec/lib/tasks/migrations/migrate_shipping_rate_taxes_spec.rb +2 -0
  533. data/spec/mailers/carton_mailer_spec.rb +2 -0
  534. data/spec/mailers/order_mailer_spec.rb +2 -0
  535. data/spec/mailers/promotion_code_batch_mailer_spec.rb +2 -0
  536. data/spec/mailers/reimbursement_mailer_spec.rb +2 -0
  537. data/spec/mailers/test_mailer_spec.rb +2 -0
  538. data/spec/models/spree/ability_spec.rb +6 -1
  539. data/spec/models/spree/address_spec.rb +3 -1
  540. data/spec/models/spree/adjustment_reason_spec.rb +2 -0
  541. data/spec/models/spree/adjustment_spec.rb +1 -2
  542. data/spec/models/spree/app_configuration_spec.rb +2 -0
  543. data/spec/models/spree/asset_spec.rb +2 -0
  544. data/spec/models/spree/calculator/default_tax_spec.rb +2 -0
  545. data/spec/models/spree/calculator/distributed_amount_spec.rb +50 -0
  546. data/spec/models/spree/calculator/flat_percent_item_total_spec.rb +2 -0
  547. data/spec/models/spree/calculator/flat_rate_spec.rb +2 -0
  548. data/spec/models/spree/calculator/flexi_rate_spec.rb +3 -1
  549. data/spec/models/spree/calculator/free_shipping_spec.rb +2 -0
  550. data/spec/models/spree/calculator/percent_on_line_item_spec.rb +2 -0
  551. data/spec/models/spree/calculator/percent_per_item_spec.rb +2 -0
  552. data/spec/models/spree/calculator/price_sack_spec.rb +2 -0
  553. data/spec/models/spree/calculator/refunds/default_refund_amount_spec.rb +2 -0
  554. data/spec/models/spree/calculator/shipping/flat_percent_item_total_spec.rb +2 -0
  555. data/spec/models/spree/calculator/shipping/flat_rate_spec.rb +2 -0
  556. data/spec/models/spree/calculator/shipping/flexi_rate_spec.rb +2 -0
  557. data/spec/models/spree/calculator/shipping/per_item_spec.rb +2 -0
  558. data/spec/models/spree/calculator/shipping/price_sack_spec.rb +2 -0
  559. data/spec/models/spree/calculator/tiered_flat_rate_spec.rb +2 -0
  560. data/spec/models/spree/calculator/tiered_percent_spec.rb +2 -0
  561. data/spec/models/spree/calculator_spec.rb +2 -0
  562. data/spec/models/spree/carton_spec.rb +2 -0
  563. data/spec/models/spree/classification_spec.rb +2 -0
  564. data/spec/models/spree/concerns/display_money_spec.rb +2 -0
  565. data/spec/models/spree/concerns/ordered_property_value_list_spec.rb +2 -0
  566. data/spec/models/spree/concerns/user_address_book_spec.rb +2 -0
  567. data/spec/models/spree/concerns/user_methods_spec.rb +2 -0
  568. data/spec/models/spree/country_spec.rb +2 -0
  569. data/spec/models/spree/credit_card_spec.rb +3 -2
  570. data/spec/models/spree/customer_return_spec.rb +3 -1
  571. data/spec/models/spree/distributed_amounts_handler_spec.rb +19 -15
  572. data/spec/models/spree/exchange_spec.rb +2 -0
  573. data/spec/models/spree/fulfilment_changer_spec.rb +2 -0
  574. data/spec/models/spree/gateway/bogus_simple.rb +2 -0
  575. data/spec/models/spree/gateway/bogus_spec.rb +2 -0
  576. data/spec/models/spree/gateway_spec.rb +2 -0
  577. data/spec/models/spree/image_spec.rb +2 -0
  578. data/spec/models/spree/inventory_unit_spec.rb +2 -0
  579. data/spec/models/spree/line_item_spec.rb +2 -0
  580. data/spec/models/spree/option_type_spec.rb +2 -0
  581. data/spec/models/spree/option_value_spec.rb +2 -0
  582. data/spec/models/spree/order/address_spec.rb +2 -0
  583. data/spec/models/spree/order/adjustments_spec.rb +2 -0
  584. data/spec/models/spree/order/callbacks_spec.rb +2 -0
  585. data/spec/models/spree/order/checkout_spec.rb +2 -0
  586. data/spec/models/spree/order/finalizing_spec.rb +2 -0
  587. data/spec/models/spree/order/number_generator_spec.rb +2 -0
  588. data/spec/models/spree/order/outstanding_balance_integration_spec.rb +2 -0
  589. data/spec/models/spree/order/payment_spec.rb +2 -0
  590. data/spec/models/spree/order/risk_assessment_spec.rb +2 -0
  591. data/spec/models/spree/order/state_machine_spec.rb +2 -0
  592. data/spec/models/spree/order/totals_spec.rb +2 -0
  593. data/spec/models/spree/order/updating_spec.rb +2 -0
  594. data/spec/models/spree/order/validations_spec.rb +2 -0
  595. data/spec/models/spree/order_cancellations_spec.rb +2 -0
  596. data/spec/models/spree/order_capturing_spec.rb +2 -0
  597. data/spec/models/spree/order_contents_spec.rb +2 -0
  598. data/spec/models/spree/order_inventory_spec.rb +2 -1
  599. data/spec/models/spree/order_merger_spec.rb +2 -0
  600. data/spec/models/spree/order_mutex_spec.rb +2 -0
  601. data/spec/models/spree/order_promotion_spec.rb +2 -0
  602. data/spec/models/spree/order_shipping_spec.rb +2 -0
  603. data/spec/models/spree/order_spec.rb +17 -12
  604. data/spec/models/spree/order_taxation_spec.rb +2 -0
  605. data/spec/models/spree/order_update_attributes_spec.rb +2 -0
  606. data/spec/models/spree/order_updater_spec.rb +2 -0
  607. data/spec/models/spree/payment/cancellation_spec.rb +2 -0
  608. data/spec/models/spree/payment_create_spec.rb +2 -0
  609. data/spec/models/spree/payment_method/bogus_credit_card_spec.rb +2 -0
  610. data/spec/models/spree/payment_method/check_spec.rb +2 -0
  611. data/spec/models/spree/payment_method/credit_card_spec.rb +2 -0
  612. data/spec/models/spree/payment_method/simple_bogus_credit_card_spec.rb +2 -0
  613. data/spec/models/spree/payment_method/store_credit_spec.rb +2 -0
  614. data/spec/models/spree/payment_method_spec.rb +58 -23
  615. data/spec/models/spree/payment_spec.rb +2 -0
  616. data/spec/models/spree/permission_sets/base_spec.rb +2 -0
  617. data/spec/models/spree/permission_sets/configuration_display.rb +2 -0
  618. data/spec/models/spree/permission_sets/configuration_management_spec.rb +2 -0
  619. data/spec/models/spree/permission_sets/dashboard_display_spec.rb +2 -0
  620. data/spec/models/spree/permission_sets/order_display_spec.rb +2 -0
  621. data/spec/models/spree/permission_sets/order_management_spec.rb +2 -0
  622. data/spec/models/spree/permission_sets/product_display_spec.rb +2 -0
  623. data/spec/models/spree/permission_sets/product_management_spec.rb +2 -0
  624. data/spec/models/spree/permission_sets/promotion_display_spec.rb +2 -0
  625. data/spec/models/spree/permission_sets/promotion_management_spec.rb +2 -0
  626. data/spec/models/spree/permission_sets/report_display_spec.rb +2 -0
  627. data/spec/models/spree/permission_sets/restricted_stock_display_spec.rb +2 -0
  628. data/spec/models/spree/permission_sets/restricted_stock_management_spec.rb +2 -0
  629. data/spec/models/spree/permission_sets/stock_display_spec.rb +2 -0
  630. data/spec/models/spree/permission_sets/stock_management_spec.rb +2 -0
  631. data/spec/models/spree/permission_sets/user_display_spec.rb +2 -0
  632. data/spec/models/spree/permission_sets/user_management_spec.rb +2 -0
  633. data/spec/models/spree/preference_spec.rb +2 -0
  634. data/spec/models/spree/preferences/configuration_spec.rb +2 -0
  635. data/spec/models/spree/preferences/preferable_spec.rb +2 -0
  636. data/spec/models/spree/preferences/scoped_store_spec.rb +2 -0
  637. data/spec/models/spree/preferences/static_model_preferences_spec.rb +2 -0
  638. data/spec/models/spree/preferences/statically_configurable_spec.rb +2 -0
  639. data/spec/models/spree/preferences/store_spec.rb +2 -0
  640. data/spec/models/spree/price_spec.rb +2 -0
  641. data/spec/models/spree/product/scopes_spec.rb +2 -0
  642. data/spec/models/spree/product_duplicator_spec.rb +3 -1
  643. data/spec/models/spree/product_filter_spec.rb +2 -0
  644. data/spec/models/spree/product_property_spec.rb +2 -0
  645. data/spec/models/spree/product_spec.rb +12 -2
  646. data/spec/models/spree/promotion/actions/create_adjustment_spec.rb +2 -0
  647. data/spec/models/spree/promotion/actions/create_item_adjustments_spec.rb +2 -0
  648. data/spec/models/spree/promotion/actions/create_quantity_adjustments_spec.rb +3 -1
  649. data/spec/models/spree/promotion/actions/free_shipping_spec.rb +2 -0
  650. data/spec/models/spree/promotion/rules/first_order_spec.rb +2 -0
  651. data/spec/models/spree/promotion/rules/first_repeat_purchase_since_spec.rb +2 -0
  652. data/spec/models/spree/promotion/rules/item_total_spec.rb +2 -0
  653. data/spec/models/spree/promotion/rules/nth_order_spec.rb +2 -0
  654. data/spec/models/spree/promotion/rules/one_use_per_user_spec.rb +2 -0
  655. data/spec/models/spree/promotion/rules/option_value_spec.rb +2 -0
  656. data/spec/models/spree/promotion/rules/product_spec.rb +2 -0
  657. data/spec/models/spree/promotion/rules/store_spec.rb +35 -0
  658. data/spec/models/spree/promotion/rules/taxon_spec.rb +2 -0
  659. data/spec/models/spree/promotion/rules/user_logged_in_spec.rb +2 -0
  660. data/spec/models/spree/promotion/rules/user_role_spec.rb +2 -0
  661. data/spec/models/spree/promotion/rules/user_spec.rb +2 -0
  662. data/spec/models/spree/promotion_action_spec.rb +2 -0
  663. data/spec/models/spree/promotion_category_spec.rb +2 -0
  664. data/spec/models/spree/promotion_code/batch_builder_spec.rb +30 -6
  665. data/spec/models/spree/promotion_code_batch_spec.rb +2 -0
  666. data/spec/models/spree/promotion_code_spec.rb +2 -0
  667. data/spec/models/spree/promotion_handler/cart_spec.rb +2 -0
  668. data/spec/models/spree/promotion_handler/coupon_spec.rb +4 -2
  669. data/spec/models/spree/promotion_handler/page_spec.rb +2 -0
  670. data/spec/models/spree/promotion_handler/shipping_spec.rb +2 -0
  671. data/spec/models/spree/promotion_rule_spec.rb +2 -0
  672. data/spec/models/spree/promotion_spec.rb +4 -2
  673. data/spec/models/spree/refund_spec.rb +2 -0
  674. data/spec/models/spree/reimbursement/credit_spec.rb +2 -0
  675. data/spec/models/spree/reimbursement/reimbursement_type_engine_spec.rb +2 -0
  676. data/spec/models/spree/reimbursement/reimbursement_type_validator_spec.rb +2 -0
  677. data/spec/models/spree/reimbursement_performer_spec.rb +2 -0
  678. data/spec/models/spree/reimbursement_spec.rb +2 -0
  679. data/spec/models/spree/reimbursement_tax_calculator_spec.rb +2 -0
  680. data/spec/models/spree/reimbursement_type/credit_spec.rb +2 -0
  681. data/spec/models/spree/reimbursement_type/exchange_spec.rb +2 -0
  682. data/spec/models/spree/reimbursement_type/original_payment_spec.rb +2 -0
  683. data/spec/models/spree/reimbursement_type/store_credit_spec.rb +2 -0
  684. data/spec/models/spree/return_authorization_spec.rb +2 -0
  685. data/spec/models/spree/return_item/eligibility_validator/default_spec.rb +2 -0
  686. data/spec/models/spree/return_item/eligibility_validator/inventory_shipped_spec.rb +2 -0
  687. data/spec/models/spree/return_item/eligibility_validator/no_reimbursements_spec.rb +2 -0
  688. data/spec/models/spree/return_item/eligibility_validator/order_completed_spec.rb +2 -0
  689. data/spec/models/spree/return_item/eligibility_validator/rma_required_spec.rb +2 -0
  690. data/spec/models/spree/return_item/eligibility_validator/time_since_purchase_spec.rb +22 -15
  691. data/spec/models/spree/return_item/exchange_variant_eligibility/same_option_value_spec.rb +2 -0
  692. data/spec/models/spree/return_item/exchange_variant_eligibility/same_product_spec.rb +2 -0
  693. data/spec/models/spree/return_item_spec.rb +2 -0
  694. data/spec/models/spree/returns_calculator_spec.rb +2 -0
  695. data/spec/models/spree/shipment_spec.rb +45 -4
  696. data/spec/models/spree/shipping_calculator_spec.rb +2 -0
  697. data/spec/models/spree/shipping_manifest_spec.rb +2 -0
  698. data/spec/models/spree/shipping_method_spec.rb +2 -0
  699. data/spec/models/spree/shipping_rate_spec.rb +1 -1
  700. data/spec/models/spree/shipping_rate_tax_spec.rb +2 -0
  701. data/spec/models/spree/state_spec.rb +2 -0
  702. data/spec/models/spree/stock/availability_spec.rb +2 -0
  703. data/spec/models/spree/stock/availability_validator_spec.rb +2 -0
  704. data/spec/models/spree/stock/differentiator_spec.rb +2 -0
  705. data/spec/models/spree/stock/estimator_spec.rb +31 -1
  706. data/spec/models/spree/stock/inventory_unit_builder_spec.rb +2 -0
  707. data/spec/models/spree/stock/package_spec.rb +2 -0
  708. data/spec/models/spree/stock/quantifier_spec.rb +2 -0
  709. data/spec/models/spree/stock/shipping_rate_selector_spec.rb +2 -0
  710. data/spec/models/spree/stock/shipping_rate_sorter_spec.rb +2 -0
  711. data/spec/models/spree/stock/simple_coordinator_spec.rb +2 -0
  712. data/spec/models/spree/stock/splitter/backordered_spec.rb +2 -0
  713. data/spec/models/spree/stock/splitter/base_spec.rb +2 -0
  714. data/spec/models/spree/stock/splitter/shipping_category_spec.rb +2 -0
  715. data/spec/models/spree/stock/splitter/weight_spec.rb +2 -0
  716. data/spec/models/spree/stock/splitter_chain_spec.rb +2 -0
  717. data/spec/models/spree/stock_item_spec.rb +2 -0
  718. data/spec/models/spree/stock_location_spec.rb +2 -0
  719. data/spec/models/spree/stock_movement_spec.rb +2 -0
  720. data/spec/models/spree/stock_quantities_spec.rb +2 -0
  721. data/spec/models/spree/store_credit_category_spec.rb +2 -0
  722. data/spec/models/spree/store_credit_event_spec.rb +17 -1
  723. data/spec/models/spree/store_credit_spec.rb +22 -5
  724. data/spec/models/spree/store_selector/by_server_name_spec.rb +2 -0
  725. data/spec/models/spree/store_selector/legacy_spec.rb +2 -0
  726. data/spec/models/spree/store_spec.rb +59 -0
  727. data/spec/models/spree/tax/order_adjuster_spec.rb +2 -0
  728. data/spec/models/spree/tax/shipping_rate_taxer_spec.rb +2 -0
  729. data/spec/models/spree/tax/tax_location_spec.rb +2 -0
  730. data/spec/models/spree/tax/taxation_integration_spec.rb +2 -0
  731. data/spec/models/spree/tax_calculator/default_spec.rb +2 -0
  732. data/spec/models/spree/tax_category_spec.rb +2 -0
  733. data/spec/models/spree/tax_rate_spec.rb +5 -4
  734. data/spec/models/spree/taxon_spec.rb +9 -1
  735. data/spec/models/spree/taxonomy_spec.rb +5 -7
  736. data/spec/models/spree/unit_cancel_spec.rb +2 -0
  737. data/spec/models/spree/user_spec.rb +2 -0
  738. data/spec/models/spree/validations/db_maximum_length_validator_spec.rb +2 -0
  739. data/spec/models/spree/variant/price_selector_spec.rb +2 -0
  740. data/spec/models/spree/variant/pricing_options_spec.rb +2 -0
  741. data/spec/models/spree/variant/scopes_spec.rb +16 -0
  742. data/spec/models/spree/variant/vat_price_generator_spec.rb +2 -0
  743. data/spec/models/spree/variant_property_rule_condition_spec.rb +2 -0
  744. data/spec/models/spree/variant_property_rule_spec.rb +2 -0
  745. data/spec/models/spree/variant_property_rule_value_spec.rb +2 -0
  746. data/spec/models/spree/variant_spec.rb +2 -2
  747. data/spec/models/spree/wallet_payment_source_spec.rb +2 -0
  748. data/spec/models/spree/wallet_spec.rb +2 -0
  749. data/spec/models/spree/zone_spec.rb +2 -0
  750. data/spec/rails_helper.rb +4 -2
  751. data/spec/shared_examples/calculator_shared_examples.rb +2 -0
  752. data/spec/spec_helper.rb +2 -0
  753. data/spec/support/big_decimal.rb +2 -0
  754. data/spec/support/concerns/default_price.rb +2 -0
  755. data/spec/support/concerns/payment_source.rb +2 -0
  756. data/spec/support/concerns/working_factories.rb +2 -0
  757. data/spec/support/dummy_ability.rb +2 -0
  758. data/spec/support/shared_contexts/rake.rb +2 -0
  759. metadata +114 -54
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Spree
2
4
  class OrderMutex < Spree::Base
3
5
  class LockFailed < StandardError; end
@@ -25,7 +27,6 @@ module Spree
25
27
  end
26
28
 
27
29
  yield
28
-
29
30
  ensure
30
31
  order_mutex.destroy if order_mutex
31
32
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Spree
2
4
  # Spree::OrderPromotion represents the relationship between:
3
5
  #
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # A service layer that handles generating Carton objects when inventory units
2
4
  # are actually shipped. It also takes care of things like updating order and
3
5
  # shipment states and delivering shipment emails as needed.
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Spree
2
4
  # Relatively simple class used to apply a {Spree::Tax::OrderTax} to a
3
5
  # {Spree::Order}.
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Spree
2
4
  class OrderUpdateAttributes
3
5
  # @param order [Order] existing (persisted) order
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Spree
2
4
  class OrderUpdater
3
5
  attr_reader :order
@@ -57,6 +59,7 @@ module Spree
57
59
  # balance_due when +payment_total+ is less than +total+
58
60
  # credit_owed when +payment_total+ is greater than +total+
59
61
  # failed when most recent payment is in the failed state
62
+ # void when the order has been canceled and the payment total is 0
60
63
  #
61
64
  # The +payment_state+ value helps with reporting, etc. since it provides a quick and easy way to locate Orders needing attention.
62
65
  def update_payment_state
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Spree
2
4
  # Manage and process a payment for an order, from a specific
3
5
  # source (e.g. `Spree::CreditCard`) using a specific payment method (e.g
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Spree
2
4
  class Payment
3
5
  # Payment cancellation handler
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Spree
2
4
  class Payment < Spree::Base
3
5
  module Processing
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Spree
2
4
  class PaymentCaptureEvent < Spree::Base
3
5
  belongs_to :payment, class_name: 'Spree::Payment'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Spree
2
4
  # Service object for creating new payments on an Order
3
5
  class PaymentCreate
@@ -1,12 +1,11 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'discard'
2
4
  require 'spree/preferences/statically_configurable'
3
5
 
4
6
  module Spree
5
7
  # A base class which is used for implementing payment methods.
6
8
  #
7
- # See https://github.com/solidusio/solidus_gateway/ for
8
- # offically supported payment method implementations.
9
- #
10
9
  # Uses STI (single table inheritance) to store all implemented payment methods
11
10
  # in one table (+spree_payment_methods+).
12
11
  #
@@ -23,7 +22,15 @@ module Spree
23
22
  self.discard_column = :deleted_at
24
23
 
25
24
  acts_as_list
26
- DISPLAY = [:both, :front_end, :back_end]
25
+
26
+ # @private
27
+ def self.const_missing(name)
28
+ if name == :DISPLAY
29
+ const_set(:DISPLAY, [:both, :front_end, :back_end])
30
+ else
31
+ super
32
+ end
33
+ end
27
34
 
28
35
  validates :name, :type, presence: true
29
36
 
@@ -61,12 +68,14 @@ module Spree
61
68
  end
62
69
 
63
70
  class << self
71
+ # @deprecated Use Spree::Config.environment.payment_methods instead
64
72
  def providers
65
73
  Spree::Deprecation.warn 'Spree::PaymentMethod.providers is deprecated and will be deleted in Solidus 3.0. ' \
66
74
  'Please use Rails.application.config.spree.payment_methods instead'
67
75
  Spree::Config.environment.payment_methods
68
76
  end
69
77
 
78
+ # @deprecated Use {.active}, {.available_to_users}, and {.available_to_admin} scopes instead.
70
79
  def available(display_on = nil, store: nil)
71
80
  Spree::Deprecation.warn "Spree::PaymentMethod.available is deprecated."\
72
81
  "Please use .active, .available_to_users, and .available_to_admin scopes instead."\
@@ -93,11 +102,15 @@ module Spree
93
102
  ModelName.new(self, Spree)
94
103
  end
95
104
 
105
+ # @deprecated Use .active.any? instead
96
106
  def active?
107
+ Spree::Deprecation.warn "#{self}.active? is deprecated. Use #{self}.active.any? instead"
97
108
  where(type: to_s, active: true).count > 0
98
109
  end
99
110
 
111
+ # @deprecated Use .with_deleted.find instead
100
112
  def find_with_destroyed(*args)
113
+ Spree::Deprecation.warn "#{self}.find_with_destroyed is deprecated. Use #{self}.with_deleted.find instead"
101
114
  unscoped { find(*args) }
102
115
  end
103
116
  end
@@ -143,7 +156,7 @@ module Spree
143
156
  raise ::NotImplementedError, "You must implement payment_source_class method for #{self.class}."
144
157
  end
145
158
 
146
- # @deprecated Use {#available_to_users=} and {#available_to_admin=} instead
159
+ # @deprecated Use {Spree::PaymentMethod#available_to_users=} and {Spree::PaymentMethod#available_to_admin=} instead
147
160
  def display_on=(value)
148
161
  Spree::Deprecation.warn "Spree::PaymentMethod#display_on= is deprecated."\
149
162
  "Please use #available_to_users= and #available_to_admin= instead."
@@ -151,7 +164,7 @@ module Spree
151
164
  self.available_to_admin = value.blank? || value == 'back_end'
152
165
  end
153
166
 
154
- # @deprecated Use {#available_to_users} and {#available_to_admin} instead
167
+ # @deprecated Use {Spree::PaymentMethod#available_to_users} and {Spree::PaymentMethod#available_to_admin} instead
155
168
  def display_on
156
169
  Spree::Deprecation.warn "Spree::PaymentMethod#display_on is deprecated."\
157
170
  "Please use #available_to_users and #available_to_admin instead."
@@ -208,8 +221,8 @@ module Spree
208
221
  true
209
222
  end
210
223
 
211
- # Custom gateways should redefine this method. See Gateway implementation
212
- # as an example
224
+ # Custom gateways can redefine this method to return reusable sources for an order.
225
+ # See {Spree::PaymentMethod::CreditCard#reusable_sources} as an example
213
226
  def reusable_sources(_order)
214
227
  []
215
228
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Spree
2
4
  class PaymentMethod::BogusCreditCard < PaymentMethod::CreditCard
3
5
  TEST_VISA = ['4111111111111111', '4012888888881881', '4222222222222']
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Spree
2
4
  class PaymentMethod::Check < PaymentMethod
3
5
  def actions
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Spree
2
4
  # An implementation of a `Spree::PaymentMethod` for credit card payments.
3
5
  #
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Spree
2
4
  # Bogus Gateway that doesn't support payment profiles.
3
5
  class PaymentMethod::SimpleBogusCreditCard < PaymentMethod::BogusCreditCard
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Spree
2
4
  class PaymentMethod::StoreCredit < PaymentMethod
3
5
  def payment_source_class
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Spree
2
4
  class PaymentSource < Spree::Base
3
5
  self.abstract_class = true
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class Spree::Preference < Spree::Base
2
4
  serialize :value
3
5
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'discard'
2
4
 
3
5
  module Spree
@@ -34,7 +36,7 @@ module Spree
34
36
  money_methods :amount, :price
35
37
  alias_method :money, :display_amount
36
38
 
37
- self.whitelisted_ransackable_attributes = %w( amount variant_id currency country_iso )
39
+ self.whitelisted_ransackable_attributes = %w(amount variant_id currency country_iso)
38
40
 
39
41
  # An alias for #amount
40
42
  def price
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'discard'
2
4
 
3
5
  module Spree
@@ -300,7 +302,7 @@ module Spree
300
302
 
301
303
  # Finds the variant property rule that matches the provided option value ids.
302
304
  #
303
- # @param [Array<Integer>] list of option value ids
305
+ # @param option_value_ids [Array<Integer>] list of option value ids
304
306
  # @return [Spree::VariantPropertyRule] the matching variant property rule
305
307
  def find_variant_property_rule(option_value_ids)
306
308
  variant_property_rules.find do |rule|
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Spree
2
4
  class Product < Spree::Base
3
5
  cattr_accessor :search_scopes do
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Spree
2
4
  class ProductOptionType < Spree::Base
3
5
  belongs_to :product, class_name: 'Spree::Product', inverse_of: :product_option_types, touch: true
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Spree
2
4
  class ProductPromotionRule < Spree::Base
3
5
  belongs_to :product
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Spree
2
4
  class ProductProperty < Spree::Base
3
5
  include Spree::OrderedPropertyValueList
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Spree
2
4
  class Promotion < Spree::Base
3
5
  MATCH_POLICIES = %w(all any)
@@ -1,5 +1,7 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Spree
2
- class Promotion
4
+ class Promotion < Spree::Base
3
5
  module Actions
4
6
  class CreateAdjustment < PromotionAction
5
7
  include Spree::CalculatedAdjustments
@@ -1,5 +1,7 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Spree
2
- class Promotion
4
+ class Promotion < Spree::Base
3
5
  module Actions
4
6
  class CreateItemAdjustments < PromotionAction
5
7
  include Spree::CalculatedAdjustments
@@ -1,135 +1,141 @@
1
- module Spree::Promotion::Actions
2
- class CreateQuantityAdjustments < CreateItemAdjustments
3
- preference :group_size, :integer, default: 1
4
-
5
- has_many :line_item_actions, foreign_key: :action_id, dependent: :destroy
6
- has_many :line_items, through: :line_item_actions
7
-
8
- ##
9
- # Computes the amount for the adjustment based on the line item and any
10
- # other applicable items in the order. The rules for this specific
11
- # adjustment are as follows:
12
- #
13
- # = Setup
14
- #
15
- # We have a quantity group promotion on t-shirts. If a user orders 3
16
- # t-shirts, they get $5 off of each. The shirts come in one size and three
17
- # colours: red, blue, and white.
18
- #
19
- # == Scenario 1
20
- #
21
- # User has 2 red shirts, 1 white shirt, and 1 blue shirt in their
22
- # order. We want to compute the adjustment amount for the white shirt.
23
- #
24
- # *Result:* -$5
25
- #
26
- # *Reasoning:* There are a total of 4 items that are eligible for the
27
- # promotion. Since that is greater than 3, we can discount the items. The
28
- # white shirt has a quantity of 1, therefore it will get discounted by
29
- # +adjustment_amount * 1+ or $5.
30
- #
31
- # === Scenario 1-1
32
- #
33
- # What about the blue shirt? How much does it get discounted?
34
- #
35
- # *Result:* $0
36
- #
37
- # *Reasoning:* We have a total quantity of 4. However, we only apply the
38
- # adjustment to groups of 3. Assuming the white and red shirts have already
39
- # had their adjustment calculated, that means 3 units have been discounted.
40
- # Leaving us with a lonely blue shirt that isn't part of a group of 3.
41
- # Therefore, it does not receive the discount.
42
- #
43
- # == Scenario 2
44
- #
45
- # User has 4 red shirts in their order. What is the amount?
46
- #
47
- # *Result:* -$15
48
- #
49
- # *Reasoning:* The total quantity of eligible items is 4, so we the
50
- # adjustment will be non-zero. However, we only apply it to groups of 3,
51
- # therefore there is one extra item that is not eligible for the
52
- # adjustment. +adjustment_amount * 3+ or $15.
53
- #
54
- def compute_amount(line_item)
55
- adjustment_amount = calculator.compute(PartialLineItem.new(line_item))
56
- if !adjustment_amount.is_a?(BigDecimal)
57
- Spree::Deprecation.warn "#{calculator.class.name}#compute returned #{adjustment_amount.inspect}, it should return a BigDecimal"
58
- end
59
- adjustment_amount ||= BigDecimal(0)
60
- adjustment_amount = adjustment_amount.abs
61
-
62
- order = line_item.order
63
- line_items = actionable_line_items(order)
64
-
65
- actioned_line_items = order.line_item_adjustments.reload.
66
- select { |a| a.source == self && a.amount < 0 }.
67
- map(&:adjustable)
68
- other_line_items = actioned_line_items - [line_item]
69
-
70
- applicable_quantity = total_applicable_quantity(line_items)
71
- used_quantity = total_used_quantity(other_line_items)
72
- usable_quantity = [
73
- applicable_quantity - used_quantity,
74
- line_item.quantity
75
- ].min
76
-
77
- persist_quantity(usable_quantity, line_item)
78
-
79
- amount = adjustment_amount * usable_quantity
80
- [line_item.amount, amount].min * -1
81
- end
82
-
83
- private
84
-
85
- def actionable_line_items(order)
86
- order.line_items.select do |item|
87
- promotion.line_item_actionable? order, item
88
- end
89
- end
90
-
91
- def total_applicable_quantity(line_items)
92
- total_quantity = line_items.sum(&:quantity)
93
- extra_quantity = total_quantity % preferred_group_size
94
-
95
- total_quantity - extra_quantity
96
- end
97
-
98
- def total_used_quantity(line_items)
99
- line_item_actions.where(
100
- line_item_id: line_items.map(&:id)
101
- ).sum(:quantity)
102
- end
103
-
104
- def persist_quantity(quantity, line_item)
105
- line_item_action = line_item_actions.where(
106
- line_item_id: line_item.id
107
- ).first_or_initialize
108
- line_item_action.quantity = quantity
109
- line_item_action.save!
110
- end
111
-
112
- ##
113
- # Used specifically for PercentOnLineItem calculator. That calculator uses
114
- # `line_item.amount`, however we might not necessarily want to discount the
115
- # entire amount. This class allows us to determine the discount per
116
- # quantity and then calculate the adjustment amount the way we normally do
117
- # for flat rate adjustments.
118
- class PartialLineItem
119
- def initialize(line_item)
120
- @line_item = line_item
121
- end
122
-
123
- def amount
124
- @line_item.price
125
- end
126
-
127
- def order
128
- @line_item.order
129
- end
130
-
131
- def currency
132
- @line_item.currency
1
+ # frozen_string_literal: true
2
+
3
+ module Spree
4
+ class Promotion < Spree::Base
5
+ module Actions
6
+ class CreateQuantityAdjustments < CreateItemAdjustments
7
+ preference :group_size, :integer, default: 1
8
+
9
+ has_many :line_item_actions, foreign_key: :action_id, dependent: :destroy
10
+ has_many :line_items, through: :line_item_actions
11
+
12
+ ##
13
+ # Computes the amount for the adjustment based on the line item and any
14
+ # other applicable items in the order. The rules for this specific
15
+ # adjustment are as follows:
16
+ #
17
+ # = Setup
18
+ #
19
+ # We have a quantity group promotion on t-shirts. If a user orders 3
20
+ # t-shirts, they get $5 off of each. The shirts come in one size and three
21
+ # colours: red, blue, and white.
22
+ #
23
+ # == Scenario 1
24
+ #
25
+ # User has 2 red shirts, 1 white shirt, and 1 blue shirt in their
26
+ # order. We want to compute the adjustment amount for the white shirt.
27
+ #
28
+ # *Result:* -$5
29
+ #
30
+ # *Reasoning:* There are a total of 4 items that are eligible for the
31
+ # promotion. Since that is greater than 3, we can discount the items. The
32
+ # white shirt has a quantity of 1, therefore it will get discounted by
33
+ # +adjustment_amount * 1+ or $5.
34
+ #
35
+ # === Scenario 1-1
36
+ #
37
+ # What about the blue shirt? How much does it get discounted?
38
+ #
39
+ # *Result:* $0
40
+ #
41
+ # *Reasoning:* We have a total quantity of 4. However, we only apply the
42
+ # adjustment to groups of 3. Assuming the white and red shirts have already
43
+ # had their adjustment calculated, that means 3 units have been discounted.
44
+ # Leaving us with a lonely blue shirt that isn't part of a group of 3.
45
+ # Therefore, it does not receive the discount.
46
+ #
47
+ # == Scenario 2
48
+ #
49
+ # User has 4 red shirts in their order. What is the amount?
50
+ #
51
+ # *Result:* -$15
52
+ #
53
+ # *Reasoning:* The total quantity of eligible items is 4, so we the
54
+ # adjustment will be non-zero. However, we only apply it to groups of 3,
55
+ # therefore there is one extra item that is not eligible for the
56
+ # adjustment. +adjustment_amount * 3+ or $15.
57
+ #
58
+ def compute_amount(line_item)
59
+ adjustment_amount = calculator.compute(PartialLineItem.new(line_item))
60
+ if !adjustment_amount.is_a?(BigDecimal)
61
+ Spree::Deprecation.warn "#{calculator.class.name}#compute returned #{adjustment_amount.inspect}, it should return a BigDecimal"
62
+ end
63
+ adjustment_amount ||= BigDecimal(0)
64
+ adjustment_amount = adjustment_amount.abs
65
+
66
+ order = line_item.order
67
+ line_items = actionable_line_items(order)
68
+
69
+ actioned_line_items = order.line_item_adjustments.reload.
70
+ select { |a| a.source == self && a.amount < 0 }.
71
+ map(&:adjustable)
72
+ other_line_items = actioned_line_items - [line_item]
73
+
74
+ applicable_quantity = total_applicable_quantity(line_items)
75
+ used_quantity = total_used_quantity(other_line_items)
76
+ usable_quantity = [
77
+ applicable_quantity - used_quantity,
78
+ line_item.quantity
79
+ ].min
80
+
81
+ persist_quantity(usable_quantity, line_item)
82
+
83
+ amount = adjustment_amount * usable_quantity
84
+ [line_item.amount, amount].min * -1
85
+ end
86
+
87
+ private
88
+
89
+ def actionable_line_items(order)
90
+ order.line_items.select do |item|
91
+ promotion.line_item_actionable? order, item
92
+ end
93
+ end
94
+
95
+ def total_applicable_quantity(line_items)
96
+ total_quantity = line_items.sum(&:quantity)
97
+ extra_quantity = total_quantity % preferred_group_size
98
+
99
+ total_quantity - extra_quantity
100
+ end
101
+
102
+ def total_used_quantity(line_items)
103
+ line_item_actions.where(
104
+ line_item_id: line_items.map(&:id)
105
+ ).sum(:quantity)
106
+ end
107
+
108
+ def persist_quantity(quantity, line_item)
109
+ line_item_action = line_item_actions.where(
110
+ line_item_id: line_item.id
111
+ ).first_or_initialize
112
+ line_item_action.quantity = quantity
113
+ line_item_action.save!
114
+ end
115
+
116
+ ##
117
+ # Used specifically for PercentOnLineItem calculator. That calculator uses
118
+ # `line_item.amount`, however we might not necessarily want to discount the
119
+ # entire amount. This class allows us to determine the discount per
120
+ # quantity and then calculate the adjustment amount the way we normally do
121
+ # for flat rate adjustments.
122
+ class PartialLineItem
123
+ def initialize(line_item)
124
+ @line_item = line_item
125
+ end
126
+
127
+ def amount
128
+ @line_item.price
129
+ end
130
+
131
+ def order
132
+ @line_item.order
133
+ end
134
+
135
+ def currency
136
+ @line_item.currency
137
+ end
138
+ end
133
139
  end
134
140
  end
135
141
  end