Packages
shopifex
1.1.0
2.4.0
2.3.0
2.2.2
2.2.1
2.2.0
2.1.20
2.1.19
2.1.18
2.1.17
2.1.16
2.1.15
2.1.14
2.1.13
2.1.12
2.1.11
2.1.10
2.1.9
2.1.8
2.1.7
2.1.6
2.1.5
2.1.4
2.1.3
2.1.2
2.1.1
2.1.0
2.0.1
2.0.0
1.1.1
1.1.0
1.0.1
1.0.0
0.6.2
0.6.1
0.6.0
0.5.7
0.5.6
0.5.5
0.5.4
0.5.3
0.5.2
0.5.1
0.5.0
0.4.1
0.4.0
0.3.6
0.3.5
0.3.4
0.3.3
0.3.2
0.3.1
0.3.0
0.2.1
0.2.0
0.1.5
0.1.4
0.1.3
0.1.2
0.1.1
0.1.0
Phoenix boilerplate for Shopify Embedded App SDK
Current section
Files
Jump to
Current section
Files
lib/shopifex/plug/fetch_flash.ex
defmodule Shopifex.Plug.FetchFlash do
import Plug.Conn
@moduledoc """
Fetches the flash in a way which maintains the session within Shopify iFrame
"""
def init(options) do
# initialize options
options
end
def call(conn, _) do
session_flash = Plug.Conn.get_session(conn, "phoenix_flash")
conn = persist_flash(conn, session_flash || %{})
register_before_send(conn, fn conn ->
flash = conn.private.phoenix_flash
flash_size = map_size(flash)
cond do
is_nil(session_flash) and flash_size == 0 ->
conn
flash_size > 0 and conn.status in 300..308 ->
Plug.Conn.put_session(conn, "phoenix_flash", flash)
flash_size > 0 and conn.status in 200..299 ->
flash = Map.take(flash, ["shop_url", "shop"])
Plug.Conn.put_session(conn, "phoenix_flash", flash)
true ->
Plug.Conn.delete_session(conn, "phoenix_flash")
end
end)
end
defp persist_flash(conn, value) do
Plug.Conn.put_private(conn, :phoenix_flash, value)
end
end