class Magenthor::Customer
Attributes
Public Class Methods
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
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
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
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 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
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
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