pify/storefront/cart
The Storefront cart: create one, read it, add, change and remove its
lines, and set its note. Every write answers the whole cart. The buyer
pays at checkout_url.
A refused write fails with ShopifyErrorUserErrors, which holds the
cart’s userErrors. A write Shopify adjusted, such as a quantity cut to
the stock, succeeds and reports the adjustment in warnings.
Types
pub type Attribute {
Attribute(key: String, value: option.Option(String))
}
Constructors
-
Attribute(key: String, value: option.Option(String))
pub type Cart {
Cart(
id: String,
checkout_url: String,
total_quantity: Int,
note: option.Option(String),
subtotal: money.Money,
total: money.Money,
lines: List(CartLine),
has_more_lines: Bool,
)
}
Constructors
-
Cart( id: String, checkout_url: String, total_quantity: Int, note: option.Option(String), subtotal: money.Money, total: money.Money, lines: List(CartLine), has_more_lines: Bool, )Arguments
- has_more_lines
-
The cart has more than
max_lineslines.
pub type CartLine {
CartLine(
id: String,
quantity: Int,
total: money.Money,
attributes: List(Attribute),
merchandise: Merchandise,
)
}
Constructors
-
CartLine( id: String, quantity: Int, total: money.Money, attributes: List(Attribute), merchandise: Merchandise, )
A change Shopify made to a write instead of refusing it. code is a
CartWarningCode, such as MERCHANDISE_NOT_ENOUGH_STOCK, and target the
id of the line or merchandise it concerns.
pub type CartWarning {
CartWarning(code: String, message: String, target: String)
}
Constructors
-
CartWarning(code: String, message: String, target: String)
The cart a write answers and the warnings it raised.
pub type CartWrite {
CartWrite(cart: Cart, warnings: List(CartWarning))
}
Constructors
-
CartWrite(cart: Cart, warnings: List(CartWarning))
pub type LineUpdate {
LineUpdate(line_id: String, quantity: Int)
}
Constructors
-
LineUpdate(line_id: String, quantity: Int)
The variant a line buys and the product it belongs to.
pub type Merchandise {
Merchandise(
variant: product.Variant,
product_id: String,
product_handle: String,
product_title: String,
)
}
Constructors
-
Merchandise( variant: product.Variant, product_id: String, product_handle: String, product_title: String, )
Values
pub fn add_lines(
client: storefront.StorefrontClient,
cart_id: String,
lines: List(LineInput),
) -> effect.Effect(Result(CartWrite, error.ShopifyError), key)
pub fn create(
client: storefront.StorefrontClient,
lines: List(LineInput),
) -> effect.Effect(Result(CartWrite, error.ShopifyError), key)
pub const create_mutation: String
pub fn decoder() -> decode.Decoder(Cart)
pub fn get(
client: storefront.StorefrontClient,
cart_id: String,
) -> effect.Effect(
Result(option.Option(Cart), error.ShopifyError),
key,
)
Ok(None) when the cart does not exist or was checked out.
pub fn line_update_to_json(update: LineUpdate) -> json.Json
pub const lines_add_mutation: String
pub const lines_remove_mutation: String
pub const lines_update_mutation: String
pub const note_update_mutation: String
pub fn remove_lines(
client: storefront.StorefrontClient,
cart_id: String,
line_ids: List(String),
) -> effect.Effect(Result(CartWrite, error.ShopifyError), key)
pub fn update_lines(
client: storefront.StorefrontClient,
cart_id: String,
updates: List(LineUpdate),
) -> effect.Effect(Result(CartWrite, error.ShopifyError), key)
A quantity of zero removes the line.
pub fn update_note(
client: storefront.StorefrontClient,
cart_id: String,
note: String,
) -> effect.Effect(Result(CartWrite, error.ShopifyError), key)