Sha256: 8bc15d1b65636caa4d8925716dfb8f0f4b494f3423851aea6cfcc93e1a8007e6

Contents?: true

Size: 798 Bytes

Versions: 2

Compression:

Stored size: 798 Bytes

Contents

module Workarea
  decorate Storefront::ApplicationController, with: :global_e do
    decorated do
      after_action :set_global_e_cart_id_cookie
    end

    def current_order
      @current_order ||= super.tap do |order|
        order.assign_attributes(
          currency: global_e_cookie["currencyCode"] || order.currency,
          shipping_country: Country[global_e_cookie["countryISO"]] || order.shipping_country
        )
      end
    end

    private

      def global_e_cookie
        @global_e_cookie ||= JSON.parse cookies[:GlobalE_Data] rescue {}
      end

      def set_global_e_cart_id_cookie
        if current_order.persisted?
          cookies["GlobalECartId"] = current_order.global_e_token
        else
          cookies.delete "GlobalECartId"
        end
      end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
workarea-global_e-1.3.0 app/controllers/workarea/storefront/application_controller.decorator
workarea-global_e-1.2.1 app/controllers/workarea/storefront/application_controller.decorator