class Magenthor::Customer

Attributes

confirmation[RW]
created_at[RW]
created_in[RW]
customer_id[RW]
dob[RW]
email[RW]
firstname[RW]
gender[RW]
group_id[RW]
increment_id[RW]
lastname[RW]
middlename[RW]
password[RW]
password_hash[RW]
prefix[RW]
store_id[RW]
suffix[RW]
taxvat[RW]
updated_at[RW]
website_id[RW]

Public Class Methods

find(customer_id) click to toggle source

Find a specific Customer by Magento ID

@param customer_id [String, Integer] the id of the customer to retrieve @return [Magenthor::Customer, FalseClass] the customer entity or false if not found

# File lib/magenthor/customer.rb, line 108
def find customer_id
    response = commit('customer.info', [customer_id])
    new(response) unless response == false
end
groups() click to toggle source

Get the list of all Magento customer groups

@return [Array, FalseClass] the list of all customer groups or false

# File lib/magenthor/customer.rb, line 139
def groups
    commit('customer_group.list',  [])
end
list(filters = []) click to toggle source

Retrieve the list of all Magento customers with or without filters

@param filters [Array] the filters by customer attributes @return [Array<Magenthor::Customer>, FalseClass] the list of all customers as Customer entities or false

# 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
new(params = {}) click to toggle source

Initialize a new Customer entity

@param params [Hash] the to save in the instance on initialization @return [Magenthor::Customer] a new instance of Customer

# 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

Public Instance Methods

create() click to toggle source

Create on Magento the local Customer

@return [TrueClass, FalseClass] true if successful or false

# 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
delete() click to toggle source

Remove from Magento the local Customer

@return [TrueClass, FalseClass] true if successful or false

# 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
update() click to toggle source

Save on Magento the updates on the local Customer

@return [TrueClass, FalseClass] true if successful or false

# 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