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,42 @@
1
+ module Spree
2
+ class OrderUpdateAttributes
3
+ # @param order [Order] existing (persisted) order
4
+ # @param attributes [Hash] attributes which are assigned to the new order.
5
+ # These attributes should already have been filtered.
6
+ # * :payments_attributes attributes
7
+ def initialize(order, attributes, request_env: nil)
8
+ @order = order
9
+ @attributes = attributes.dup
10
+ @payments_attributes = @attributes.delete(:payments_attributes) || []
11
+ @request_env = request_env
12
+ end
13
+
14
+ # Assign the attributes to the order and save the order
15
+ # @return true if saved, otherwise false and errors will be set on the order
16
+ def apply
17
+ assign_order_attributes
18
+ assign_payments_attributes
19
+
20
+ if order.save
21
+ order.set_shipments_cost if order.shipments.any?
22
+ true
23
+ else
24
+ false
25
+ end
26
+ end
27
+
28
+ private
29
+
30
+ attr_reader :attributes, :payments_attributes, :order
31
+
32
+ def assign_order_attributes
33
+ order.assign_attributes attributes
34
+ end
35
+
36
+ def assign_payments_attributes
37
+ @payments_attributes.each do |payment_attributes|
38
+ PaymentCreate.new(order, payment_attributes, request_env: @request_env).build
39
+ end
40
+ end
41
+ end
42
+ end
@@ -109,7 +109,7 @@ module Spree
109
109
  shipment_total: order.shipment_total,
110
110
  promo_total: order.promo_total,
111
111
  total: order.total,
112
- updated_at: Time.now,
112
+ updated_at: Time.current,
113
113
  )
114
114
  end
115
115
 
@@ -32,13 +32,13 @@ module Spree
32
32
  # invalidate previously entered payments
33
33
  after_create :invalidate_old_payments
34
34
 
35
- attr_accessor :source_attributes, :request_env
35
+ attr_accessor :source_attributes
36
+ after_initialize :apply_source_attributes
36
37
 
37
- after_initialize :build_source
38
+ attr_accessor :request_env
38
39
 
39
40
  validates :amount, numericality: true
40
41
  validates :source, presence: true, if: :source_required?
41
- validates :payment_method, presence: true
42
42
 
43
43
  default_scope -> { order(:created_at) }
44
44
 
@@ -149,13 +149,19 @@ module Spree
149
149
  # this payment's payment method and associates it correctly.
150
150
  #
151
151
  # @see https://github.com/spree/spree/issues/981
152
- def build_source
152
+ #
153
+ # TODO: Move this into upcoming CartUpdate class
154
+ def apply_source_attributes
153
155
  return unless new_record?
154
- if source_attributes.present? && source.blank? && payment_method.try(:payment_source_class)
155
- self.source = payment_method.payment_source_class.new(source_attributes)
156
- self.source.payment_method_id = payment_method.id
157
- self.source.user_id = self.order.user_id if self.order
158
- end
156
+ return if source_attributes.blank?
157
+
158
+ ActiveSupport::Deprecation.warn(<<WARN.squish)
159
+ Building payment sources by assigning source_attributes on payments is
160
+ deprecated. Instead use either the PaymentCreate class or the
161
+ OrderUpdateAttributes class.
162
+ WARN
163
+
164
+ PaymentCreate.new(order, {source_attributes: source_attributes}, payment: self, request_env: request_env).build
159
165
  end
160
166
 
161
167
  # @return [Array<String>] the actions available on this payment
@@ -255,7 +261,7 @@ module Spree
255
261
  # Necessary because some payment gateways will refuse payments with
256
262
  # duplicate IDs. We *were* using the Order number, but that's set once and
257
263
  # is unchanging. What we need is a unique identifier on a per-payment basis,
258
- # and this is it. Related to #1998.
264
+ # and this is it. Related to https://github.com/spree/spree/issues/1998.
259
265
  # See https://github.com/spree/spree/issues/1998#issuecomment-12869105
260
266
  def set_unique_identifier
261
267
  begin
@@ -0,0 +1,68 @@
1
+ module Spree
2
+ # Service object for creating new payments on an Order
3
+ class PaymentCreate
4
+ # @param order [Order] The order for the new payment
5
+ # @param attributes [Hash] attributes which are assigned to the new payment
6
+ # * :payment_method_id Id of payment method used for this payment
7
+ # * :source_attributes Attributes used to build the source of this payment. Usually a {CreditCard}
8
+ # * :existing_card_id (Integer) The id of an existing {CreditCard} object to use
9
+ # @param request_env [Hash] rack env of user creating the payment
10
+ # @param payment [Payment] Internal use only. Instead of making a new payment, change the attributes for an existing one.
11
+ def initialize(order, attributes, payment: nil, request_env: {})
12
+ @order = order
13
+ @payment = payment
14
+ @attributes = attributes.dup.with_indifferent_access
15
+ @source_attributes = @attributes.delete(:source_attributes) || {}
16
+ @request_env = request_env
17
+ end
18
+
19
+ # Build the new Payment
20
+ # @return [Payment] a new (unpersisted) Payment
21
+ def build
22
+ @payment ||= order.payments.new
23
+ @payment.request_env = @request_env if @request_env
24
+ @payment.attributes = @attributes
25
+
26
+ if source_attributes[:existing_card_id].present?
27
+ build_existing_card
28
+ else
29
+ build_source
30
+ end
31
+
32
+ @payment
33
+ end
34
+
35
+ private
36
+
37
+ attr_reader :order, :payment, :attributes, :source_attributes
38
+
39
+ def build_source
40
+ payment_method = payment.payment_method
41
+ if source_attributes.present? && payment_method.try(:payment_source_class)
42
+ payment.source = payment_method.payment_source_class.new(source_attributes)
43
+ payment.source.payment_method_id = payment_method.id
44
+ payment.source.user_id = order.user_id if order
45
+ end
46
+ end
47
+
48
+ def build_existing_card
49
+ credit_card = available_cards.find(source_attributes[:existing_card_id])
50
+
51
+ # FIXME: does this work?
52
+ if source_attributes[:verification_value]
53
+ credit_card.verification_value = source_attributes[:verification_value]
54
+ end
55
+
56
+ payment.source = credit_card
57
+ payment.payment_method_id = credit_card.payment_method_id
58
+ end
59
+
60
+ def available_cards
61
+ if user_id = order.user_id
62
+ CreditCard.where(user_id: user_id)
63
+ else
64
+ CreditCard.none
65
+ end
66
+ end
67
+ end
68
+ end
@@ -2,7 +2,6 @@ module Spree
2
2
  class PaymentMethod < Spree::Base
3
3
  acts_as_paranoid
4
4
  DISPLAY = [:both, :front_end, :back_end]
5
- default_scope -> { where(deleted_at: nil) }
6
5
 
7
6
  validates :name, presence: true
8
7
 
@@ -1,5 +1,5 @@
1
1
  class Spree::Preference < Spree::Base
2
2
  serialize :value
3
3
 
4
- validates :key, presence: true, uniqueness: true
4
+ validates :key, presence: true, uniqueness: { allow_blank: true }
5
5
  end
@@ -1,7 +1,7 @@
1
1
  module Spree
2
2
  class Price < Spree::Base
3
3
  acts_as_paranoid
4
- belongs_to :variant, class_name: 'Spree::Variant', inverse_of: :prices, touch: true
4
+ belongs_to :variant, -> { with_deleted }, class_name: 'Spree::Variant', touch: true
5
5
 
6
6
  validate :check_price
7
7
  validates :amount, numericality: { greater_than_or_equal_to: 0 }, allow_nil: true
@@ -31,13 +31,6 @@ module Spree
31
31
  self[:amount] = Spree::LocalizedNumber.parse(price)
32
32
  end
33
33
 
34
- # @note This returns the variant regardless of whether it was soft
35
- # deleted.
36
- # @return [Spree::Variant] this price's variant.
37
- def variant
38
- Spree::Variant.unscoped { super }
39
- end
40
-
41
34
  private
42
35
 
43
36
  def check_price
@@ -32,9 +32,10 @@ module Spree
32
32
  belongs_to :shipping_category, class_name: 'Spree::ShippingCategory', inverse_of: :products
33
33
 
34
34
  has_one :master,
35
- -> { where is_master: true },
35
+ -> { where(is_master: true).with_deleted },
36
36
  inverse_of: :product,
37
- class_name: 'Spree::Variant'
37
+ class_name: 'Spree::Variant',
38
+ autosave: true
38
39
 
39
40
  has_many :variants,
40
41
  -> { where(is_master: false).order(:position) },
@@ -70,7 +71,6 @@ module Spree
70
71
 
71
72
  has_many :variant_images, -> { order(:position) }, source: :images, through: :variants_including_master
72
73
 
73
- after_create :set_master_variant_defaults
74
74
  after_create :add_associations_from_prototype
75
75
  after_create :build_variants_from_option_values_hash, if: :option_values_hash
76
76
 
@@ -78,9 +78,7 @@ module Spree
78
78
 
79
79
  after_initialize :ensure_master
80
80
 
81
- after_save :save_master
82
- after_save :run_touch_callbacks, if: :anything_changed?
83
- after_save :reset_nested_changes
81
+ after_save :run_touch_callbacks, if: :changed?
84
82
  after_touch :touch_taxons
85
83
 
86
84
  before_validation :normalize_slug, on: :update
@@ -231,7 +229,7 @@ module Spree
231
229
  # @param property_value [String] the property value
232
230
  def set_property(property_name, property_value)
233
231
  ActiveRecord::Base.transaction do
234
- # Works around spree_i18n #301
232
+ # Works around spree_i18n https://github.com/spree/spree/issues/301
235
233
  property = Property.create_with(presentation: property_name).find_or_create_by(name: property_name)
236
234
  product_property = ProductProperty.where(product: self, property: property).first_or_initialize
237
235
  product_property.value = property_value
@@ -257,13 +255,6 @@ module Spree
257
255
  end
258
256
  end
259
257
 
260
- # Override so if the master variant is deleted, we can still find it.
261
- #
262
- # @return [Spree::Variant] the master variant
263
- def master
264
- super || variants_including_master.with_deleted.find_by(is_master: true)
265
- end
266
-
267
258
  # Image that can be used for the product.
268
259
  #
269
260
  # Will first search for images on the product, then those belonging to the
@@ -320,7 +311,7 @@ module Spree
320
311
 
321
312
  def ensure_master
322
313
  return unless new_record?
323
- self.master ||= build_master
314
+ find_or_build_master
324
315
  end
325
316
 
326
317
  def normalize_slug
@@ -328,44 +319,18 @@ module Spree
328
319
  end
329
320
 
330
321
  def punch_slug
331
- update_column :slug, "#{Time.now.to_i}_#{slug}" # punch slug with date prefix to allow reuse of original
332
- end
333
-
334
- def anything_changed?
335
- changed? || @nested_changes
322
+ update_column :slug, "#{Time.current.to_i}_#{slug}" # punch slug with date prefix to allow reuse of original
336
323
  end
337
324
 
338
- def reset_nested_changes
339
- @nested_changes = false
340
- end
341
-
342
- # there's a weird quirk with the delegate stuff that does not automatically save the delegate object
343
- # when saving so we force a save using a hook
344
- # Fix for issue #5306
345
- def save_master
346
- if master && (master.changed? || master.new_record? || (master.default_price && (master.default_price.changed? || master.default_price.new_record?)))
347
- master.save!
348
- @nested_changes = true
349
- end
350
- end
351
-
352
- # If the master cannot be saved, the Product object will get its errors
353
- # and will be destroyed
325
+ # If the master is invalid, the Product object will be assigned its errors
354
326
  def validate_master
355
- # We call master.default_price here to ensure price is initialized.
356
- # Required to avoid Variant#check_price validation failing on create.
357
- unless master.default_price && master.valid?
327
+ unless master.valid?
358
328
  master.errors.each do |att, error|
359
329
  self.errors.add(att, error)
360
330
  end
361
331
  end
362
332
  end
363
333
 
364
- # ensures the master variant is flagged as such
365
- def set_master_variant_defaults
366
- master.is_master = true
367
- end
368
-
369
334
  # Try building a slug based on the following fields in increasing order of specificity.
370
335
  def slug_candidates
371
336
  [
@@ -168,12 +168,12 @@ module Spree
168
168
  end
169
169
 
170
170
  add_search_scope :not_deleted do
171
- where("#{Product.quoted_table_name}.deleted_at IS NULL or #{Product.quoted_table_name}.deleted_at >= ?", Time.zone.now)
171
+ where("#{Product.quoted_table_name}.deleted_at IS NULL or #{Product.quoted_table_name}.deleted_at >= ?", Time.current)
172
172
  end
173
173
 
174
174
  # Can't use add_search_scope for this as it needs a default argument
175
175
  def self.available(available_on = nil, currency = nil)
176
- joins(:master => :prices).where("#{Product.quoted_table_name}.available_on <= ?", available_on || Time.now)
176
+ joins(:master => :prices).where("#{Product.quoted_table_name}.available_on <= ?", available_on || Time.current)
177
177
  end
178
178
  search_scopes << :available
179
179
 
@@ -211,27 +211,28 @@ module Spree
211
211
  end
212
212
  end
213
213
 
214
- private
214
+ class << self
215
+ private
215
216
 
216
- def self.price_table_name
217
+ def price_table_name
217
218
  Price.quoted_table_name
218
219
  end
219
220
 
220
221
  # specifically avoid having an order for taxon search (conflicts with main order)
221
- def self.prepare_taxon_conditions(taxons)
222
+ def prepare_taxon_conditions(taxons)
222
223
  ids = taxons.map { |taxon| taxon.self_and_descendants.pluck(:id) }.flatten.uniq
223
224
  joins(:taxons).where("#{Taxon.table_name}.id" => ids)
224
225
  end
225
226
 
226
227
  # Produce an array of keywords for use in scopes.
227
228
  # Always return array with at least an empty string to avoid SQL errors
228
- def self.prepare_words(words)
229
+ def prepare_words(words)
229
230
  return [''] if words.blank?
230
231
  a = words.split(/[,\s]/).map(&:strip)
231
232
  a.any? ? a : ['']
232
233
  end
233
234
 
234
- def self.get_taxons(*ids_or_records_or_names)
235
+ def get_taxons(*ids_or_records_or_names)
235
236
  taxons = Taxon.table_name
236
237
  ids_or_records_or_names.flatten.map { |t|
237
238
  case t
@@ -244,4 +245,5 @@ module Spree
244
245
  }.compact.flatten.uniq
245
246
  end
246
247
  end
248
+ end
247
249
  end
@@ -30,7 +30,7 @@ module Spree
30
30
  user.
31
31
  orders.
32
32
  complete.
33
- where(Spree::Order.arel_table[:completed_at].lt(order.completed_at || Time.now)).
33
+ where(Spree::Order.arel_table[:completed_at].lt(order.completed_at || Time.current)).
34
34
  count
35
35
  end
36
36
 
@@ -2,7 +2,8 @@ module Spree
2
2
  class Promotion
3
3
  module Rules
4
4
  class Taxon < PromotionRule
5
- has_and_belongs_to_many :taxons, class_name: '::Spree::Taxon', join_table: 'spree_taxons_promotion_rules', foreign_key: 'promotion_rule_id'
5
+ has_many :promotion_rule_taxons, class_name: 'Spree::PromotionRuleTaxon', foreign_key: :promotion_rule_id
6
+ has_many :taxons, through: :promotion_rule_taxons, class_name: 'Spree::Taxon'
6
7
 
7
8
  MATCH_POLICIES = %w(any all)
8
9
  preference :match_policy, default: MATCH_POLICIES.first
@@ -20,6 +20,7 @@ module Spree
20
20
  end
21
21
  end
22
22
 
23
+ private
23
24
  # @return The best promotion from this set of adjustments.
24
25
  def best_promotion_adjustment
25
26
  @best_promotion_adjustment ||= @adjustments.select(&:eligible?).min_by do |a|
@@ -2,7 +2,7 @@ class Spree::PromotionCode < Spree::Base
2
2
  belongs_to :promotion, inverse_of: :codes
3
3
  has_many :adjustments
4
4
 
5
- validates :value, presence: true, uniqueness: true
5
+ validates :value, presence: true, uniqueness: { allow_blank: true }
6
6
  validates :promotion, presence: true
7
7
 
8
8
  before_save :downcase_value
@@ -0,0 +1,6 @@
1
+ module Spree
2
+ class PromotionRuleTaxon < Spree::Base
3
+ belongs_to :promotion_rule
4
+ belongs_to :taxon
5
+ end
6
+ end
@@ -1,6 +1,7 @@
1
1
  module Spree
2
2
  class Property < Spree::Base
3
- has_and_belongs_to_many :prototypes, join_table: 'spree_properties_prototypes'
3
+ has_many :property_prototypes
4
+ has_many :prototypes, through: :property_prototypes
4
5
 
5
6
  has_many :product_properties, dependent: :delete_all, inverse_of: :property
6
7
  has_many :products, through: :product_properties
@@ -0,0 +1,6 @@
1
+ module Spree
2
+ class PropertyPrototype < Spree::Base
3
+ belongs_to :prototype
4
+ belongs_to :property
5
+ end
6
+ end