Class: SolidusPaypalCommercePlatform::PaypalAddress
- Inherits:
-
Object
- Object
- SolidusPaypalCommercePlatform::PaypalAddress
- Defined in:
- app/models/solidus_paypal_commerce_platform/paypal_address.rb
Instance Attribute Summary collapse
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
Instance Method Summary collapse
-
#initialize(order) ⇒ PaypalAddress
constructor
A new instance of PaypalAddress.
- #simulate_update(paypal_address) ⇒ Object
- #update(paypal_address) ⇒ Object
Constructor Details
#initialize(order) ⇒ PaypalAddress
Returns a new instance of PaypalAddress.
7 8 9 |
# File 'app/models/solidus_paypal_commerce_platform/paypal_address.rb', line 7 def initialize(order) @order = order end |
Instance Attribute Details
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
5 6 7 |
# File 'app/models/solidus_paypal_commerce_platform/paypal_address.rb', line 5 def errors @errors end |
Instance Method Details
#simulate_update(paypal_address) ⇒ Object
11 12 13 14 15 16 17 18 19 |
# File 'app/models/solidus_paypal_commerce_platform/paypal_address.rb', line 11 def simulate_update(paypal_address) @order.update(ship_address: format_simulated_address(paypal_address)) return unless @order.ship_address.valid? @order.ensure_updated_shipments @order.email = "[email protected]" unless @order.email @order.contents.advance end |
#update(paypal_address) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'app/models/solidus_paypal_commerce_platform/paypal_address.rb', line 21 def update(paypal_address) formatted_address = address_attributes(paypal_address[:updated_address], paypal_address[:recipient]) new_address = @order.ship_address.dup || ::Spree::Address.new new_address.assign_attributes(formatted_address) add_email_to_order(paypal_address[:recipient]) unless @order.email if new_address.save @order.update(ship_address_id: new_address.id) # Also setting billing address if it doesn't already exist @order.update(bill_address_id: new_address.id) unless @order.bill_address else @errors = new_address.errors end new_address end |