Class: Magento::Customer
- Inherits:
-
Model
- Object
- Model
- Magento::Customer
show all
- Defined in:
- lib/magento/customer.rb
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Model
api_resource, #delete, delete, entity_name, #id, #save
included, #to_h
Class Method Details
.create(attributes) ⇒ Object
25
26
27
28
29
30
31
32
33
|
# File 'lib/magento/customer.rb', line 25
def create(attributes)
attributes.transform_keys!(&:to_sym)
password = attributes.delete :password
hash = request.post("customers", {
customer: attributes,
password: password
}).parse
build(hash)
end
|
.find(id) ⇒ Object
41
42
43
44
|
# File 'lib/magento/customer.rb', line 41
def find(id)
hash = request.get("customers/#{id}").parse
build(hash)
end
|
.find_by_id ⇒ Object
17
|
# File 'lib/magento/customer.rb', line 17
alias_method :find_by_id, :find
|
.find_by_token(token) ⇒ Object
35
36
37
38
39
|
# File 'lib/magento/customer.rb', line 35
def find_by_token(token)
user_request = Request.new(config: Magento.configuration.copy_with(token: token))
customer_hash = user_request.get('customers/me').parse
build(customer_hash)
end
|
.login(username, password) ⇒ Object
Log in to a user account
Example:
Magento::Customer.login('[email protected]', '123456')
53
54
55
56
57
58
|
# File 'lib/magento/customer.rb', line 53
def login(username, password)
request.post("integration/customer/token", {
username: username,
password: password
})
end
|
.reset_password(email:, reset_token:, new_password:) ⇒ Object
Reset a user’s password
Example:
Magento::Customer.reset_password(
email: '[email protected]',
reset_token: 'mEKMTciuhPfWkQ3zHTCLIJNC',
new_password: '123456'
)
71
72
73
74
75
76
77
|
# File 'lib/magento/customer.rb', line 71
def reset_password(email:, reset_token:, new_password:)
request.post("customers/resetPassword", {
email: email,
reset_token: reset_token,
new_password: new_password
}).parse
end
|
.update(id, attributes) ⇒ Object
19
20
21
22
23
|
# File 'lib/magento/customer.rb', line 19
def update(id, attributes)
hash = request.put("customers/#{id}", { customer: attributes }).parse
block_given? ? yield(hash) : build(hash)
end
|
Instance Method Details
#fullname ⇒ Object
5
6
7
|
# File 'lib/magento/customer.rb', line 5
def fullname
"#{@firstname} #{@lastname}"
end
|
#update(attributes) ⇒ Object
9
10
11
12
13
14
|
# File 'lib/magento/customer.rb', line 9
def update(attributes)
raise "id not present" if @id.nil?
attributes.each { |key, value| send("#{key}=", value) }
save
end
|