Sha256: e3f511943c2e0b986d80e086ca32643a64bc73ea37c723a9cc2c7a71147ee1c5

Contents?: true

Size: 1.31 KB

Versions: 1

Compression:

Stored size: 1.31 KB

Contents

module Harpiya
  class StoreController < Harpiya::BaseController
    include Harpiya::Core::ControllerHelpers::Order
    include Harpiya::LocaleUrls

    helper 'harpiya/locale'
    helper 'harpiya/currency'

    skip_before_action :verify_authenticity_token, only: :ensure_cart, raise: false

    before_action :redirect_to_default_locale

    def account_link
      render partial: 'harpiya/shared/link_to_account'
      fresh_when(etag: [try_harpiya_current_user, I18n.locale])
    end

    def cart_link
      render partial: 'harpiya/shared/link_to_cart'
      fresh_when(etag: [simple_current_order, I18n.locale])
    end

    def api_tokens
      render json: {
        order_token: simple_current_order&.token,
        oauth_token: current_oauth_token&.token
      }
    end

    def ensure_cart
      render json: current_order(create_order_if_necessary: true) # force creation of order if doesn't exists
    end

    protected

    def config_locale
      Harpiya::Frontend::Config[:locale]
    end

    def store_etag
      [
        current_store,
        current_currency,
        I18n.locale,
        try_harpiya_current_user.present?,
        try_harpiya_current_user.try(:has_harpiya_role?, 'admin')
      ].compact
    end

    def store_last_modified
      (current_store.updated_at || Time.current).utc
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
harpiya_frontend-4.3.0.alpha app/controllers/harpiya/store_controller.rb