Class: Magenthor::Customer
Instance Attribute Summary collapse
-
#confirmation ⇒ Object
Returns the value of attribute confirmation.
-
#created_at ⇒ Object
readonly
Returns the value of attribute created_at.
-
#created_in ⇒ Object
Returns the value of attribute created_in.
-
#customer_id ⇒ Object
readonly
Returns the value of attribute customer_id.
-
#dob ⇒ Object
Returns the value of attribute dob.
-
#email ⇒ Object
Returns the value of attribute email.
-
#firstname ⇒ Object
Returns the value of attribute firstname.
-
#gender ⇒ Object
Returns the value of attribute gender.
-
#group_id ⇒ Object
Returns the value of attribute group_id.
-
#increment_id ⇒ Object
readonly
Returns the value of attribute increment_id.
-
#lastname ⇒ Object
Returns the value of attribute lastname.
-
#middlename ⇒ Object
Returns the value of attribute middlename.
-
#password ⇒ Object
Returns the value of attribute password.
-
#password_hash ⇒ Object
readonly
Returns the value of attribute password_hash.
-
#prefix ⇒ Object
Returns the value of attribute prefix.
-
#store_id ⇒ Object
Returns the value of attribute store_id.
-
#suffix ⇒ Object
Returns the value of attribute suffix.
-
#taxvat ⇒ Object
Returns the value of attribute taxvat.
-
#updated_at ⇒ Object
readonly
Returns the value of attribute updated_at.
-
#website_id ⇒ Object
Returns the value of attribute website_id.
Class Method Summary collapse
-
.find(customer_id) ⇒ Magenthor::Customer, FalseClass
Find a specific Customer by Magento ID.
-
.groups ⇒ Array, FalseClass
Get the list of all Magento customer groups.
-
.list(filters = []) ⇒ Array<Magenthor::Customer>, FalseClass
Retrieve the list of all Magento customers with or without filters.
Instance Method Summary collapse
-
#create ⇒ TrueClass, FalseClass
Create on Magento the local Customer.
-
#delete ⇒ TrueClass, FalseClass
Remove from Magento the local Customer.
-
#initialize(params = {}) ⇒ Magenthor::Customer
constructor
Initialize a new Customer entity.
-
#update ⇒ TrueClass, FalseClass
Save on Magento the updates on the local Customer.
Methods inherited from Base
Constructor Details
#initialize(params = {}) ⇒ Magenthor::Customer
Initialize a new Customer entity
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
#confirmation ⇒ Object
Returns the value of attribute confirmation.
5 6 7 |
# File 'lib/magenthor/customer.rb', line 5 def confirmation @confirmation end |
#created_at ⇒ Object
Returns the value of attribute created_at.
8 9 10 |
# File 'lib/magenthor/customer.rb', line 8 def created_at @created_at end |
#created_in ⇒ Object
Returns the value of attribute created_in.
5 6 7 |
# File 'lib/magenthor/customer.rb', line 5 def created_in @created_in end |
#customer_id ⇒ Object
Returns the value of attribute customer_id.
8 9 10 |
# File 'lib/magenthor/customer.rb', line 8 def customer_id @customer_id end |
#dob ⇒ Object
Returns the value of attribute dob.
5 6 7 |
# File 'lib/magenthor/customer.rb', line 5 def dob @dob end |
#email ⇒ Object
Returns the value of attribute email.
5 6 7 |
# File 'lib/magenthor/customer.rb', line 5 def email @email end |
#firstname ⇒ Object
Returns the value of attribute firstname.
5 6 7 |
# File 'lib/magenthor/customer.rb', line 5 def firstname @firstname end |
#gender ⇒ Object
Returns the value of attribute gender.
5 6 7 |
# File 'lib/magenthor/customer.rb', line 5 def gender @gender end |
#group_id ⇒ Object
Returns the value of attribute group_id.
5 6 7 |
# File 'lib/magenthor/customer.rb', line 5 def group_id @group_id end |
#increment_id ⇒ Object
Returns the value of attribute increment_id.
5 6 7 |
# File 'lib/magenthor/customer.rb', line 5 def increment_id @increment_id end |
#lastname ⇒ Object
Returns the value of attribute lastname.
5 6 7 |
# File 'lib/magenthor/customer.rb', line 5 def lastname @lastname end |
#middlename ⇒ Object
Returns the value of attribute middlename.
5 6 7 |
# File 'lib/magenthor/customer.rb', line 5 def middlename @middlename end |
#password ⇒ Object
Returns the value of attribute password.
5 6 7 |
# File 'lib/magenthor/customer.rb', line 5 def password @password end |
#password_hash ⇒ Object
Returns the value of attribute password_hash.
8 9 10 |
# File 'lib/magenthor/customer.rb', line 8 def password_hash @password_hash end |
#prefix ⇒ Object
Returns the value of attribute prefix.
5 6 7 |
# File 'lib/magenthor/customer.rb', line 5 def prefix @prefix end |
#store_id ⇒ Object
Returns the value of attribute store_id.
5 6 7 |
# File 'lib/magenthor/customer.rb', line 5 def store_id @store_id end |
#suffix ⇒ Object
Returns the value of attribute suffix.
5 6 7 |
# File 'lib/magenthor/customer.rb', line 5 def suffix @suffix end |
#taxvat ⇒ Object
Returns the value of attribute taxvat.
5 6 7 |
# File 'lib/magenthor/customer.rb', line 5 def taxvat @taxvat end |
#updated_at ⇒ Object
Returns the value of attribute updated_at.
8 9 10 |
# File 'lib/magenthor/customer.rb', line 8 def updated_at @updated_at end |
#website_id ⇒ Object
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
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 |
.groups ⇒ Array, FalseClass
Get the list of all Magento customer groups
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
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
#create ⇒ TrueClass, FalseClass
Create on Magento the local Customer
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 |
#delete ⇒ TrueClass, FalseClass
Remove from Magento the local Customer
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 |
#update ⇒ TrueClass, FalseClass
Save on Magento the updates on the local Customer
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 |