make admin provider UI support both Printify and Printful
- Provider form accepts ?type= query param (printify/printful) - Conditional setup instructions per provider (API key steps, login URLs) - Dynamic labels, titles, and config handling (shop_id vs store_id) - Provider index shows dropdown with both provider options - Settings page renamed from @printify to @provider (generic) - Fix Printful shipping rates: add default state codes for US/CA/AU Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -198,8 +198,9 @@ defmodule SimpleshopTheme.Providers.Printful do
|
||||
|
||||
defp fetch_rate_for_product(catalog_product_id, variant_id, country_code) do
|
||||
items = [%{source: "catalog", catalog_variant_id: variant_id, quantity: 1}]
|
||||
recipient = build_recipient(country_code)
|
||||
|
||||
case Client.calculate_shipping(%{country_code: country_code}, items) do
|
||||
case Client.calculate_shipping(recipient, items) do
|
||||
{:ok, rates} when is_list(rates) ->
|
||||
standard = Enum.find(rates, &(&1["shipping"] == "STANDARD")) || List.first(rates)
|
||||
|
||||
@@ -228,6 +229,18 @@ defmodule SimpleshopTheme.Providers.Printful do
|
||||
end
|
||||
end
|
||||
|
||||
# Printful requires state_code for US, CA, and AU
|
||||
@default_state_codes %{"US" => "NY", "CA" => "ON", "AU" => "NSW"}
|
||||
|
||||
defp build_recipient(country_code) do
|
||||
base = %{country_code: country_code}
|
||||
|
||||
case @default_state_codes[country_code] do
|
||||
nil -> base
|
||||
state -> Map.put(base, :state_code, state)
|
||||
end
|
||||
end
|
||||
|
||||
# Returns {catalog_product_id, first_catalog_variant_id} per product
|
||||
defp extract_per_product_items(products) do
|
||||
products
|
||||
|
||||
Reference in New Issue
Block a user