Class: DelayedSend

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#emailObject

Returns the value of attribute email

Returns:

  • (Object)

    the current value of email



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

def email
  @email
end

#html_viewObject

Returns the value of attribute html_view

Returns:

  • (Object)

    the current value of html_view



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

def html_view
  @html_view
end

#message_nameObject

Returns the value of attribute message_name

Returns:

  • (Object)

    the current value of message_name



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

def message_name
  @message_name
end

#order_idObject

Returns the value of attribute order_id

Returns:

  • (Object)

    the current value of order_id



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

def order_id
  @order_id
end

#plain_viewObject

Returns the value of attribute plain_view

Returns:

  • (Object)

    the current value of plain_view



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

def plain_view
  @plain_view
end

#store_codeObject

Returns the value of attribute store_code

Returns:

  • (Object)

    the current value of store_code



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

def store_code
  @store_code
end

Instance Method Details

#performObject



2
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
# File 'lib/delayed_send.rb', line 2

def perform
  return if email.blank?
  #store_code ||= 'default'
  order = Spree::Order.find(order_id)
  token= Spree::BrontoConfiguration.[store_code]['token']
  from_email= order.store.mail_from_address
  from_name= Spree::BrontoConfiguration.[store_code]['from_name']
  reply_email= order.store.mail_from_address
  email_options={:fromEmail =>from_email,:fromName => from_name, :replyEmail => reply_email}


  view = ActionView::Base.new(Rails::Application::Configuration.new(Rails.root).paths["app/mailers/spree"])
  view.view_paths<<File.join(File.dirname(__FILE__), '../app/mailers/spree')

  attributes = {:First_Name => order.bill_address.firstname,
               :Last_name => order.bill_address.lastname}

  attributes[:SENDTIME__CONTENT1] = view.render(plain_view, :order => order) unless plain_view.nil?
  attributes[:SENDTIME__CONTENT2] = (view.render(html_view, :order => order)).gsub(/\n/,'').html_safe unless html_view.nil?

  begin
    communication = BrontoIntegration::Communication.new(token)
    communication.trigger_delivery_by_id(message_name,email,'transactional','html',attributes,email_options)

  rescue => exception
    begin    #handle the transactional contact in case the message is not approved for transactional.
      contact = BrontoIntegration::Contact.new(token)
      contact.update_status(email,'active')
      communication.trigger_delivery_by_id(message_name,email,'triggered','html',attributes,email_options)
    rescue => exception
      raise exception
    end
  end
end