Class: Magento::Customer

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

Overview

www.magentocommerce.com/wiki/doc/webservices-api/api/customer 100 Invalid customer data. Details in error message. 101 Invalid filters specified. Details in error message. 102 Customer does not exist. 103 Customer not deleted. Details in error message.

Instance Attribute Summary

Attributes inherited from Base

#attributes

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Base::ClassMethods

#api_path, #commit

Methods included from Base::InstanceMethods

#id, #id=, #initialize, #method_missing, #object_attributes=

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Magento::Base::InstanceMethods

Class Method Details

.allObject



102
103
104
# File 'lib/magento/customer.rb', line 102

def all
  list
end

.create(attributes) ⇒ Object

customer.create Create customer

Return: int

Arguments:

array customerData - cutomer data (email, firstname, lastname, etc…)



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

def create(attributes)
  id = commit("create", attributes)
  record = new(attributes)
  record.id = id
  record
end

.delete(*args) ⇒ Object

customer.delete Delete customer

Return: boolean

Arguments:

int customerId - customer ID.



83
84
85
# File 'lib/magento/customer.rb', line 83

def delete(*args)
  commit("delete", *args)
end

.find(find_type, options = {}) ⇒ Object



91
92
93
94
95
96
97
98
99
100
# File 'lib/magento/customer.rb', line 91

def find(find_type, options = {})
  filters = {}
  options.each_pair { |k, v| filters[k] = {:eq => v} }
  results = list(filters)
  if find_type == :first
    results.first
  else
    results
  end
end

.find_by_id(id) ⇒ Object



87
88
89
# File 'lib/magento/customer.rb', line 87

def find_by_id(id)
  info(id)
end

.info(*args) ⇒ Object

customer.info Retrieve customer data

Return: array

Arguments:

int customerId - Customer ID. array attributes | string attribute (optional depending on version) -

return only these attributes. Possible attributes are updated_at, increment_id, 
customer_id, created_at. The value, customer_id, is always returned.


57
58
59
# File 'lib/magento/customer.rb', line 57

def info(*args)
  new(commit("info", *args))
end

.list(*args) ⇒ Object

customer.list Retrieve customers

Return: array

Arguments:

array filters - filters by customer attributes (optional) filter list - “updated_at”, “website_id”, “increment_id”, “lastname”, “group_id”,

“firstname”, “created_in”, “customer_id”, “password_hash”, “store_id”, “email”, “created_at”

Note: password_hash will only match exactly with the same MD5 and salt as was used when Magento stored the value. If you try to match with an unsalted MD5 hash, or any salt other than what Magento used, it will not match. This is just a straight string comparison.



23
24
25
26
27
28
# File 'lib/magento/customer.rb', line 23

def list(*args)
  results = commit("list", *args)
  results.collect do |result|
    new(result)
  end
end

.update(*args) ⇒ Object

customer.update Update customer data

Return: boolean

Arguments:

int customerId - customer ID array customerData - customer data (email, firstname, etc…)



70
71
72
# File 'lib/magento/customer.rb', line 70

def update(*args)
  commit("update", *args)
end

Instance Method Details

#addressesObject



107
108
109
# File 'lib/magento/customer.rb', line 107

def addresses
  Magento::CustomerAddress.list(self.id)
end

#deleteObject



111
112
113
# File 'lib/magento/customer.rb', line 111

def delete
  self.class.delete(self.id)
end

#update_attribute(name, value) ⇒ Object



115
116
117
118
# File 'lib/magento/customer.rb', line 115

def update_attribute(name, value)
  @attributes[name] = value
  self.class.update(self.id, Hash[*[name.to_sym, value]])
end

#update_attributes(attrs) ⇒ Object



120
121
122
123
# File 'lib/magento/customer.rb', line 120

def update_attributes(attrs)
  attrs.each_pair { |k, v| @attributes[k] = v }
  self.class.update(self.id, attrs)
end