Class: SolidusBolt::Users::SyncAddressesService

Inherits:
BaseService
  • Object
show all
Defined in:
app/services/solidus_bolt/users/sync_addresses_service.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from BaseService

call

Constructor Details

#initialize(user:, access_token:) ⇒ SyncAddressesService

Returns a new instance of SyncAddressesService.



8
9
10
11
12
# File 'app/services/solidus_bolt/users/sync_addresses_service.rb', line 8

def initialize(user:, access_token:)
  @access_token = access_token
  @user = user
  super
end

Instance Attribute Details

#access_tokenObject (readonly)

Returns the value of attribute access_token.



6
7
8
# File 'app/services/solidus_bolt/users/sync_addresses_service.rb', line 6

def access_token
  @access_token
end

#userObject (readonly)

Returns the value of attribute user.



6
7
8
# File 'app/services/solidus_bolt/users/sync_addresses_service.rb', line 6

def user
  @user
end

Instance Method Details

#callObject



14
15
16
17
18
19
20
21
22
23
# File 'app/services/solidus_bolt/users/sync_addresses_service.rb', line 14

def call
  return if user.nil? || access_token.nil?

  bolt_addresses.each do |bolt_address|
    default = bolt_address['default']
    address = convert_to_solidus(bolt_address)
    user.save_in_address_book(address, default, :shipping)
    user.save_in_address_book(address, default, :billing)
  end
end