Class: Gemgento::Address

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/gemgento/address.rb

Overview

Author:

  • Gemgento LLC

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#address1Object

Returns the value of attribute address1.



11
12
13
# File 'app/models/gemgento/address.rb', line 11

def address1
  @address1
end

#address2Object

Returns the value of attribute address2.



11
12
13
# File 'app/models/gemgento/address.rb', line 11

def address2
  @address2
end

#address3Object

Returns the value of attribute address3.



11
12
13
# File 'app/models/gemgento/address.rb', line 11

def address3
  @address3
end

#copy_to_userObject

Returns the value of attribute copy_to_user.



11
12
13
# File 'app/models/gemgento/address.rb', line 11

def copy_to_user
  @copy_to_user
end

Instance Method Details

#as_json(options = nil) ⇒ String

Return the Address as JSON.

Parameters:

  • options (Hash) (defaults to: nil)

    an optional hash of options.

Returns:

  • (String)


35
36
37
38
39
40
41
42
43
# File 'app/models/gemgento/address.rb', line 35

def as_json(options = nil)
  result = super
  result['address1'] = self.address1
  result['address2'] = self.address2
  result['address3'] = self.address3
  result['country'] = self.country.name unless self.country.nil?
  result['region'] = self.region.code unless self.region.nil?
  return result
end

#copy_from_addressable_to_userGemgento::Address

Duplicate address from addressable user to user.

Returns:



48
49
50
51
52
53
54
55
56
57
# File 'app/models/gemgento/address.rb', line 48

def copy_from_addressable_to_user
  address = duplicate
  address.addressable = self.addressable.user
  address.is_billing = self.is_billing
  address.is_shipping = self.is_shipping
  address.sync_needed = true
  address.save

  return address
end

#copy_from_addressable_to_user?Boolean

Returns:

  • (Boolean)


60
61
62
# File 'app/models/gemgento/address.rb', line 60

def copy_from_addressable_to_user?
  self.copy_to_user.to_bool && self.addressable.try(:user).is_a?(Gemgento::User)
end

#create_magento_address?Boolean

Check if a Magento address can be created.

Returns:

  • (Boolean)


95
96
97
# File 'app/models/gemgento/address.rb', line 95

def create_magento_address?
  self.magento_id.nil? && self.is_addressable_user?
end

#duplicateGemgento::Address

Duplicate an address. Different from dup because it avoids unique magento attributes and includes country and region associations.

Returns:



74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'app/models/gemgento/address.rb', line 74

def duplicate
  address = self.dup
  address.region = self.region
  address.country = self.country
  address.magento_id = nil
  address.addressable = nil
  address.is_billing = false
  address.is_shipping = false
  address.increment_id = nil
  address.sync_needed = false

  return address
end

#is_addressable_user?Boolean

Returns:

  • (Boolean)


88
89
90
# File 'app/models/gemgento/address.rb', line 88

def is_addressable_user?
  self.addressable.is_a?(Gemgento::User)
end

#street=(value) ⇒ Object

Set the street attribute. Override required to explode the street into address lines.



65
66
67
68
# File 'app/models/gemgento/address.rb', line 65

def street=(value)
  super
  explode_street_address
end

#update_magento_address?Boolean

Check if a Magento address can be updated.

Returns:

  • (Boolean)


102
103
104
# File 'app/models/gemgento/address.rb', line 102

def update_magento_address?
  !self.magento_id.nil? && self.is_addressable_user?
end