Skip to content

Instantly share code, notes, and snippets.

Fabian Zitter Ninigi

  • Tokyo, Japan
Block or report user

Report or block Ninigi

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View hide_and_show_paypal.js
function toggleCountryPayment() {
var isPayPal = function(el) {
return el.querySelectorAll(".radio__label__primary")[0] && el.querySelectorAll(".radio__label__primary")[0].textContent.trim() === "PayPal";
}
var shipToElement = document.querySelector("address.address") && document.querySelector("address.address").firstChild;
if (shipToElement && shipToElement.data.indexOf("Malaysia") > -1) {
var els = document.querySelectorAll(".section--payment-method .radio-wrapper.content-box__row"),
radioButtons = [];
View embedded_app_plug.ex
defmodule Useless.Plugs.EmbeddedAppPlug do
@moduledoc """
Loads the shop from database, puts a private shop field in conn and sets x-frame-options.
Will halt if no shop found
"""
alias Plug.Conn
alias Useless.ShopifyApp
View shop_controller.ex
defmodule UselessWeb.ShopController do
# ...
def new(conn, %{"hmac" => _, "shop" => shopify_domain}) do
shop = ShopifyApp.find_shop_by(%{shopify_domain: shopify_domain})
conn
|> put_layout({UselessWeb.EmbeddedAppView, "layout.html"})
|> render("show.html", shop: shop)
end
View shop_controller.ex
defmodule UselessWeb.ShopController do
# ...
def new(conn, %{"shop" => shop_name}) when is_bitstring(shop_name),
do: signup(conn, %{"shop" => %{"shopify_domain" => shop_name}})
def new(conn, _params) do
changeset = ShopifyApp.change_shop(%Shop{})
render(conn, "new.html", changeset: changeset)
end
View shopify_app.ex
@doc """
Creates a new shop if no shop with the given shopify_domain exists, or updates
the existing shop
## Examples
iex> create_or_update_shop(%{shopify_domain: "shop@my_shopify.com", shopify_token: "a-token"})
{:ok, %Shop{}}
iex> create_or_update_shop(%{shopify_domain: nil, shopify_token: "a-token"})
View shopify_app_test.exs
test "create_or_update_shop/1 creates a shop if it doesn't already exist" do
assert {:ok, %Shop{} = shop} = ShopifyApp.create_or_update_shop(@valid_attrs)
assert shop.shopify_domain == @valid_attrs.shopify_domain
assert shop.shopify_token == @valid_attrs.shopify_token
end
test "create_or_update_shop/1 updates a shop's token if it already exists" do
shop_fixture()
params = %{
shopify_domain: @valid_attrs.shopify_domain,
View auth_controller.ex
defmodule UselessWeb.AuthController do
use UselessWeb, :controller
alias Useless.ShopifyApp
alias Useless.ShopifyApp.Shop
def shopify(conn, %{"shop" => shopify_domain, "code" => shopify_token}) do
session = shopify_domain |> Shopify.session()
with {:ok, %{data: oauth}} <- Shopify.OAuth.request_token(session, shopify_token),
View shop_controller.ex
defmodule UselessWeb.ShopController do
use UselessWeb, :controller
alias Useless.ShopifyApp
alias Useless.ShopifyApp.Shop
def new(conn, _params) do
changeset = ShopifyApp.change_shop(%Shop{})
render(conn, "new.html", changeset: changeset)
end
@Ninigi
Ninigi / select_default_shipping.js
Last active Jul 6, 2018
Force a default value for the shipping methods in shopify checkout to be selected on page load.
View select_default_shipping.js
var preferedShipping = "EMS"; // This has to be the exact name of the shipping method you want to be preselected
function waitForFetch(tries, callback) {
if (tries > 40000) {return} // stop waiting after ~ 40 seconds
if (document.querySelector(".blank-slate")) {
setTimeout(function() { waitForFetch(tries + 1, callback) }, 10);
} else {
callback();
}
View new.html.eex
<h2>New Shop</h2>
<%= render "signup_form.html", Map.put(assigns, :action, shop_path(@conn, :signup)) %>
You can’t perform that action at this time.