Sha256: a1fdab78bb890a103aebbe1db27981e5c9d115fe43feaa4a7b0c2ebac746fd03

Contents?: true

Size: 835 Bytes

Versions: 5

Compression:

Stored size: 835 Bytes

Contents

module Workarea
  module MailChimp
    module Ecommerce
      class SaveOrder
        include Sidekiq::Worker
        include Sidekiq::CallbacksWorker

        sidekiq_options(
          enqueue_on: { Workarea::Order => [:place] },
          unique: :until_executing
        )

        def perform(id)
          order = Workarea::Order.find(id)
          mc_order = Workarea::MailChimp::Order.new(order)
          store_id = Workarea::MailChimp.config.default_store[:id]

          MailChimp.request.ecommerce.stores(store_id).orders.create(body: mc_order.to_h)

          order.set(exported_to_mail_chimp_at: Time.current)

          delete_cart(id, store_id)
        end

        def delete_cart(id, store_id)
          MailChimp.request.ecommerce.stores(store_id).carts(id).delete rescue nil
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
workarea-mail_chimp-3.1.0 app/workers/workarea/mail_chimp/ecommerce/save_order.rb
workarea-mail_chimp-3.0.5 app/workers/workarea/mail_chimp/ecommerce/save_order.rb
workarea-mail_chimp-3.0.4 app/workers/workarea/mail_chimp/ecommerce/save_order.rb
workarea-mail_chimp-3.0.3 app/workers/workarea/mail_chimp/ecommerce/save_order.rb
workarea-mail_chimp-3.0.2 app/workers/workarea/mail_chimp/ecommerce/save_order.rb