Class: Magenthor::Customer

Inherits:
Base
  • Object
show all
Defined in:
lib/magenthor/customer.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

setup

Constructor Details

#initialize(params = {}) ⇒ Magenthor::Customer

Initialize a new Customer entity

Parameters:

  • params (Hash) (defaults to: {})

    the to save in the instance on initialization



19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/magenthor/customer.rb', line 19

def initialize params = {}
    methods.grep(/\w=$/).each do |m|
        send(m, nil)
    end
    params.each do |k, v|
        send("#{k}=", v) if respond_to? "#{k}="
    end
    self.customer_id = params["customer_id"]
    self.increment_id = params["increment_id"]
    self.created_at = params["created_at"]
    self.updated_at = params["updated_at"]
    self.password_hash = params["password_hash"]
    
end

Instance Attribute Details

#confirmationObject

Returns the value of attribute confirmation.



5
6
7
# File 'lib/magenthor/customer.rb', line 5

def confirmation
  @confirmation
end

#created_atObject

Returns the value of attribute created_at.



8
9
10
# File 'lib/magenthor/customer.rb', line 8

def created_at
  @created_at
end

#created_inObject

Returns the value of attribute created_in.



5
6
7
# File 'lib/magenthor/customer.rb', line 5

def created_in
  @created_in
end

#customer_idObject

Returns the value of attribute customer_id.



8
9
10
# File 'lib/magenthor/customer.rb', line 8

def customer_id
  @customer_id
end

#dobObject

Returns the value of attribute dob.



5
6
7
# File 'lib/magenthor/customer.rb', line 5

def dob
  @dob
end

#emailObject

Returns the value of attribute email.



5
6
7
# File 'lib/magenthor/customer.rb', line 5

def email
  @email
end

#firstnameObject

Returns the value of attribute firstname.



5
6
7
# File 'lib/magenthor/customer.rb', line 5

def firstname
  @firstname
end

#genderObject

Returns the value of attribute gender.



5
6
7
# File 'lib/magenthor/customer.rb', line 5

def gender
  @gender
end

#group_idObject

Returns the value of attribute group_id.



5
6
7
# File 'lib/magenthor/customer.rb', line 5

def group_id
  @group_id
end

#increment_idObject

Returns the value of attribute increment_id.



5
6
7
# File 'lib/magenthor/customer.rb', line 5

def increment_id
  @increment_id
end

#lastnameObject

Returns the value of attribute lastname.



5
6
7
# File 'lib/magenthor/customer.rb', line 5

def lastname
  @lastname
end

#middlenameObject

Returns the value of attribute middlename.



5
6
7
# File 'lib/magenthor/customer.rb', line 5

def middlename
  @middlename
end

#passwordObject

Returns the value of attribute password.



5
6
7
# File 'lib/magenthor/customer.rb', line 5

def password
  @password
end

#password_hashObject

Returns the value of attribute password_hash.



8
9
10
# File 'lib/magenthor/customer.rb', line 8

def password_hash
  @password_hash
end

#prefixObject

Returns the value of attribute prefix.



5
6
7
# File 'lib/magenthor/customer.rb', line 5

def prefix
  @prefix
end

#store_idObject

Returns the value of attribute store_id.



5
6
7
# File 'lib/magenthor/customer.rb', line 5

def store_id
  @store_id
end

#suffixObject

Returns the value of attribute suffix.



5
6
7
# File 'lib/magenthor/customer.rb', line 5

def suffix
  @suffix
end

#taxvatObject

Returns the value of attribute taxvat.



5
6
7
# File 'lib/magenthor/customer.rb', line 5

def taxvat
  @taxvat
end

#updated_atObject

Returns the value of attribute updated_at.



8
9
10
# File 'lib/magenthor/customer.rb', line 8

def updated_at
  @updated_at
end

#website_idObject

Returns the value of attribute website_id.



5
6
7
# File 'lib/magenthor/customer.rb', line 5

def website_id
  @website_id
end

Class Method Details

.find(customer_id) ⇒ Magenthor::Customer, FalseClass

Find a specific Customer by Magento ID

Parameters:

  • customer_id (String, Integer)

    the id of the customer to retrieve

Returns:



108
109
110
111
# File 'lib/magenthor/customer.rb', line 108

def find customer_id
    response = commit('customer.info', [customer_id])
    new(response) unless response == false
end

.groupsArray, FalseClass

Get the list of all Magento customer groups

Returns:

  • (Array, FalseClass)

    the list of all customer groups or false



139
140
141
# File 'lib/magenthor/customer.rb', line 139

def groups
    commit('customer_group.list',  [])
end

.list(filters = []) ⇒ Array<Magenthor::Customer>, FalseClass

Retrieve the list of all Magento customers with or without filters

Parameters:

  • filters (Array) (defaults to: [])

    the filters by customer attributes

Returns:

  • (Array<Magenthor::Customer>, FalseClass)

    the list of all customers as Customer entities or false



94
95
96
97
98
99
100
101
102
# File 'lib/magenthor/customer.rb', line 94

def list filters = []
    response = commit('customer.list', filters)
    return false if response == false
    customers = []
    response.each do |r|
        customers << find(r["customer_id"])
    end
    return customers
end

Instance Method Details

#createTrueClass, FalseClass

Create on Magento the local Customer

Returns:

  • (TrueClass, FalseClass)

    true if successful or false



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/magenthor/customer.rb', line 48

def create
    attributes = {}
    methods.grep(/\w=$/).each do |m|
        attributes[m.to_s.gsub('=','')] = send(m.to_s.gsub('=',''))
    end
    response = self.class.commit('customer.create', [attributes])
    return false if response == false

    obj = self.class.find(response)
    methods.grep(/\w=$/).each do |m|
        send(m, obj.send(m.to_s.gsub('=','')))
    end
    self.customer_id = obj.customer_id
    self.increment_id = obj.increment_id
    self.created_at = obj.created_at
    self.updated_at = obj.updated_at
    self.password_hash = obj.password_hash

    return true
end

#deleteTrueClass, FalseClass

Remove from Magento the local Customer

Returns:

  • (TrueClass, FalseClass)

    true if successful or false



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/magenthor/customer.rb', line 72

def delete
    response = self.class.commit('customer.delete', [self.customer_id])
    return false if response == false

    methods.grep(/\w=$/).each do |m|
        send(m, nil)
    end
    self.customer_id = nil
    self.increment_id = nil
    self.created_at = nil
    self.updated_at = nil
    self.password_hash = nil

    return true
end

#updateTrueClass, FalseClass

Save on Magento the updates on the local Customer

Returns:

  • (TrueClass, FalseClass)

    true if successful or false



37
38
39
40
41
42
43
# File 'lib/magenthor/customer.rb', line 37

def update
    attributes = {}
    methods.grep(/\w=$/).each do |m|
        attributes[m.to_s.gsub('=','')] = send(m.to_s.gsub('=',''))
    end
    self.class.commit('customer.update', [self.customer_id, attributes])
end