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.
- checksums.yaml +4 -4
- data/app/assets/images/logo/solidus_logo.png +0 -0
- data/app/helpers/spree/base_helper.rb +2 -3
- data/app/models/concerns/spree/adjustment_source.rb +1 -1
- data/app/models/concerns/spree/default_price.rb +3 -1
- data/app/models/concerns/spree/named_type.rb +1 -1
- data/app/models/concerns/spree/user_methods.rb +10 -0
- data/app/models/spree/adjustment.rb +1 -1
- data/app/models/spree/adjustment_reason.rb +2 -4
- data/app/models/spree/app_configuration.rb +36 -0
- data/app/models/spree/base.rb +10 -1
- data/app/models/spree/calculator/tiered_percent.rb +2 -1
- data/app/models/spree/classification.rb +1 -1
- data/app/models/spree/country.rb +3 -3
- data/app/models/spree/credit_card.rb +2 -2
- data/app/models/spree/customer_return.rb +3 -4
- data/app/models/spree/inventory_unit.rb +13 -24
- data/app/models/spree/item_adjustments.rb +5 -5
- data/app/models/spree/line_item.rb +6 -15
- data/app/models/spree/log_entry.rb +1 -1
- data/app/models/spree/option_type.rb +4 -2
- data/app/models/spree/option_type_prototype.rb +6 -0
- data/app/models/spree/option_value.rb +1 -1
- data/app/models/spree/order.rb +18 -63
- data/app/models/spree/order/checkout.rb +4 -2
- data/app/models/spree/order_cancellations.rb +52 -1
- data/app/models/spree/order_contents.rb +1 -1
- data/app/models/spree/order_merger.rb +143 -0
- data/app/models/spree/order_shipping.rb +3 -3
- data/app/models/spree/order_update_attributes.rb +42 -0
- data/app/models/spree/order_updater.rb +1 -1
- data/app/models/spree/payment.rb +16 -10
- data/app/models/spree/payment_create.rb +68 -0
- data/app/models/spree/payment_method.rb +0 -1
- data/app/models/spree/preference.rb +1 -1
- data/app/models/spree/price.rb +1 -8
- data/app/models/spree/product.rb +9 -44
- data/app/models/spree/product/scopes.rb +9 -7
- data/app/models/spree/promotion/rules/nth_order.rb +1 -1
- data/app/models/spree/promotion/rules/taxon.rb +2 -1
- data/app/models/spree/promotion_chooser.rb +1 -0
- data/app/models/spree/promotion_code.rb +1 -1
- data/app/models/spree/promotion_rule_taxon.rb +6 -0
- data/app/models/spree/property.rb +2 -1
- data/app/models/spree/property_prototype.rb +6 -0
- data/app/models/spree/prototype.rb +6 -2
- data/app/models/spree/reimbursement.rb +10 -0
- data/app/models/spree/return_item/eligibility_validator/time_since_purchase.rb +1 -1
- data/app/models/spree/return_reason.rb +1 -7
- data/app/models/spree/role_user.rb +3 -5
- data/app/models/spree/shipment.rb +6 -11
- data/app/models/spree/shipping_method.rb +1 -7
- data/app/models/spree/shipping_rate.rb +3 -14
- data/app/models/spree/stock/coordinator.rb +48 -4
- data/app/models/spree/stock/estimator.rb +3 -6
- data/app/models/spree/stock/packer.rb +18 -2
- data/app/models/spree/stock/shipping_rate_selector.rb +16 -0
- data/app/models/spree/stock/shipping_rate_sorter.rb +16 -0
- data/app/models/spree/stock_item.rb +19 -15
- data/app/models/spree/stock_location.rb +2 -12
- data/app/models/spree/stock_transfer.rb +3 -3
- data/app/models/spree/store_credit.rb +2 -2
- data/app/models/spree/tax_category.rb +3 -2
- data/app/models/spree/tax_rate.rb +7 -14
- data/app/models/spree/taxon.rb +4 -1
- data/app/models/spree/taxonomy.rb +1 -1
- data/app/models/spree/transfer_item.rb +2 -2
- data/app/models/spree/unit_cancel.rb +2 -0
- data/app/models/spree/variant.rb +9 -14
- data/app/models/spree/zone.rb +6 -0
- data/app/models/spree/zone_member.rb +1 -4
- data/app/views/spree/order_mailer/cancel_email.text.erb +0 -0
- data/config/locales/en.yml +7 -5
- data/db/default/spree/countries.rb +1 -1
- data/db/default/spree/zones.rb +5 -11
- data/db/migrate/20130213191427_create_default_stock.rb +1 -1
- data/db/migrate/20130306181701_add_address_fields_to_stock_location.rb +1 -1
- data/db/migrate/20140309033438_create_store_from_preferences.rb +5 -2
- data/db/migrate/20141009204607_add_store_id_to_orders.rb +6 -2
- data/db/migrate/20141215235502_remove_extra_products_slug_index.rb +5 -0
- data/db/migrate/20141217215630_update_product_slug_index.rb +6 -0
- data/db/migrate/20150225205344_move_promotion_code_to_promotion_code_value.rb +2 -2
- data/db/migrate/20150609093816_increase_scale_on_pre_tax_amounts.rb +10 -0
- data/db/migrate/20151117063249_convert_habtm_to_hmt_for_properties_prototypes.rb +17 -0
- data/db/migrate/20151124062500_convert_habtm_to_hmt_for_option_type_prototypes.rb +17 -0
- data/db/migrate/20151126063028_convert_habtm_to_hmt_for_taxons_promotion_rules.rb +15 -0
- data/db/migrate/20151219020209_add_stock_item_unique_index.rb +9 -0
- data/lib/generators/spree/dummy/dummy_generator.rb +1 -1
- data/lib/generators/spree/dummy/templates/rails/database.yml +1 -1
- data/lib/generators/spree/install/templates/config/initializers/spree.rb +25 -1
- data/lib/generators/spree/install/templates/vendor/assets/javascripts/spree/backend/all.js +3 -0
- data/lib/generators/spree/install/templates/vendor/assets/javascripts/spree/frontend/all.js +3 -0
- data/lib/generators/spree/install/templates/vendor/assets/stylesheets/spree/backend/all.css +3 -0
- data/lib/generators/spree/install/templates/vendor/assets/stylesheets/spree/frontend/all.css +3 -0
- data/lib/spree/core/controller_helpers/common.rb +1 -1
- data/lib/spree/core/controller_helpers/order.rb +1 -1
- data/lib/spree/core/controller_helpers/payment_parameters.rb +104 -5
- data/lib/spree/core/engine.rb +3 -2
- data/lib/spree/core/stock_configuration.rb +11 -0
- data/lib/spree/core/unreturned_item_charger.rb +4 -4
- data/lib/spree/core/version.rb +9 -1
- data/lib/spree/permission_sets/restricted_stock_transfer_management.rb +15 -24
- data/lib/spree/permitted_attributes.rb +3 -1
- data/lib/spree/testing_support/capybara_ext.rb +14 -40
- data/lib/spree/testing_support/factories.rb +0 -15
- data/lib/spree/testing_support/factories/address_factory.rb +3 -0
- data/lib/spree/testing_support/factories/adjustment_factory.rb +9 -1
- data/lib/spree/testing_support/factories/carton_factory.rb +4 -1
- data/lib/spree/testing_support/factories/customer_return_factory.rb +4 -0
- data/lib/spree/testing_support/factories/inventory_unit_factory.rb +5 -0
- data/lib/spree/testing_support/factories/line_item_factory.rb +3 -0
- data/lib/spree/testing_support/factories/option_type_factory.rb +6 -0
- data/lib/spree/testing_support/factories/{options_factory.rb → option_value_factory.rb} +0 -5
- data/lib/spree/testing_support/factories/order_factory.rb +13 -3
- data/lib/spree/testing_support/factories/order_promotion_factory.rb +3 -0
- data/lib/spree/testing_support/factories/payment_factory.rb +13 -5
- data/lib/spree/testing_support/factories/price_factory.rb +2 -0
- data/lib/spree/testing_support/factories/product_factory.rb +7 -1
- data/lib/spree/testing_support/factories/product_option_type_factory.rb +3 -0
- data/lib/spree/testing_support/factories/product_property_factory.rb +3 -0
- data/lib/spree/testing_support/factories/promotion_code_factory.rb +3 -0
- data/lib/spree/testing_support/factories/promotion_factory.rb +3 -0
- data/lib/spree/testing_support/factories/prototype_factory.rb +2 -0
- data/lib/spree/testing_support/factories/refund_factory.rb +10 -5
- data/lib/spree/testing_support/factories/refund_reason_factory.rb +5 -0
- data/lib/spree/testing_support/factories/reimbursement_factory.rb +2 -0
- data/lib/spree/testing_support/factories/return_authorization_factory.rb +4 -4
- data/lib/spree/testing_support/factories/return_item_factory.rb +4 -0
- data/lib/spree/testing_support/factories/return_reason_factory.rb +5 -0
- data/lib/spree/testing_support/factories/shipment_factory.rb +6 -1
- data/lib/spree/testing_support/factories/shipping_method_factory.rb +22 -10
- data/lib/spree/testing_support/factories/shipping_rate_factory.rb +9 -0
- data/lib/spree/testing_support/factories/state_factory.rb +2 -0
- data/lib/spree/testing_support/factories/stock_item_factory.rb +4 -1
- data/lib/spree/testing_support/factories/stock_location_factory.rb +8 -0
- data/lib/spree/testing_support/factories/stock_movement_factory.rb +2 -0
- data/lib/spree/testing_support/factories/{stock_factory.rb → stock_package_factory.rb} +5 -10
- data/lib/spree/testing_support/factories/stock_packer_factory.rb +13 -0
- data/lib/spree/testing_support/factories/stock_transfer_factory.rb +2 -2
- data/lib/spree/testing_support/factories/store_credit_event_factory.rb +4 -1
- data/lib/spree/testing_support/factories/store_credit_factory.rb +10 -6
- data/lib/spree/testing_support/factories/tax_category_factory.rb +2 -0
- data/lib/spree/testing_support/factories/tax_rate_factory.rb +4 -0
- data/lib/spree/testing_support/factories/taxon_factory.rb +2 -0
- data/lib/spree/testing_support/factories/user_factory.rb +6 -2
- data/lib/spree/testing_support/factories/variant_factory.rb +5 -0
- data/lib/spree/testing_support/factories/variant_property_rule_condition_factory.rb +3 -0
- data/lib/spree/testing_support/factories/variant_property_rule_factory.rb +4 -0
- data/lib/spree/testing_support/factories/variant_property_rule_value_factory.rb +3 -0
- data/lib/spree/testing_support/factories/zone_factory.rb +6 -0
- data/lib/spree/testing_support/sequences.rb +9 -0
- data/lib/tasks/exchanges.rake +4 -3
- data/lib/tasks/migrations/copy_shipped_shipments_to_cartons.rake +2 -2
- data/solidus_core.gemspec +4 -5
- data/spec/helpers/base_helper_spec.rb +6 -6
- data/spec/helpers/order_helper_spec.rb +1 -1
- data/spec/helpers/products_helper_spec.rb +2 -2
- data/spec/helpers/taxons_helper_spec.rb +1 -1
- data/spec/lib/spree/core/controller_helpers/payment_parameters_spec.rb +107 -7
- data/spec/lib/spree/core/importer/order_spec.rb +1 -1
- data/spec/lib/spree/core/stock_configuration_spec.rb +16 -0
- data/spec/lib/spree/core/testing_support/factories/address_factory_spec.rb +24 -0
- data/spec/lib/spree/core/testing_support/factories/adjustment_factory_spec.rb +18 -0
- data/spec/lib/spree/core/testing_support/factories/adjustment_reason_factory_spec.rb +12 -0
- data/spec/lib/spree/core/testing_support/factories/calculator_factory_spec.rb +42 -0
- data/spec/lib/spree/core/testing_support/factories/carton_factory_spec.rb +12 -0
- data/spec/lib/spree/core/testing_support/factories/country_factory_spec.rb +12 -0
- data/spec/lib/spree/core/testing_support/factories/credit_card_factory_spec.rb +12 -0
- data/spec/lib/spree/core/testing_support/factories/customer_return_factory_spec.rb +28 -0
- data/spec/lib/spree/core/testing_support/factories/image_factory_spec.rb +12 -0
- data/spec/lib/spree/core/testing_support/factories/inventory_unit_factory_spec.rb +12 -0
- data/spec/lib/spree/core/testing_support/factories/line_item_factory_spec.rb +12 -0
- data/spec/lib/spree/core/testing_support/factories/option_type_factory_spec.rb +12 -0
- data/spec/lib/spree/core/testing_support/factories/option_value_factory_spec.rb +12 -0
- data/spec/lib/spree/core/testing_support/factories/order_factory_spec.rb +49 -0
- data/spec/lib/spree/core/testing_support/factories/order_promotion_factory_spec.rb +12 -0
- data/spec/lib/spree/core/testing_support/factories/payment_factory_spec.rb +24 -0
- data/spec/lib/spree/core/testing_support/factories/payment_method_factory_spec.rb +30 -0
- data/spec/lib/spree/core/testing_support/factories/price_factory_spec.rb +12 -0
- data/spec/lib/spree/core/testing_support/factories/product_factory_spec.rb +30 -0
- data/spec/lib/spree/core/testing_support/factories/product_option_type_factory_spec.rb +12 -0
- data/spec/lib/spree/core/testing_support/factories/product_property_factory_spec.rb +12 -0
- data/spec/lib/spree/core/testing_support/factories/promotion_category_factory_spec.rb +12 -0
- data/spec/lib/spree/core/testing_support/factories/promotion_code_factory_spec.rb +12 -0
- data/spec/lib/spree/core/testing_support/factories/promotion_factory_spec.rb +30 -0
- data/spec/lib/spree/core/testing_support/factories/property_factory_spec.rb +12 -0
- data/spec/lib/spree/core/testing_support/factories/prototype_factory_spec.rb +12 -0
- data/spec/lib/spree/core/testing_support/factories/refund_factory_spec.rb +12 -0
- data/spec/lib/spree/core/testing_support/factories/refund_reason_factory_spec.rb +12 -0
- data/spec/lib/spree/core/testing_support/factories/reimbursement_factory_spec.rb +12 -0
- data/spec/lib/spree/core/testing_support/factories/reimbursement_type_factory_spec.rb +12 -0
- data/spec/lib/spree/core/testing_support/factories/return_authorization_factory_spec.rb +12 -0
- data/spec/lib/spree/core/testing_support/factories/return_item_factory_spec.rb +18 -0
- data/spec/lib/spree/core/testing_support/factories/return_reason_factory_spec.rb +12 -0
- data/spec/lib/spree/core/testing_support/factories/role_factory_spec.rb +18 -0
- data/spec/lib/spree/core/testing_support/factories/shipment_factory_spec.rb +12 -0
- data/spec/lib/spree/core/testing_support/factories/shipping_category_factory_spec.rb +12 -0
- data/spec/lib/spree/core/testing_support/factories/shipping_method_factory_spec.rb +28 -0
- data/spec/lib/spree/core/testing_support/factories/shipping_rate_factory_spec.rb +12 -0
- data/spec/lib/spree/core/testing_support/factories/state_factory_spec.rb +12 -0
- data/spec/lib/spree/core/testing_support/factories/stock_item_factory_spec.rb +12 -0
- data/spec/lib/spree/core/testing_support/factories/stock_location_factory_spec.rb +24 -0
- data/spec/lib/spree/core/testing_support/factories/stock_movement_factory_spec.rb +12 -0
- data/spec/lib/spree/core/testing_support/factories/stock_package_factory_spec.rb +26 -0
- data/spec/lib/spree/core/testing_support/factories/stock_packer_factory_spec.rb +16 -0
- data/spec/lib/spree/core/testing_support/factories/stock_transfer_factory_spec.rb +12 -0
- data/spec/lib/spree/core/testing_support/factories/store_credit_category_factory_spec.rb +12 -0
- data/spec/lib/spree/core/testing_support/factories/store_credit_event_factory_spec.rb +42 -0
- data/spec/lib/spree/core/testing_support/factories/store_credit_factory_spec.rb +12 -0
- data/spec/lib/spree/core/testing_support/factories/store_credit_type_factory_spec.rb +18 -0
- data/spec/lib/spree/core/testing_support/factories/store_credit_update_reason_factory_spec.rb +12 -0
- data/spec/lib/spree/core/testing_support/factories/store_factory_spec.rb +12 -0
- data/spec/lib/spree/core/testing_support/factories/tax_category_factory_spec.rb +12 -0
- data/spec/lib/spree/core/testing_support/factories/tax_rate_factory_spec.rb +12 -0
- data/spec/lib/spree/core/testing_support/factories/taxon_factory_spec.rb +12 -0
- data/spec/lib/spree/core/testing_support/factories/taxonomy_factory_spec.rb +12 -0
- data/spec/lib/spree/core/testing_support/factories/tracker_factory_spec.rb +12 -0
- data/spec/lib/spree/core/testing_support/factories/user_factory_spec.rb +22 -0
- data/spec/lib/spree/core/testing_support/factories/variant_factory_spec.rb +36 -0
- data/spec/lib/spree/core/testing_support/factories/variant_property_rule_condition_factory_spec.rb +12 -0
- data/spec/lib/spree/core/testing_support/factories/variant_property_rule_factory_spec.rb +12 -0
- data/spec/lib/spree/core/testing_support/factories/variant_property_rule_value_factory_spec.rb +12 -0
- data/spec/lib/spree/core/testing_support/factories/zone_factory_spec.rb +18 -0
- data/spec/lib/spree/core/unreturned_item_charger_spec.rb +1 -1
- data/spec/lib/spree/core/version_spec.rb +17 -0
- data/spec/lib/spree/money_spec.rb +1 -1
- data/spec/mailers/carton_mailer_spec.rb +1 -1
- data/spec/mailers/order_mailer_spec.rb +1 -1
- data/spec/mailers/reimbursement_mailer_spec.rb +1 -3
- data/spec/mailers/test_mailer_spec.rb +1 -3
- data/spec/models/spree/address_spec.rb +4 -4
- data/spec/models/spree/adjustment_reason_spec.rb +1 -3
- data/spec/models/spree/app_configuration_spec.rb +4 -0
- data/spec/models/spree/calculator/price_sack_spec.rb +3 -3
- data/spec/models/spree/calculator/shipping/price_sack_spec.rb +3 -3
- data/spec/models/spree/calculator/tiered_percent_spec.rb +86 -10
- data/spec/models/spree/carton_spec.rb +3 -1
- data/spec/models/spree/classification_spec.rb +3 -3
- data/spec/models/spree/credit_card_spec.rb +16 -16
- data/spec/models/spree/customer_return_spec.rb +1 -1
- data/spec/models/spree/gateway/bogus_simple.rb +1 -1
- data/spec/models/spree/inventory_unit_spec.rb +3 -3
- data/spec/models/spree/item_adjustments_spec.rb +1 -1
- data/spec/models/spree/line_item_spec.rb +2 -2
- data/spec/models/spree/option_type_spec.rb +2 -2
- data/spec/models/spree/option_value_spec.rb +2 -2
- data/spec/models/spree/order/callbacks_spec.rb +1 -1
- data/spec/models/spree/order/checkout_spec.rb +16 -11
- data/spec/models/spree/order/payment_spec.rb +24 -22
- data/spec/models/spree/order/state_machine_spec.rb +1 -1
- data/spec/models/spree/order/validations_spec.rb +1 -1
- data/spec/models/spree/order_cancellations_spec.rb +63 -0
- data/spec/models/spree/order_contents_spec.rb +1 -1
- data/spec/models/spree/order_merger_spec.rb +133 -0
- data/spec/models/spree/order_spec.rb +39 -159
- data/spec/models/spree/order_update_attributes_spec.rb +82 -0
- data/spec/models/spree/order_updater_spec.rb +6 -4
- data/spec/models/spree/payment_create_spec.rb +131 -0
- data/spec/models/spree/payment_spec.rb +130 -48
- data/spec/models/spree/permission_sets/restricted_stock_transfer_management_spec.rb +91 -33
- data/spec/models/spree/product_filter_spec.rb +3 -3
- data/spec/models/spree/product_spec.rb +80 -26
- data/spec/models/spree/promotion/actions/create_adjustment_spec.rb +1 -1
- data/spec/models/spree/promotion/actions/create_item_adjustments_spec.rb +2 -2
- data/spec/models/spree/promotion/rules/nth_order_spec.rb +1 -1
- data/spec/models/spree/promotion/rules/user_spec.rb +2 -2
- data/spec/models/spree/promotion_handler/coupon_spec.rb +2 -2
- data/spec/models/spree/promotion_spec.rb +18 -18
- data/spec/models/spree/reimbursement_spec.rb +22 -0
- data/spec/models/spree/return_item_spec.rb +2 -2
- data/spec/models/spree/shipment_spec.rb +28 -12
- data/spec/models/spree/shipping_method_spec.rb +2 -2
- data/spec/models/spree/shipping_rate_spec.rb +3 -3
- data/spec/models/spree/stock/coordinator_spec.rb +5 -0
- data/spec/models/spree/stock/estimator_spec.rb +35 -1
- data/spec/models/spree/stock/package_spec.rb +1 -1
- data/spec/models/spree/stock/packer_spec.rb +2 -3
- data/spec/models/spree/stock/shipping_rate_selector_spec.rb +16 -0
- data/spec/models/spree/stock/shipping_rate_sorter_spec.rb +16 -0
- data/spec/models/spree/stock_item_spec.rb +5 -7
- data/spec/models/spree/stock_location_spec.rb +5 -9
- data/spec/models/spree/stock_transfer_spec.rb +33 -13
- data/spec/models/spree/store_credit_event_spec.rb +1 -1
- data/spec/models/spree/store_credit_spec.rb +1 -1
- data/spec/models/spree/tax_rate_spec.rb +381 -120
- data/spec/models/spree/taxon_spec.rb +3 -3
- data/spec/models/spree/transfer_item_spec.rb +4 -4
- data/spec/models/spree/unit_cancel_spec.rb +1 -1
- data/spec/models/spree/variant_spec.rb +3 -3
- data/spec/models/spree/zone_spec.rb +35 -1
- data/spec/support/concerns/working_factories.rb +9 -0
- data/vendor/assets/javascripts/jquery-migrate-1.0.0.js +498 -0
- data/vendor/assets/javascripts/jquery.payment.js +231 -80
- metadata +103 -27
- data/app/models/spree/order/currency_updater.rb +0 -40
- 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
|
data/app/models/spree/payment.rb
CHANGED
@@ -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
|
35
|
+
attr_accessor :source_attributes
|
36
|
+
after_initialize :apply_source_attributes
|
36
37
|
|
37
|
-
|
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
|
-
|
152
|
+
#
|
153
|
+
# TODO: Move this into upcoming CartUpdate class
|
154
|
+
def apply_source_attributes
|
153
155
|
return unless new_record?
|
154
|
-
if source_attributes.
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
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
|
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
|
data/app/models/spree/price.rb
CHANGED
@@ -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',
|
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
|
data/app/models/spree/product.rb
CHANGED
@@ -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
|
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 :
|
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
|
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
|
-
|
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.
|
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
|
-
|
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
|
-
|
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.
|
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.
|
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
|
-
|
214
|
+
class << self
|
215
|
+
private
|
215
216
|
|
216
|
-
def
|
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
|
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
|
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
|
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
|
@@ -2,7 +2,8 @@ module Spree
|
|
2
2
|
class Promotion
|
3
3
|
module Rules
|
4
4
|
class Taxon < PromotionRule
|
5
|
-
|
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
|
@@ -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
|
@@ -1,6 +1,7 @@
|
|
1
1
|
module Spree
|
2
2
|
class Property < Spree::Base
|
3
|
-
|
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
|