Class: Gemgento::API::SOAP::Customer::Address

Inherits:
Object
  • Object
show all
Defined in:
lib/gemgento/api/soap/customer/address.rb

Class Method Summary collapse

Class Method Details

.create(address) ⇒ Gemgento::MagentoResponse

Create a Customer Address in Magento.

Parameters:

Returns:



61
62
63
64
65
66
67
# File 'lib/gemgento/api/soap/customer/address.rb', line 61

def self.create(address)
  message = {
      customer_id: address.addressable.magento_id,
      address_data: compose_address_data(address)
  }
  MagentoApi.create_call(:customer_address_create, message)
end

.delete(address_id) ⇒ Gemgento::MagentoResponse

Delete a Customer Address in Magento.



84
85
86
# File 'lib/gemgento/api/soap/customer/address.rb', line 84

def self.delete(address_id)
  MagentoApi.create_call(:customer_address_update, {address_id: address_id})
end

.fetch(user) ⇒ Void

Fetch Customer Addresses for a User and sync them to Gemgento.

Parameters:

Returns:

  • (Void)


20
21
22
23
24
25
26
27
28
# File 'lib/gemgento/api/soap/customer/address.rb', line 20

def self.fetch(user)
  response = list(user.magento_id)

  if response.success? && response.body[:result][:item]
    response.body[:result][:item].each do |address|
      sync_magento_to_local(address, user)
    end
  end
end

.fetch_allVoid

Fetch Customer Addresses for all Gemgento Users from Magento.

Returns:

  • (Void)


10
11
12
13
14
# File 'lib/gemgento/api/soap/customer/address.rb', line 10

def self.fetch_all
  User.all.each do |user|
    fetch(user)
  end
end

.info(address_id) ⇒ Gemgento::MagentoReponse

Get Magento Address data.

Parameters:

  • address_id (Integer)

    Magento Address id.

Returns:

  • (Gemgento::MagentoReponse)


52
53
54
55
# File 'lib/gemgento/api/soap/customer/address.rb', line 52

def self.info(address_id)
  MagentoApi.create_call(:customer_address_list, { address_id: address_id })
  # response.body[:result][:info]
end

.list(customer_id) ⇒ Gemgento::MagentoResponse

Get a list of all Magento Addresses for a specific customer.

Parameters:

  • customer_id (Integer)

    Magento Customer id.

Returns:



34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/gemgento/api/soap/customer/address.rb', line 34

def self.list(customer_id)
  response = MagentoApi.create_call(:customer_address_list, {customer_id: customer_id})

  if response.success?
    if response.body[:result][:item].nil?
      response.body[:result][:item] = []
    elsif !response.body[:result][:item].is_a? Array
      response.body[:result][:item] = [response.body[:result][:item]]
    end
  end

  return response
end

.update(address) ⇒ Gemgento::MagentoResponse

Update a Customer Address in Magento.

Parameters:

Returns:



73
74
75
76
77
78
79
# File 'lib/gemgento/api/soap/customer/address.rb', line 73

def self.update(address)
  message = {
      address_id: address.magento_id,
      address_data: compose_address_data(address)
  }
  MagentoApi.create_call(:customer_address_update, message)
end