Shopify SDK for Unity
Public Types | Public Member Functions | Static Public Member Functions | Properties | Events | List of all members
Shopify.Unity.SDK.CartLineItems Class Reference

Is used to add, update, or delete line items in a Cart . More...

Public Types

enum class  LineItemChangeType { Add , Remove , Update }
 

Public Member Functions

void AddOrUpdate (ProductVariant variant, long? quantity=null, Dictionary< string, string > customAttributes=null)
 Adds or updates a line item using a ProductVariant . More...
 
void AddOrUpdate (Product product, Dictionary< string, string > selectedOptions, long? quantity=null, Dictionary< string, string > customAttributes=null)
 Adds a new line item using a Product and selected options. If an existing line item exists for the variant id, then that line item will be updated. More...
 
List< CartLineItemAll ()
 Returns all Line Items that have been created. More...
 
CartLineItem Get (string variantId)
 Returns one Line Item based on a variant id. If no line item exists for the variant id null will be returned. More...
 
CartLineItem Get (ProductVariant variant)
 Returns one Line Item based on a ProductVariant . If no line item exists for the variant, null will be returned. More...
 
CartLineItem Get (Product product, Dictionary< string, string > selectedOptions)
 Returns one Line Item based on a product and selected options. If no line item exists for the matching variant, null will be returned. More...
 
bool Delete (string variantId)
 Deletes one Line Item based on a variant id. If a line item was deleted, true will be returned. If no line items were deleted, false will be returned. More...
 
bool Delete (ProductVariant variant)
 Deletes one Line Item based on a ProductVariant . If a line item was deleted, true will be returned. If no line items were deleted, false will be returned. More...
 
bool Delete (Product product, Dictionary< string, string > selectedOptions)
 Deletes one Line Item based on a Product and selected options. If a line item was deleted, true will be returned. If no line item was deleted, false will be returned. More...
 
void Reset ()
 Deletes all line items More...
 
void UpdateLineItemsFromCheckoutLineItems (List< CheckoutLineItem > checkoutLineItems)
 

Static Public Member Functions

static List< CheckoutLineItemInputConvertToCheckoutLineItemInput (List< CartLineItem > lineItems)
 
static List< string > ConvertToLineItemIds (List< CartLineItem > lineItems)
 

Properties

bool IsSaved [get]
 
decimal Subtotal [get]
 

Events

LineItemChangeHandler OnChange
 

Detailed Description

Is used to add, update, or delete line items in a Cart

.

Member Function Documentation

◆ AddOrUpdate() [1/2]

void Shopify.Unity.SDK.CartLineItems.AddOrUpdate ( Product  product,
Dictionary< string, string >  selectedOptions,
long?  quantity = null,
Dictionary< string, string >  customAttributes = null 
)
inline

Adds a new line item using a Product and selected options. If an existing line item exists for the variant id, then that line item will be updated.

Parameters
productproduct to check selected options against
selectedOptionsa Dictionary used to define user selected options
quantitythe number of items you'd like to order for variantId
customAttributescustomAttributes can be used to define extra information for this line item

Throws when no matching variant could be found for selected options in product

// Example that updates the quantity of items to be purchased to 3.
// If no line item exists for `variantId`, then a new line item is created
Cart cart = ShopifyBuy.Client().Cart();
Dictionary<string, string> selectedOptions = new Dictionary<string, string>() {
{"Size", "Small"},
{"Color", "Red"}
};
cart.LineItems.AddOrUpdate(product, selectedOptions, 3);

◆ AddOrUpdate() [2/2]

void Shopify.Unity.SDK.CartLineItems.AddOrUpdate ( ProductVariant  variant,
long?  quantity = null,
Dictionary< string, string >  customAttributes = null 
)
inline

Adds or updates a line item using a ProductVariant .

Parameters
variantProductVariant whose id will be used to create or update a line item
quantitythe number of items you'd like to order for variantId
customAttributescan be used to define extra information for this line item
// Example that updates the quantity of items to be purchased to 3.
// If no line item exists for `variantId`, then a new line item is created
Cart cart = ShopifyBuy.Client().Cart();
cart.LineItems.AddOrUpdate(variant, 3);

◆ All()

List<CartLineItem> Shopify.Unity.SDK.CartLineItems.All ( )
inline

Returns all Line Items that have been created.

// Example that checks how many line items the cart contains
Cart cart = ShopifyBuy.Client().Cart();
Debug.Log("The cart has " + cart.LineItems.All().Count + " line items");

◆ Delete() [1/3]

bool Shopify.Unity.SDK.CartLineItems.Delete ( Product  product,
Dictionary< string, string >  selectedOptions 
)
inline

Deletes one Line Item based on a Product and selected options. If a line item was deleted, true will be returned. If no line item was deleted, false will be returned.

Parameters
productproduct whose options will be used to determine which line item is deleted
selectedOptionsa Dictionary used to define user selected options
// Example that deletes a line item based on a product and selected options
Cart cart = ShopifyBuy.Client().Cart();
Dictionary<string, string> selectedOptions = new Dictionary<string, string>() {
{"Size", "Small"},
{"Color", "Red"}
};
Debug.Log("Did delete? " + cart.LineItems.Delete(product, selectedOptions));

◆ Delete() [2/3]

bool Shopify.Unity.SDK.CartLineItems.Delete ( ProductVariant  variant)
inline

Deletes one Line Item based on a ProductVariant . If a line item was deleted, true will be returned. If no line items were deleted, false will be returned.

Parameters
variantvariant to provide the ID to delete a line item
// Example that deletes a line item based on a product variant
Cart cart = ShopifyBuy.Client().Cart();
Debug.Log("Did delete? " + cart.LineItems.Delete(variant));

◆ Delete() [3/3]

bool Shopify.Unity.SDK.CartLineItems.Delete ( string  variantId)
inline

Deletes one Line Item based on a variant id. If a line item was deleted, true will be returned. If no line items were deleted, false will be returned.

Parameters
variantIdvariant id used to delete a line item
// Example that deletes a line item based on variantId
Cart cart = ShopifyBuy.Client().Cart();
Debug.Log("Did delete? " + cart.LineItems.Delete(variantId));

◆ Get() [1/3]

CartLineItem Shopify.Unity.SDK.CartLineItems.Get ( Product  product,
Dictionary< string, string >  selectedOptions 
)
inline

Returns one Line Item based on a product and selected options. If no line item exists for the matching variant, null will be returned.

Parameters
productproduct whose options will be selected
selectedOptionsa Dictionary used to define user selected options
// Example that checks the quantity of a line item based on a product and selected options
Cart cart = ShopifyBuy.Client().Cart();
Dictionary<string, string> selectedOptions = new Dictionary<string, string>() {
{"Size", "Small"},
{"Color", "Red"}
};
Debug.Log(cart.LineItems.Get(product, selectedOptions).quantity);

◆ Get() [2/3]

CartLineItem Shopify.Unity.SDK.CartLineItems.Get ( ProductVariant  variant)
inline

Returns one Line Item based on a ProductVariant . If no line item exists for the variant, null will be returned.

Parameters
variantvariant whose variant id used to create a line item
// Example that checks the quantity of a line item based on a variant
Cart cart = ShopifyBuy.Client().Cart();
Debug.Log(cart.LineItems.Get(variant).quantity);

◆ Get() [3/3]

CartLineItem Shopify.Unity.SDK.CartLineItems.Get ( string  variantId)
inline

Returns one Line Item based on a variant id. If no line item exists for the variant id null will be returned.

Parameters
variantIdvariant id used to create a line item
// Example that checks the quantity of a line item based on variantId
Cart cart = ShopifyBuy.Client().Cart();
Debug.Log(cart.LineItems.Get(variantId).quantity);

◆ Reset()

void Shopify.Unity.SDK.CartLineItems.Reset ( )
inline

Deletes all line items


The documentation for this class was generated from the following file: