solidus_core 1.1.4 → 1.2.0.beta1

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 (296) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/images/logo/solidus_logo.png +0 -0
  3. data/app/helpers/spree/base_helper.rb +2 -3
  4. data/app/models/concerns/spree/adjustment_source.rb +1 -1
  5. data/app/models/concerns/spree/default_price.rb +3 -1
  6. data/app/models/concerns/spree/named_type.rb +1 -1
  7. data/app/models/concerns/spree/user_methods.rb +10 -0
  8. data/app/models/spree/adjustment.rb +1 -1
  9. data/app/models/spree/adjustment_reason.rb +2 -4
  10. data/app/models/spree/app_configuration.rb +36 -0
  11. data/app/models/spree/base.rb +10 -1
  12. data/app/models/spree/calculator/tiered_percent.rb +2 -1
  13. data/app/models/spree/classification.rb +1 -1
  14. data/app/models/spree/country.rb +3 -3
  15. data/app/models/spree/credit_card.rb +2 -2
  16. data/app/models/spree/customer_return.rb +3 -4
  17. data/app/models/spree/inventory_unit.rb +13 -24
  18. data/app/models/spree/item_adjustments.rb +5 -5
  19. data/app/models/spree/line_item.rb +6 -15
  20. data/app/models/spree/log_entry.rb +1 -1
  21. data/app/models/spree/option_type.rb +4 -2
  22. data/app/models/spree/option_type_prototype.rb +6 -0
  23. data/app/models/spree/option_value.rb +1 -1
  24. data/app/models/spree/order.rb +18 -63
  25. data/app/models/spree/order/checkout.rb +4 -2
  26. data/app/models/spree/order_cancellations.rb +52 -1
  27. data/app/models/spree/order_contents.rb +1 -1
  28. data/app/models/spree/order_merger.rb +143 -0
  29. data/app/models/spree/order_shipping.rb +3 -3
  30. data/app/models/spree/order_update_attributes.rb +42 -0
  31. data/app/models/spree/order_updater.rb +1 -1
  32. data/app/models/spree/payment.rb +16 -10
  33. data/app/models/spree/payment_create.rb +68 -0
  34. data/app/models/spree/payment_method.rb +0 -1
  35. data/app/models/spree/preference.rb +1 -1
  36. data/app/models/spree/price.rb +1 -8
  37. data/app/models/spree/product.rb +9 -44
  38. data/app/models/spree/product/scopes.rb +9 -7
  39. data/app/models/spree/promotion/rules/nth_order.rb +1 -1
  40. data/app/models/spree/promotion/rules/taxon.rb +2 -1
  41. data/app/models/spree/promotion_chooser.rb +1 -0
  42. data/app/models/spree/promotion_code.rb +1 -1
  43. data/app/models/spree/promotion_rule_taxon.rb +6 -0
  44. data/app/models/spree/property.rb +2 -1
  45. data/app/models/spree/property_prototype.rb +6 -0
  46. data/app/models/spree/prototype.rb +6 -2
  47. data/app/models/spree/reimbursement.rb +10 -0
  48. data/app/models/spree/return_item/eligibility_validator/time_since_purchase.rb +1 -1
  49. data/app/models/spree/return_reason.rb +1 -7
  50. data/app/models/spree/role_user.rb +3 -5
  51. data/app/models/spree/shipment.rb +6 -11
  52. data/app/models/spree/shipping_method.rb +1 -7
  53. data/app/models/spree/shipping_rate.rb +3 -14
  54. data/app/models/spree/stock/coordinator.rb +48 -4
  55. data/app/models/spree/stock/estimator.rb +3 -6
  56. data/app/models/spree/stock/packer.rb +18 -2
  57. data/app/models/spree/stock/shipping_rate_selector.rb +16 -0
  58. data/app/models/spree/stock/shipping_rate_sorter.rb +16 -0
  59. data/app/models/spree/stock_item.rb +19 -15
  60. data/app/models/spree/stock_location.rb +2 -12
  61. data/app/models/spree/stock_transfer.rb +3 -3
  62. data/app/models/spree/store_credit.rb +2 -2
  63. data/app/models/spree/tax_category.rb +3 -2
  64. data/app/models/spree/tax_rate.rb +7 -14
  65. data/app/models/spree/taxon.rb +4 -1
  66. data/app/models/spree/taxonomy.rb +1 -1
  67. data/app/models/spree/transfer_item.rb +2 -2
  68. data/app/models/spree/unit_cancel.rb +2 -0
  69. data/app/models/spree/variant.rb +9 -14
  70. data/app/models/spree/zone.rb +6 -0
  71. data/app/models/spree/zone_member.rb +1 -4
  72. data/app/views/spree/order_mailer/cancel_email.text.erb +0 -0
  73. data/config/locales/en.yml +7 -5
  74. data/db/default/spree/countries.rb +1 -1
  75. data/db/default/spree/zones.rb +5 -11
  76. data/db/migrate/20130213191427_create_default_stock.rb +1 -1
  77. data/db/migrate/20130306181701_add_address_fields_to_stock_location.rb +1 -1
  78. data/db/migrate/20140309033438_create_store_from_preferences.rb +5 -2
  79. data/db/migrate/20141009204607_add_store_id_to_orders.rb +6 -2
  80. data/db/migrate/20141215235502_remove_extra_products_slug_index.rb +5 -0
  81. data/db/migrate/20141217215630_update_product_slug_index.rb +6 -0
  82. data/db/migrate/20150225205344_move_promotion_code_to_promotion_code_value.rb +2 -2
  83. data/db/migrate/20150609093816_increase_scale_on_pre_tax_amounts.rb +10 -0
  84. data/db/migrate/20151117063249_convert_habtm_to_hmt_for_properties_prototypes.rb +17 -0
  85. data/db/migrate/20151124062500_convert_habtm_to_hmt_for_option_type_prototypes.rb +17 -0
  86. data/db/migrate/20151126063028_convert_habtm_to_hmt_for_taxons_promotion_rules.rb +15 -0
  87. data/db/migrate/20151219020209_add_stock_item_unique_index.rb +9 -0
  88. data/lib/generators/spree/dummy/dummy_generator.rb +1 -1
  89. data/lib/generators/spree/dummy/templates/rails/database.yml +1 -1
  90. data/lib/generators/spree/install/templates/config/initializers/spree.rb +25 -1
  91. data/lib/generators/spree/install/templates/vendor/assets/javascripts/spree/backend/all.js +3 -0
  92. data/lib/generators/spree/install/templates/vendor/assets/javascripts/spree/frontend/all.js +3 -0
  93. data/lib/generators/spree/install/templates/vendor/assets/stylesheets/spree/backend/all.css +3 -0
  94. data/lib/generators/spree/install/templates/vendor/assets/stylesheets/spree/frontend/all.css +3 -0
  95. data/lib/spree/core/controller_helpers/common.rb +1 -1
  96. data/lib/spree/core/controller_helpers/order.rb +1 -1
  97. data/lib/spree/core/controller_helpers/payment_parameters.rb +104 -5
  98. data/lib/spree/core/engine.rb +3 -2
  99. data/lib/spree/core/stock_configuration.rb +11 -0
  100. data/lib/spree/core/unreturned_item_charger.rb +4 -4
  101. data/lib/spree/core/version.rb +9 -1
  102. data/lib/spree/permission_sets/restricted_stock_transfer_management.rb +15 -24
  103. data/lib/spree/permitted_attributes.rb +3 -1
  104. data/lib/spree/testing_support/capybara_ext.rb +14 -40
  105. data/lib/spree/testing_support/factories.rb +0 -15
  106. data/lib/spree/testing_support/factories/address_factory.rb +3 -0
  107. data/lib/spree/testing_support/factories/adjustment_factory.rb +9 -1
  108. data/lib/spree/testing_support/factories/carton_factory.rb +4 -1
  109. data/lib/spree/testing_support/factories/customer_return_factory.rb +4 -0
  110. data/lib/spree/testing_support/factories/inventory_unit_factory.rb +5 -0
  111. data/lib/spree/testing_support/factories/line_item_factory.rb +3 -0
  112. data/lib/spree/testing_support/factories/option_type_factory.rb +6 -0
  113. data/lib/spree/testing_support/factories/{options_factory.rb → option_value_factory.rb} +0 -5
  114. data/lib/spree/testing_support/factories/order_factory.rb +13 -3
  115. data/lib/spree/testing_support/factories/order_promotion_factory.rb +3 -0
  116. data/lib/spree/testing_support/factories/payment_factory.rb +13 -5
  117. data/lib/spree/testing_support/factories/price_factory.rb +2 -0
  118. data/lib/spree/testing_support/factories/product_factory.rb +7 -1
  119. data/lib/spree/testing_support/factories/product_option_type_factory.rb +3 -0
  120. data/lib/spree/testing_support/factories/product_property_factory.rb +3 -0
  121. data/lib/spree/testing_support/factories/promotion_code_factory.rb +3 -0
  122. data/lib/spree/testing_support/factories/promotion_factory.rb +3 -0
  123. data/lib/spree/testing_support/factories/prototype_factory.rb +2 -0
  124. data/lib/spree/testing_support/factories/refund_factory.rb +10 -5
  125. data/lib/spree/testing_support/factories/refund_reason_factory.rb +5 -0
  126. data/lib/spree/testing_support/factories/reimbursement_factory.rb +2 -0
  127. data/lib/spree/testing_support/factories/return_authorization_factory.rb +4 -4
  128. data/lib/spree/testing_support/factories/return_item_factory.rb +4 -0
  129. data/lib/spree/testing_support/factories/return_reason_factory.rb +5 -0
  130. data/lib/spree/testing_support/factories/shipment_factory.rb +6 -1
  131. data/lib/spree/testing_support/factories/shipping_method_factory.rb +22 -10
  132. data/lib/spree/testing_support/factories/shipping_rate_factory.rb +9 -0
  133. data/lib/spree/testing_support/factories/state_factory.rb +2 -0
  134. data/lib/spree/testing_support/factories/stock_item_factory.rb +4 -1
  135. data/lib/spree/testing_support/factories/stock_location_factory.rb +8 -0
  136. data/lib/spree/testing_support/factories/stock_movement_factory.rb +2 -0
  137. data/lib/spree/testing_support/factories/{stock_factory.rb → stock_package_factory.rb} +5 -10
  138. data/lib/spree/testing_support/factories/stock_packer_factory.rb +13 -0
  139. data/lib/spree/testing_support/factories/stock_transfer_factory.rb +2 -2
  140. data/lib/spree/testing_support/factories/store_credit_event_factory.rb +4 -1
  141. data/lib/spree/testing_support/factories/store_credit_factory.rb +10 -6
  142. data/lib/spree/testing_support/factories/tax_category_factory.rb +2 -0
  143. data/lib/spree/testing_support/factories/tax_rate_factory.rb +4 -0
  144. data/lib/spree/testing_support/factories/taxon_factory.rb +2 -0
  145. data/lib/spree/testing_support/factories/user_factory.rb +6 -2
  146. data/lib/spree/testing_support/factories/variant_factory.rb +5 -0
  147. data/lib/spree/testing_support/factories/variant_property_rule_condition_factory.rb +3 -0
  148. data/lib/spree/testing_support/factories/variant_property_rule_factory.rb +4 -0
  149. data/lib/spree/testing_support/factories/variant_property_rule_value_factory.rb +3 -0
  150. data/lib/spree/testing_support/factories/zone_factory.rb +6 -0
  151. data/lib/spree/testing_support/sequences.rb +9 -0
  152. data/lib/tasks/exchanges.rake +4 -3
  153. data/lib/tasks/migrations/copy_shipped_shipments_to_cartons.rake +2 -2
  154. data/solidus_core.gemspec +4 -5
  155. data/spec/helpers/base_helper_spec.rb +6 -6
  156. data/spec/helpers/order_helper_spec.rb +1 -1
  157. data/spec/helpers/products_helper_spec.rb +2 -2
  158. data/spec/helpers/taxons_helper_spec.rb +1 -1
  159. data/spec/lib/spree/core/controller_helpers/payment_parameters_spec.rb +107 -7
  160. data/spec/lib/spree/core/importer/order_spec.rb +1 -1
  161. data/spec/lib/spree/core/stock_configuration_spec.rb +16 -0
  162. data/spec/lib/spree/core/testing_support/factories/address_factory_spec.rb +24 -0
  163. data/spec/lib/spree/core/testing_support/factories/adjustment_factory_spec.rb +18 -0
  164. data/spec/lib/spree/core/testing_support/factories/adjustment_reason_factory_spec.rb +12 -0
  165. data/spec/lib/spree/core/testing_support/factories/calculator_factory_spec.rb +42 -0
  166. data/spec/lib/spree/core/testing_support/factories/carton_factory_spec.rb +12 -0
  167. data/spec/lib/spree/core/testing_support/factories/country_factory_spec.rb +12 -0
  168. data/spec/lib/spree/core/testing_support/factories/credit_card_factory_spec.rb +12 -0
  169. data/spec/lib/spree/core/testing_support/factories/customer_return_factory_spec.rb +28 -0
  170. data/spec/lib/spree/core/testing_support/factories/image_factory_spec.rb +12 -0
  171. data/spec/lib/spree/core/testing_support/factories/inventory_unit_factory_spec.rb +12 -0
  172. data/spec/lib/spree/core/testing_support/factories/line_item_factory_spec.rb +12 -0
  173. data/spec/lib/spree/core/testing_support/factories/option_type_factory_spec.rb +12 -0
  174. data/spec/lib/spree/core/testing_support/factories/option_value_factory_spec.rb +12 -0
  175. data/spec/lib/spree/core/testing_support/factories/order_factory_spec.rb +49 -0
  176. data/spec/lib/spree/core/testing_support/factories/order_promotion_factory_spec.rb +12 -0
  177. data/spec/lib/spree/core/testing_support/factories/payment_factory_spec.rb +24 -0
  178. data/spec/lib/spree/core/testing_support/factories/payment_method_factory_spec.rb +30 -0
  179. data/spec/lib/spree/core/testing_support/factories/price_factory_spec.rb +12 -0
  180. data/spec/lib/spree/core/testing_support/factories/product_factory_spec.rb +30 -0
  181. data/spec/lib/spree/core/testing_support/factories/product_option_type_factory_spec.rb +12 -0
  182. data/spec/lib/spree/core/testing_support/factories/product_property_factory_spec.rb +12 -0
  183. data/spec/lib/spree/core/testing_support/factories/promotion_category_factory_spec.rb +12 -0
  184. data/spec/lib/spree/core/testing_support/factories/promotion_code_factory_spec.rb +12 -0
  185. data/spec/lib/spree/core/testing_support/factories/promotion_factory_spec.rb +30 -0
  186. data/spec/lib/spree/core/testing_support/factories/property_factory_spec.rb +12 -0
  187. data/spec/lib/spree/core/testing_support/factories/prototype_factory_spec.rb +12 -0
  188. data/spec/lib/spree/core/testing_support/factories/refund_factory_spec.rb +12 -0
  189. data/spec/lib/spree/core/testing_support/factories/refund_reason_factory_spec.rb +12 -0
  190. data/spec/lib/spree/core/testing_support/factories/reimbursement_factory_spec.rb +12 -0
  191. data/spec/lib/spree/core/testing_support/factories/reimbursement_type_factory_spec.rb +12 -0
  192. data/spec/lib/spree/core/testing_support/factories/return_authorization_factory_spec.rb +12 -0
  193. data/spec/lib/spree/core/testing_support/factories/return_item_factory_spec.rb +18 -0
  194. data/spec/lib/spree/core/testing_support/factories/return_reason_factory_spec.rb +12 -0
  195. data/spec/lib/spree/core/testing_support/factories/role_factory_spec.rb +18 -0
  196. data/spec/lib/spree/core/testing_support/factories/shipment_factory_spec.rb +12 -0
  197. data/spec/lib/spree/core/testing_support/factories/shipping_category_factory_spec.rb +12 -0
  198. data/spec/lib/spree/core/testing_support/factories/shipping_method_factory_spec.rb +28 -0
  199. data/spec/lib/spree/core/testing_support/factories/shipping_rate_factory_spec.rb +12 -0
  200. data/spec/lib/spree/core/testing_support/factories/state_factory_spec.rb +12 -0
  201. data/spec/lib/spree/core/testing_support/factories/stock_item_factory_spec.rb +12 -0
  202. data/spec/lib/spree/core/testing_support/factories/stock_location_factory_spec.rb +24 -0
  203. data/spec/lib/spree/core/testing_support/factories/stock_movement_factory_spec.rb +12 -0
  204. data/spec/lib/spree/core/testing_support/factories/stock_package_factory_spec.rb +26 -0
  205. data/spec/lib/spree/core/testing_support/factories/stock_packer_factory_spec.rb +16 -0
  206. data/spec/lib/spree/core/testing_support/factories/stock_transfer_factory_spec.rb +12 -0
  207. data/spec/lib/spree/core/testing_support/factories/store_credit_category_factory_spec.rb +12 -0
  208. data/spec/lib/spree/core/testing_support/factories/store_credit_event_factory_spec.rb +42 -0
  209. data/spec/lib/spree/core/testing_support/factories/store_credit_factory_spec.rb +12 -0
  210. data/spec/lib/spree/core/testing_support/factories/store_credit_type_factory_spec.rb +18 -0
  211. data/spec/lib/spree/core/testing_support/factories/store_credit_update_reason_factory_spec.rb +12 -0
  212. data/spec/lib/spree/core/testing_support/factories/store_factory_spec.rb +12 -0
  213. data/spec/lib/spree/core/testing_support/factories/tax_category_factory_spec.rb +12 -0
  214. data/spec/lib/spree/core/testing_support/factories/tax_rate_factory_spec.rb +12 -0
  215. data/spec/lib/spree/core/testing_support/factories/taxon_factory_spec.rb +12 -0
  216. data/spec/lib/spree/core/testing_support/factories/taxonomy_factory_spec.rb +12 -0
  217. data/spec/lib/spree/core/testing_support/factories/tracker_factory_spec.rb +12 -0
  218. data/spec/lib/spree/core/testing_support/factories/user_factory_spec.rb +22 -0
  219. data/spec/lib/spree/core/testing_support/factories/variant_factory_spec.rb +36 -0
  220. data/spec/lib/spree/core/testing_support/factories/variant_property_rule_condition_factory_spec.rb +12 -0
  221. data/spec/lib/spree/core/testing_support/factories/variant_property_rule_factory_spec.rb +12 -0
  222. data/spec/lib/spree/core/testing_support/factories/variant_property_rule_value_factory_spec.rb +12 -0
  223. data/spec/lib/spree/core/testing_support/factories/zone_factory_spec.rb +18 -0
  224. data/spec/lib/spree/core/unreturned_item_charger_spec.rb +1 -1
  225. data/spec/lib/spree/core/version_spec.rb +17 -0
  226. data/spec/lib/spree/money_spec.rb +1 -1
  227. data/spec/mailers/carton_mailer_spec.rb +1 -1
  228. data/spec/mailers/order_mailer_spec.rb +1 -1
  229. data/spec/mailers/reimbursement_mailer_spec.rb +1 -3
  230. data/spec/mailers/test_mailer_spec.rb +1 -3
  231. data/spec/models/spree/address_spec.rb +4 -4
  232. data/spec/models/spree/adjustment_reason_spec.rb +1 -3
  233. data/spec/models/spree/app_configuration_spec.rb +4 -0
  234. data/spec/models/spree/calculator/price_sack_spec.rb +3 -3
  235. data/spec/models/spree/calculator/shipping/price_sack_spec.rb +3 -3
  236. data/spec/models/spree/calculator/tiered_percent_spec.rb +86 -10
  237. data/spec/models/spree/carton_spec.rb +3 -1
  238. data/spec/models/spree/classification_spec.rb +3 -3
  239. data/spec/models/spree/credit_card_spec.rb +16 -16
  240. data/spec/models/spree/customer_return_spec.rb +1 -1
  241. data/spec/models/spree/gateway/bogus_simple.rb +1 -1
  242. data/spec/models/spree/inventory_unit_spec.rb +3 -3
  243. data/spec/models/spree/item_adjustments_spec.rb +1 -1
  244. data/spec/models/spree/line_item_spec.rb +2 -2
  245. data/spec/models/spree/option_type_spec.rb +2 -2
  246. data/spec/models/spree/option_value_spec.rb +2 -2
  247. data/spec/models/spree/order/callbacks_spec.rb +1 -1
  248. data/spec/models/spree/order/checkout_spec.rb +16 -11
  249. data/spec/models/spree/order/payment_spec.rb +24 -22
  250. data/spec/models/spree/order/state_machine_spec.rb +1 -1
  251. data/spec/models/spree/order/validations_spec.rb +1 -1
  252. data/spec/models/spree/order_cancellations_spec.rb +63 -0
  253. data/spec/models/spree/order_contents_spec.rb +1 -1
  254. data/spec/models/spree/order_merger_spec.rb +133 -0
  255. data/spec/models/spree/order_spec.rb +39 -159
  256. data/spec/models/spree/order_update_attributes_spec.rb +82 -0
  257. data/spec/models/spree/order_updater_spec.rb +6 -4
  258. data/spec/models/spree/payment_create_spec.rb +131 -0
  259. data/spec/models/spree/payment_spec.rb +130 -48
  260. data/spec/models/spree/permission_sets/restricted_stock_transfer_management_spec.rb +91 -33
  261. data/spec/models/spree/product_filter_spec.rb +3 -3
  262. data/spec/models/spree/product_spec.rb +80 -26
  263. data/spec/models/spree/promotion/actions/create_adjustment_spec.rb +1 -1
  264. data/spec/models/spree/promotion/actions/create_item_adjustments_spec.rb +2 -2
  265. data/spec/models/spree/promotion/rules/nth_order_spec.rb +1 -1
  266. data/spec/models/spree/promotion/rules/user_spec.rb +2 -2
  267. data/spec/models/spree/promotion_handler/coupon_spec.rb +2 -2
  268. data/spec/models/spree/promotion_spec.rb +18 -18
  269. data/spec/models/spree/reimbursement_spec.rb +22 -0
  270. data/spec/models/spree/return_item_spec.rb +2 -2
  271. data/spec/models/spree/shipment_spec.rb +28 -12
  272. data/spec/models/spree/shipping_method_spec.rb +2 -2
  273. data/spec/models/spree/shipping_rate_spec.rb +3 -3
  274. data/spec/models/spree/stock/coordinator_spec.rb +5 -0
  275. data/spec/models/spree/stock/estimator_spec.rb +35 -1
  276. data/spec/models/spree/stock/package_spec.rb +1 -1
  277. data/spec/models/spree/stock/packer_spec.rb +2 -3
  278. data/spec/models/spree/stock/shipping_rate_selector_spec.rb +16 -0
  279. data/spec/models/spree/stock/shipping_rate_sorter_spec.rb +16 -0
  280. data/spec/models/spree/stock_item_spec.rb +5 -7
  281. data/spec/models/spree/stock_location_spec.rb +5 -9
  282. data/spec/models/spree/stock_transfer_spec.rb +33 -13
  283. data/spec/models/spree/store_credit_event_spec.rb +1 -1
  284. data/spec/models/spree/store_credit_spec.rb +1 -1
  285. data/spec/models/spree/tax_rate_spec.rb +381 -120
  286. data/spec/models/spree/taxon_spec.rb +3 -3
  287. data/spec/models/spree/transfer_item_spec.rb +4 -4
  288. data/spec/models/spree/unit_cancel_spec.rb +1 -1
  289. data/spec/models/spree/variant_spec.rb +3 -3
  290. data/spec/models/spree/zone_spec.rb +35 -1
  291. data/spec/support/concerns/working_factories.rb +9 -0
  292. data/vendor/assets/javascripts/jquery-migrate-1.0.0.js +498 -0
  293. data/vendor/assets/javascripts/jquery.payment.js +231 -80
  294. metadata +103 -27
  295. data/app/models/spree/order/currency_updater.rb +0 -40
  296. data/spec/models/spree/order/currency_updater_spec.rb +0 -32
@@ -0,0 +1,6 @@
1
+ module Spree
2
+ class OptionTypePrototype < Spree::Base
3
+ belongs_to :option_type
4
+ belongs_to :prototype
5
+ end
6
+ end
@@ -6,7 +6,7 @@ module Spree
6
6
  has_many :option_values_variants, dependent: :destroy
7
7
  has_many :variants, through: :option_values_variants
8
8
 
9
- validates :name, presence: true, uniqueness: { scope: :option_type_id }
9
+ validates :name, presence: true, uniqueness: { scope: :option_type_id, allow_blank: true }
10
10
  validates :presentation, presence: true
11
11
 
12
12
  after_save :touch, if: :changed?
@@ -9,7 +9,6 @@ module Spree
9
9
  ORDER_NUMBER_PREFIX = 'R'
10
10
 
11
11
  include Spree::Order::Checkout
12
- include Spree::Order::CurrencyUpdater
13
12
  include Spree::Order::Payments
14
13
 
15
14
  class InsufficientStock < StandardError; end
@@ -93,7 +92,6 @@ module Spree
93
92
 
94
93
  before_create :create_token
95
94
  before_create :link_by_email
96
- before_update :homogenize_line_item_currencies, if: :currency_changed?
97
95
 
98
96
  validates :email, presence: true, if: :require_email
99
97
  validates :email, email: true, if: :require_email, allow_blank: true
@@ -101,7 +99,11 @@ module Spree
101
99
 
102
100
  make_permalink field: :number
103
101
 
104
- delegate :update_totals, :persist_totals, :to => :updater
102
+ delegate :update_totals, :persist_totals, to: :updater
103
+ delegate :firstname, :lastname, to: :bill_address, prefix: true, allow_nil: true
104
+ alias_method :billing_firstname, :bill_address_firstname
105
+ alias_method :billing_lastname, :bill_address_lastname
106
+
105
107
 
106
108
  class_attribute :update_hooks
107
109
  self.update_hooks = Set.new
@@ -109,8 +111,11 @@ module Spree
109
111
  class_attribute :line_item_comparison_hooks
110
112
  self.line_item_comparison_hooks = Set.new
111
113
 
112
- def self.by_number(number)
113
- where(number: number)
114
+ class << self
115
+ def by_number(number)
116
+ where(number: number)
117
+ end
118
+ deprecate :by_number, deprecator: Spree::Deprecation
114
119
  end
115
120
 
116
121
  scope :created_between, ->(start_date, end_date) { where(created_at: start_date..end_date) }
@@ -190,9 +195,9 @@ module Spree
190
195
  end
191
196
 
192
197
  def confirmation_required?
193
- ActiveSupport::Deprecation.warn "Order#confirmation_required is deprecated.", caller
194
198
  true
195
199
  end
200
+ deprecate :confirmation_required?, deprecator: Spree::Deprecation
196
201
 
197
202
  def backordered?
198
203
  shipments.any?(&:backordered?)
@@ -410,14 +415,6 @@ module Spree
410
415
  ).uniq
411
416
  end
412
417
 
413
- def billing_firstname
414
- bill_address.try(:firstname)
415
- end
416
-
417
- def billing_lastname
418
- bill_address.try(:lastname)
419
- end
420
-
421
418
  def insufficient_stock_lines
422
419
  line_items.select(&:insufficient_stock?)
423
420
  end
@@ -435,35 +432,8 @@ module Spree
435
432
  end
436
433
  end
437
434
 
438
- def merge!(order, user = nil)
439
- order.line_items.each do |other_order_line_item|
440
- next unless other_order_line_item.currency == currency
441
-
442
- # Compare the line items of the other order with mine.
443
- # Make sure you allow any extensions to chime in on whether or
444
- # not the extension-specific parts of the line item match
445
- current_line_item = self.line_items.detect { |my_li|
446
- my_li.variant == other_order_line_item.variant &&
447
- self.line_item_comparison_hooks.all? { |hook|
448
- self.send(hook, my_li, other_order_line_item.serializable_hash)
449
- }
450
- }
451
- if current_line_item
452
- current_line_item.quantity += other_order_line_item.quantity
453
- current_line_item.save!
454
- else
455
- other_order_line_item.order_id = self.id
456
- other_order_line_item.save!
457
- end
458
- end
459
-
460
- self.associate_user!(user) if !self.user && !user.blank?
461
-
462
- updater.update
463
-
464
- # So that the destroy doesn't take out line items which may have been re-assigned
465
- order.line_items.reload
466
- order.destroy
435
+ def merge!(*args)
436
+ Spree::Config.order_merger_class.new(self).merge!(*args)
467
437
  end
468
438
 
469
439
  def empty!
@@ -555,7 +525,7 @@ module Spree
555
525
 
556
526
  self.update_columns(
557
527
  state: 'cart',
558
- updated_at: Time.now,
528
+ updated_at: Time.current,
559
529
  )
560
530
  self.next! if self.line_items.size > 0
561
531
  end
@@ -583,7 +553,7 @@ module Spree
583
553
  cancel!
584
554
  self.update_columns(
585
555
  canceler_id: user.id,
586
- canceled_at: Time.now,
556
+ canceled_at: Time.current,
587
557
  )
588
558
  end
589
559
  end
@@ -615,10 +585,12 @@ module Spree
615
585
  guest_token
616
586
  end
617
587
 
588
+ # @deprecated Do not use this method. Behaviour is unreliable.
618
589
  def fully_discounted?
619
590
  adjustment_total + line_items.map(&:final_amount).sum == 0.0
620
591
  end
621
592
  alias_method :fully_discounted, :fully_discounted?
593
+ deprecate :fully_discounted, deprecator: Spree::Deprecation
622
594
 
623
595
  def unreturned_exchange?
624
596
  # created_at - 1 is a hack to ensure that this doesn't blow up on MySQL,
@@ -709,23 +681,6 @@ module Spree
709
681
  Spree::Money.new(total_available_store_credit - total_applicable_store_credit, { currency: currency })
710
682
  end
711
683
 
712
- def payments_attributes=(attributes)
713
- validate_payments_attributes(attributes)
714
- super(attributes)
715
- end
716
-
717
- def validate_payments_attributes(attributes)
718
- attributes = Array.wrap(attributes)
719
- # Ensure the payment methods specified are allowed for this user
720
- payment_methods = Spree::PaymentMethod.where(id: available_payment_methods)
721
- attributes.each do |payment_attributes|
722
- payment_method_id = payment_attributes[:payment_method_id]
723
-
724
- # raise RecordNotFound unless it is an allowed payment method
725
- payment_methods.find(payment_method_id) if payment_method_id
726
- end
727
- end
728
-
729
684
  private
730
685
 
731
686
  def link_by_email
@@ -793,7 +748,7 @@ module Spree
793
748
  end
794
749
 
795
750
  def use_billing?
796
- @use_billing == true || @use_billing == 'true' || @use_billing == '1'
751
+ use_billing.in?([true, 'true', '1'])
797
752
  end
798
753
 
799
754
  def set_currency
@@ -247,7 +247,9 @@ module Spree
247
247
 
248
248
  set_callback :updating_from_params, :before, :update_params_payment_source
249
249
 
250
+ # @deprecated Use {OrderUpdateAttributes} instead
250
251
  def update_from_params(params, permitted_params, request_env = {})
252
+ ActiveSupport::Deprecation.warn "update_from_params is deprecated. Use the OrderUpdateAttributes class instead", caller
251
253
  success = false
252
254
  @updating_params = params
253
255
  run_callbacks :updating_from_params do
@@ -274,8 +276,8 @@ module Spree
274
276
  attributes[:payments_attributes].first[:request_env] = request_env
275
277
  end
276
278
 
277
- success = self.update_attributes(attributes)
278
- set_shipments_cost if self.shipments.any?
279
+ update = OrderUpdateAttributes.new(self, attributes, request_env: request_env)
280
+ success = update.apply
279
281
  end
280
282
 
281
283
  @updating_params = nil
@@ -14,6 +14,15 @@ class Spree::OrderCancellations
14
14
  @order = order
15
15
  end
16
16
 
17
+ # Marks inventory units short shipped. Adjusts the order based on the value of the inventory.
18
+ # Sends an email to the customer about what inventory has been short shipped.
19
+ #
20
+ # @api public
21
+ #
22
+ # @param [Array<InventoryUnit>] inventory_units the inventory units to be short shipped
23
+ # @param [String] whodunnit the system or person that is short shipping the inventory units
24
+ #
25
+ # @return [Array<UnitCancel>] the units that have been canceled due to short shipping
17
26
  def short_ship(inventory_units, whodunnit:nil)
18
27
  if inventory_units.map(&:order_id).uniq != [@order.id]
19
28
  raise ArgumentError, "Not all inventory units belong to this order"
@@ -42,6 +51,48 @@ class Spree::OrderCancellations
42
51
  unit_cancels
43
52
  end
44
53
 
54
+ # Marks inventory unit canceled. Optionally allows specifying the reason why and who is performing the action.
55
+ #
56
+ # @api public
57
+ #
58
+ # @param [InventoryUnit] inventory_unit the inventory unit to be canceled
59
+ # @param [String] reason the reason that you are canceling the inventory unit
60
+ # @param [String] whodunnit the system or person that is canceling the inventory unit
61
+ #
62
+ # @return [UnitCancel] the unit that has been canceled
63
+ def cancel_unit(inventory_unit, reason: Spree::UnitCancel::DEFAULT_REASON, whodunnit:nil)
64
+ unit_cancel = nil
65
+
66
+ Spree::OrderMutex.with_lock!(@order) do
67
+ unit_cancel = Spree::UnitCancel.create!(
68
+ inventory_unit: inventory_unit,
69
+ reason: reason,
70
+ created_by: whodunnit,
71
+ )
72
+
73
+ inventory_unit.cancel!
74
+ end
75
+
76
+ unit_cancel
77
+ end
78
+
79
+ # Reimburses inventory units due to cancellation.
80
+ #
81
+ # @api public
82
+ # @param [Array<InventoryUnit>] inventory_units the inventory units to be reimbursed
83
+ # @return [Reimbursement] the reimbursement for inventory being canceled
84
+ def reimburse_units(inventory_units)
85
+ reimbursement = nil
86
+
87
+ Spree::OrderMutex.with_lock!(@order) do
88
+ return_items = inventory_units.map(&:current_or_new_return_item)
89
+ reimbursement = Spree::Reimbursement.new(order: @order, return_items: return_items)
90
+ reimbursement.return_all
91
+ end
92
+
93
+ reimbursement
94
+ end
95
+
45
96
  private
46
97
 
47
98
  def short_ship_unit(inventory_unit, whodunnit:nil)
@@ -65,7 +116,7 @@ class Spree::OrderCancellations
65
116
 
66
117
  shipments.each do |shipment|
67
118
  if shipment.inventory_units.all? {|iu| iu.shipped? || iu.canceled? }
68
- shipment.update_attributes!(state: 'shipped', shipped_at: Time.now)
119
+ shipment.update_attributes!(state: 'shipped', shipped_at: Time.current)
69
120
  end
70
121
  end
71
122
  end
@@ -51,7 +51,7 @@ module Spree
51
51
  order.update_attributes!(
52
52
  approver: user,
53
53
  approver_name: name,
54
- approved_at: Time.now,
54
+ approved_at: Time.current,
55
55
  )
56
56
  end
57
57
 
@@ -0,0 +1,143 @@
1
+ module Spree
2
+ # Spree::OrderMerger is responsible for taking two orders and merging them
3
+ # together by adding the line items from additional orders to the order
4
+ # that the OrderMerger is initialized with.
5
+ #
6
+ # Orders that are merged should be incomplete orders which should belong to
7
+ # the same user. They should also be in the same currency.
8
+ class OrderMerger
9
+ # @!attribute order
10
+ # @api public
11
+ # @return [Spree::Order] The order which items wll be merged into.
12
+ attr_accessor :order
13
+
14
+ delegate :updater, to: :order
15
+
16
+ # Create the OrderMerger
17
+ #
18
+ # @api public
19
+ # @param [Spree::Order] order The order which line items will be merged
20
+ # into.
21
+ def initialize(order)
22
+ @order = order
23
+ end
24
+
25
+ # Merge a second order in to the order the OrderMerger was initialized with
26
+ #
27
+ # The line items from `other_order` will be merged in to the `order` for
28
+ # this OrderMerger object. If the line items are for the same variant, it
29
+ # will the quantity of the incoming line item to the existing line item.
30
+ # Otherwise, it will assign the line item to the new order.
31
+ #
32
+ # After the orders have been merged the `other_order` will be destroyed.
33
+ #
34
+ # @example
35
+ # initial_order = Spree::Order.find(1)
36
+ # order_to_merge = Spree::Order.find(2)
37
+ # merger = Spree::OrderMerger.new(initial_order)
38
+ # merger.merge!(order_to_merge)
39
+ # # order_to_merge is destroyed, initial order now contains the line items
40
+ # # of order_to_merge
41
+ #
42
+ # @api public
43
+ # @param [Spree::Order] other_order An order which will be merged in to the
44
+ # order the OrderMerger was initialized with.
45
+ # @param [Spree::User] user Associate the order the user specified. If not
46
+ # specified, the order user association will not be changed.
47
+ # @return [void]
48
+ def merge!(other_order, user = nil)
49
+ other_order.line_items.each do |other_order_line_item|
50
+ next unless other_order_line_item.currency == order.currency
51
+
52
+ current_line_item = find_matching_line_item(other_order_line_item)
53
+ handle_merge(current_line_item, other_order_line_item)
54
+ end
55
+
56
+ set_user(user)
57
+ persist_merge
58
+
59
+ # So that the destroy doesn't take out line items which may have been re-assigned
60
+ other_order.line_items.reload
61
+ other_order.destroy
62
+ end
63
+
64
+ private
65
+
66
+ # Retreive a matching line item from the existing order
67
+ #
68
+ # It will compare line items based on variants, and all line item
69
+ # comparison hooks on the order.
70
+ #
71
+ # @api private
72
+ # @param [Spree::LineItem] other_order_line_item The line item from
73
+ # `other_order` we are attempting to merge in.
74
+ # @return [Spree::LineItem] A matching line item from the order. nil if none
75
+ # exist.
76
+ def find_matching_line_item(other_order_line_item)
77
+ order.line_items.detect do |my_li|
78
+ my_li.variant == other_order_line_item.variant &&
79
+ order.line_item_comparison_hooks.all? do |hook|
80
+ order.send(hook, my_li, other_order_line_item.serializable_hash)
81
+ end
82
+ end
83
+ end
84
+
85
+ # Associate the user with the order
86
+ #
87
+ # @api private
88
+ # @param [Spree::User] user The user to associate with the order. If nil
89
+ # the order user association will remain the same. If the order is already
90
+ # associated with a user, it will not be changed.
91
+ # @return [void]
92
+ def set_user(user)
93
+ order.associate_user!(user) if !order.user && user
94
+ end
95
+
96
+ # Merge the `other_order_line_item` into `current_line_item`
97
+ #
98
+ # If `current_line_item` is nil, the `other_order_line_item` will be
99
+ # re-assigned to the `order`.
100
+ #
101
+ # If the merged line item can not be saved, an error will be added to
102
+ # `order`.
103
+ #
104
+ # @api private
105
+ # @param [Spree::LineItem] current_line_item The line item to be merged
106
+ # into. If nil, the `other_order_line_item` will be re-assigned.
107
+ # @param [Spree::LineItem] other_order_line_item The line item to merge in.
108
+ # @return [void]
109
+ def handle_merge(current_line_item, other_order_line_item)
110
+ if current_line_item
111
+ current_line_item.quantity += other_order_line_item.quantity
112
+ handle_error(current_line_item) unless current_line_item.save
113
+ else
114
+ other_order_line_item.order_id = order.id
115
+ handle_error(other_order_line_item) unless other_order_line_item.save
116
+ end
117
+ end
118
+
119
+ # Handle an error from saving the `line_item`
120
+ #
121
+ # This adds errors from the line item to the `errors[:base]` of the order.
122
+ #
123
+ # @api private
124
+ # @param [Spree::LineItem] line_item The line item which could not be saved
125
+ # @return [void]
126
+ def handle_error(line_item)
127
+ order.errors[:base] << line_item.errors.full_messages
128
+ end
129
+
130
+ # Save the order totals after merge
131
+ #
132
+ # It triggers the order updater to ensure that item counts and totals are
133
+ # up to date.
134
+ #
135
+ # @api private
136
+ # @return [void]
137
+ def persist_merge
138
+ updater.update_item_count
139
+ updater.update_item_total
140
+ updater.persist_totals
141
+ end
142
+ end
143
+ end
@@ -19,7 +19,7 @@ class Spree::OrderShipping
19
19
  stock_location: shipment.stock_location,
20
20
  address: shipment.address,
21
21
  shipping_method: shipment.shipping_method,
22
- shipped_at: Time.now,
22
+ shipped_at: Time.current,
23
23
  external_number: external_number,
24
24
  # TODO: Remove the `|| shipment.tracking` once Shipment#ship! is called by
25
25
  # OrderShipping#ship rather than vice versa
@@ -41,7 +41,7 @@ class Spree::OrderShipping
41
41
  # @param tracking_number An option tracking number.
42
42
  # @return The carton created.
43
43
  def ship(inventory_units:, stock_location:, address:, shipping_method:,
44
- shipped_at: Time.now, external_number: nil, tracking_number: nil, suppress_mailer: false)
44
+ shipped_at: Time.current, external_number: nil, tracking_number: nil, suppress_mailer: false)
45
45
 
46
46
  carton = nil
47
47
 
@@ -68,7 +68,7 @@ class Spree::OrderShipping
68
68
  # TODO: make OrderShipping#ship_shipment call Shipment#ship! rather than
69
69
  # having Shipment#ship! call OrderShipping#ship_shipment. We only really
70
70
  # need this `update_columns` for the specs, until we make that change.
71
- shipment.update_columns(state: 'shipped', shipped_at: Time.now)
71
+ shipment.update_columns(state: 'shipped', shipped_at: Time.current)
72
72
  end
73
73
  end
74
74