Class: DelayedSubscriberUpdate

Inherits:
Struct
  • Object
show all
Defined in:
lib/delayed_subscriber_update.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#order_idObject

Returns the value of attribute order_id

Returns:

  • (Object)

    the current value of order_id



1
2
3
# File 'lib/delayed_subscriber_update.rb', line 1

def order_id
  @order_id
end

#tokenObject

Returns the value of attribute token

Returns:

  • (Object)

    the current value of token



1
2
3
# File 'lib/delayed_subscriber_update.rb', line 1

def token
  @token
end

Instance Method Details

#performObject



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/delayed_subscriber_update.rb', line 3

def perform
  order = Spree::Order.find(order_id)

  if order.user.nil?
    email=order.email
    user_id=''
    else
    user=order.user.reload #reload the user to be sure we have the most uptodate record
    email=user.email
    user_id=order.user.id
  end

    if email.length > 0
      begin
          address=order.bill_address
      fields={          # these fields neeb be created in bronto, otherwise they won't get updated.
          :customer_id => user_id,
          :firstname => address.firstname,
          :lastname => address.lastname,
          :address1 => address.address1,
          :address2 => address.address2,
          :phone_home => address.phone,
          :postal_code => address.zipcode,
          :city => address.city,
          :state_province => (address.state_id.nil? ? address.state_name.to_s : address.state.name),
          :country => address.country.name
          }
      contact = BrontoIntegration::Contact.new(token)
      contacts=contact.set_up(email,fields)
      rescue => exception
        # should just send email to operations and go ahead
        #raise exception
      end
    end
end