CartApi class

Cart API for Magento integration.

This class provides comprehensive shopping cart functionality for Magento, supporting both guest and authenticated customer carts.

Features

  • Cart Management: Create, retrieve, and delete carts
  • Item Operations: Add, update, and remove items from cart
  • Coupon Management: Apply and remove discount coupons
  • Shipping: Estimate shipping costs and set shipping information
  • Totals: Calculate cart totals including taxes and shipping
  • Guest & Customer: Support for both guest and authenticated user carts
  • Cart Merging: Merge guest cart with customer cart after login

Usage

final cartApi = CartApi(apiClient);

// Create a guest cart
final cart = await cartApi.createCart();

// Add item to cart
await cartApi.addToCart(
  cartId: cart.id,
  sku: 'PRODUCT-SKU',
  quantity: 2,
);

Constructors

CartApi.new(MagentoApiClient _client)

Properties

hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

addToCart({required String cartId, required String sku, required int quantity, Map<String, dynamic>? productOptions}) Future<Cart>
Add item to guest cart.
addToCustomerCart({required String sku, required int quantity, Map<String, dynamic>? productOptions}) Future<Cart>
Add item to customer cart
applyCoupon({required String cartId, required String couponCode}) Future<Cart>
Apply coupon to cart
applyCouponToCustomerCart(String couponCode) Future<Cart>
Apply coupon to customer cart
clearCustomerCart() Future<bool>
Clear customer cart
createCart() Future<Cart>
Create a new guest cart.
deleteCart(String cartId) Future<bool>
Delete cart
estimateCustomerCartShipping(Address address) Future<List<ShippingMethod>>
Estimate shipping for customer cart
estimateShipping({required String cartId, required Address address}) Future<List<ShippingMethod>>
Estimate shipping for cart
getCart(String cartId) Future<Cart>
Get cart information
getCartTotals(String cartId) Future<CartTotals>
Get cart totals
getCustomerCart() Future<Cart>
Get customer cart
getCustomerCartTotals() Future<CartTotals>
Get customer cart totals
mergeGuestCart(String customerId) Future<Cart>
Merge guest cart with customer cart
moveToWishlist({required String cartId, required int itemId}) Future<bool>
Move item from cart to wishlist
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
removeCoupon(String cartId) Future<Cart>
Remove coupon from cart
removeCouponFromCustomerCart() Future<Cart>
Remove coupon from customer cart
removeFromCart({required String cartId, required int itemId}) Future<Cart>
Remove item from cart
removeFromCustomerCart(int itemId) Future<Cart>
Remove item from customer cart
setCustomerCartShippingInformation({required Address address, required String methodCode, required String carrierCode}) Future<Cart>
Set shipping information for customer cart
setShippingInformation({required String cartId, required Address address, required String methodCode, required String carrierCode}) Future<Cart>
Set shipping information for cart
toString() String
A string representation of this object.
inherited
updateCartItemQuantity({required String cartId, required int itemId, required int quantity}) Future<Cart>
Update cart item quantity
updateCustomerCartItemQuantity({required int itemId, required int quantity}) Future<Cart>
Update customer cart item quantity

Operators

operator ==(Object other) bool
The equality operator.
inherited