Class: Magento::Customer

Inherits:
Model
  • Object
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

Methods included from ModelParser

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_idObject



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

.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

#fullnameObject



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