Getting a Specific Carts
Function: carts_get_info()
Purpose
The carts_get_info()
function is used to retrieve detailed information about a specific cart session using its session_id. It provides a complete snapshot of the cart, including customer data, items, pricing, taxes, discounts, and shipping details.
Parameters
Parameter | Type | Description |
---|---|---|
session_id | String | The unique identifier of the Cart Session. |
Use Case
Use this function to fetch the current state of a user's shopping cart—such as when displaying the cart contents before checkout, verifying totals, or analyzing cart behavior for a given session. This is particularly useful in e-commerce workflows to track and troubleshoot cart-specific issues or display real-time cart data.
def carts_get_info():
SDKConfig.PRINT_REQUEST_DATA = True
SDKConfig.PRINT_RAW_RESPONSE = True
webcommander_sdk: WebCommanderSDK = WebCommanderSDK().init_sdk(request_token_dto=CommonData.get_request_token_dto())
try:
response = webcommander_sdk.carts.info(session_id="SESSION_ID")
print(response)
except WCException as ab:
print(ab)
print(ab.get_errors())
print(ab.raw_response)
Response
The function returns a CartSessionResponseDTO
object, which contains detailed information about the cart. This includes the session ID, customer ID, currency, cart items with product and pricing info, totals (e.g., subtotal, tax, grand total), discounts, and any applicable messages.
CartSessionResponseDTO(
cart=CartSessionCartDTO(
customerId=CUSTOMER_ID,
sessionId="SESSION_ID",
currencyCode="CURRENCY_CODE",
currencySymbol="CURRENCY_SYMBOL",
deliveryType="DELIVERY_TYPE",
totals=CartSessionTotalsDTO(
subtotal=SUBTOTAL,
discount=DISCOUNT,
shippingDiscount=SHIPPING_DISCOUNT,
tax=TAX,
total=TOTAL,
grandTotal=GRAND_TOTAL,
paid=PAID
),
shipping=CartSessionShippingDTO(
cost=SHIPPING_COST,
handlingFee=HANDLING_FEE,
handlingTax=HANDLING_TAX,
shippingTax=SHIPPING_TAX,
totalTax=TOTAL_TAX
),
items=[
CartSessionItemDTO(
id=ITEM_ID,
quantity=QUANTITY,
variations=["VARIATION_1", "VARIATION_2"],
taxable=TAXABLE,
shippable=SHIPPABLE,
pricing=CartSessionItemPricingDTO(
unitPrice=UNIT_PRICE,
displayUnitPrice=DISPLAY_UNIT_PRICE,
total=ITEM_TOTAL,
discount=ITEM_DISCOUNT,
discountTax=ITEM_DISCOUNT_TAX,
tax=ITEM_TAX
),
product=CartSessionProductDTO(
id=PRODUCT_ID,
sku="SKU",
basePrice=BASE_PRICE,
availableStock=AVAILABLE_STOCK,
onSale=ON_SALE,
costPrice=COST_PRICE,
salePrice=SALE_PRICE,
url="URL",
name="PRODUCT_NAME",
productType="PRODUCT_TYPE",
imageLink="IMAGE_LINK"
)
)
],
discount=CartSessionDiscountDTO(
discount=CART_DISCOUNT,
orderDiscount=ORDER_DISCOUNT,
shippingDiscount=SHIPPING_DISCOUNT,
discountOnTax=DISCOUNT_ON_TAX,
discountOnShippingTax=DISCOUNT_ON_SHIPPING_TAX
),
messages=CartSessionMessagesDTO(
discount=CartSessionDiscountMessageDTO(
message="DISCOUNT_MESSAGE",
status=DISCOUNT_STATUS
)
)
)
)
Creating a New Cart
Function: carts_create()
Purpose
The carts_create()
function is used to programmatically create a new cart session by submitting customer information, shipping and billing addresses, product configuration, quantity, and optional coupon codes. This simulates the process of adding items to a cart on an e-commerce platform.
Parameters
Parameter | Type | Description |
---|---|---|
customerId | String | Unique identifier of the customer. |
billingAddress | Object | Details of the billing address, including name, address, and contact. |
shippingAddress | Object | Details of the shipping address. Includes IP address. |
sessionId | String | Session identifier to track the cart. |
productId | String | ID of the product to add to the cart. |
config | Dictionary | Configuration options like product variation ID. |
couponCode | String (optional) | Coupon code to apply discounts. |
quantity | String/Integer | Number of items to add to the cart. |
Use Case
Use this function when initializing a customer's cart, such as during the first step of the checkout process. It is also useful for testing cart creation flows with various combinations of products, addresses, or discounts, allowing for integration or QA validation in shopping experiences.
def carts_create():
SDKConfig.PRINT_REQUEST_DATA = False
SDKConfig.PRINT_RAW_RESPONSE = False
webcommander_sdk: WebCommanderSDK = WebCommanderSDK().init_sdk(
request_token_dto=CommonData.get_request_token_dto()
)
try:
request_data = CreateCartRequestDTO(
customerId="CUSTOMER_ID",
billingAddress=CreateCartAddressDTO(
firstName="BILLING_FIRST_NAME",
lastName="BILLING_LAST_NAME",
addressLine1="BILLING_ADDRESS_LINE_1",
addressLine2="BILLING_ADDRESS_LINE_2",
city="BILLING_CITY",
postCode="BILLING_POST_CODE",
countryId="BILLING_COUNTRY_ID",
stateId=BILLING_STATE_ID,
email="BILLING_EMAIL"
),
shippingAddress=CreateCartAddressDTO(
firstName="SHIPPING_FIRST_NAME",
lastName="SHIPPING_LAST_NAME",
addressLine1="SHIPPING_ADDRESS_LINE_1",
addressLine2="SHIPPING_ADDRESS_LINE_2",
city="SHIPPING_CITY",
postCode="SHIPPING_POST_CODE",
countryId="SHIPPING_COUNTRY_ID",
stateId=SHIPPING_STATE_ID,
email="SHIPPING_EMAIL",
ipAddress="IP_ADDRESS"
),
sessionId="SESSION_ID",
productId="PRODUCT_ID",
config={"variation": VARIATION_ID},
couponCode="COUPON_CODE",
quantity="QUANTITY"
)
response = webcommander_sdk.carts.create_cart(request_data=request_data)
print(response)
except WCException as ab:
print(ab)
print(ab.get_errors())
print(ab.raw_response)
Response
The function returns a CartSessionResponseDTO
object containing the full cart session data, including session ID, customer info, currency details, cart totals, list of items, discounts applied, and shipping costs.
CartSessionResponseDTO(
cart=CartSessionCartDTO(
customerId=CUSTOMER_ID,
sessionId="SESSION_ID",
currencyCode="CURRENCY_CODE",
currencySymbol="CURRENCY_SYMBOL",
deliveryType="DELIVERY_TYPE",
totals=CartSessionTotalsDTO(
subtotal=SUBTOTAL,
discount=DISCOUNT,
shippingDiscount=SHIPPING_DISCOUNT,
tax=TAX,
total=TOTAL,
grandTotal=GRAND_TOTAL,
paid=PAID
),
shipping=CartSessionShippingDTO(
cost=SHIPPING_COST,
handlingFee=HANDLING_FEE,
handlingTax=HANDLING_TAX,
shippingTax=SHIPPING_TAX,
totalTax=TOTAL_TAX
),
items=[
CartSessionItemDTO(
id=ITEM_ID,
quantity=QUANTITY,
variations=["VARIATION_1", "VARIATION_2"],
taxable=TAXABLE,
shippable=SHIPPABLE,
pricing=CartSessionItemPricingDTO(
unitPrice=UNIT_PRICE,
displayUnitPrice=DISPLAY_UNIT_PRICE,
total=ITEM_TOTAL,
discount=ITEM_DISCOUNT,
discountTax=ITEM_DISCOUNT_TAX,
tax=ITEM_TAX
),
product=CartSessionProductDTO(
id=PRODUCT_ID,
sku="SKU",
basePrice=BASE_PRICE,
availableStock=AVAILABLE_STOCK,
onSale=ON_SALE,
costPrice=COST_PRICE,
salePrice=SALE_PRICE,
url="PRODUCT_URL",
name="PRODUCT_NAME",
productType="PRODUCT_TYPE",
imageLink="IMAGE_LINK"
)
)
],
discount=CartSessionDiscountDTO(
discount=CART_DISCOUNT,
orderDiscount=ORDER_DISCOUNT,
shippingDiscount=SHIPPING_DISCOUNT,
discountOnTax=DISCOUNT_ON_TAX,
discountOnShippingTax=DISCOUNT_ON_SHIPPING_TAX
),
messages=CartSessionMessagesDTO(
discount=CartSessionDiscountMessageDTO(
message="DISCOUNT_MESSAGE",
status=DISCOUNT_STATUS
)
)
)
)
Updating Specific Carts
Function: carts_update()
Purpose
The carts_update()
function is designed to update an existing cart session by modifying item details (such as quantity, price, or options) or updating the shipping address. It supports both full cart updates and partial updates to a specific item in the cart, depending on the payload structure.
Parameters
Parameter | Type | Description |
---|---|---|
id | String | The unique identifier of the Carts. |
Use Case
Use this function when a customer changes product variations, updates quantities, or edits their shipping address during the checkout process. It is particularly useful for reflecting changes in cart configuration before placing an order, ensuring that the latest selections are captured in the cart session.
def carts_update_test():
SDKConfig.PRINT_REQUEST_DATA = True
SDKConfig.PRINT_RAW_RESPONSE = True
webcommander_sdk: WebCommanderSDK = WebCommanderSDK().init_sdk(
request_token_dto=CommonData.get_request_token_dto()
)
try:
# Type-1 Payload (Update using full cart item details)
request_data = UpdateCartRequestDTO(
cartItems=[
UpdateCartItemDTO(
id="ITEM_ID",
productPrice="PRODUCT_PRICE",
quantity=QUANTITY,
options=[
UpdateCartOptionDTO(name="OPTION_NAME_1", value="OPTION_VALUE_1"),
UpdateCartOptionDTO(name="OPTION_NAME_2", value="OPTION_VALUE_2")
]
)
],
shippingAddress=UpdateCartAddressDTO(
firstName="FIRST_NAME",
lastName="LAST_NAME",
email="EMAIL",
addressLine1="ADDRESS_LINE_1",
addressLine2="ADDRESS_LINE_2",
country="COUNTRY_ID",
state="STATE_ID",
city="CITY",
postCode="POST_CODE"
)
)
# Type-2 Payload (Update using cart item ID directly)
request_data = UpdateCartRequestDTO(
cartItemId="CART_ITEM_ID",
quantity="QUANTITY",
shippingAddress=UpdateCartAddressDTO(
firstName="FIRST_NAME",
lastName="LAST_NAME",
addressLine1="ADDRESS_LINE_1",
addressLine2="ADDRESS_LINE_2",
city="CITY",
postCode="POST_CODE",
countryId="COUNTRY_ID",
stateId=STATE_ID,
email="EMAIL",
customerId="CUSTOMER_ID"
# ipAddress can be added if needed
)
)
response = webcommander_sdk.carts.update_cart(session_id="SESSION_ID", request_data=request_data)
print(response)
except WCException as ab:
print(ab)
print(ab.get_errors())
print(ab.raw_response)
Response
The function returns a CartSessionResponseDTO
object containing the updated cart session details, including the current items, totals, tax, discounts, and shipping information.
CartSessionResponseDTO(
cart=CartSessionCartDTO(
customerId=CUSTOMER_ID,
sessionId="SESSION_ID",
currencyCode="CURRENCY_CODE",
currencySymbol="CURRENCY_SYMBOL",
deliveryType="DELIVERY_TYPE",
totals=CartSessionTotalsDTO(
subtotal=SUBTOTAL,
discount=DISCOUNT,
shippingDiscount=SHIPPING_DISCOUNT,
tax=TAX,
total=TOTAL,
grandTotal=GRAND_TOTAL,
paid=PAID
),
shipping=CartSessionShippingDTO(
cost=SHIPPING_COST,
handlingFee=HANDLING_FEE,
handlingTax=HANDLING_TAX,
shippingTax=SHIPPING_TAX,
totalTax=TOTAL_TAX
),
items=[
CartSessionItemDTO(
id=ITEM_ID,
quantity=QUANTITY,
variations=["VARIATION_1", "VARIATION_2"],
taxable=TAXABLE,
shippable=SHIPPABLE,
pricing=CartSessionItemPricingDTO(
unitPrice=UNIT_PRICE,
displayUnitPrice=DISPLAY_UNIT_PRICE,
total=ITEM_TOTAL,
discount=ITEM_DISCOUNT,
discountTax=ITEM_DISCOUNT_TAX,
tax=ITEM_TAX
),
product=CartSessionProductDTO(
id=PRODUCT_ID,
sku="SKU",
basePrice=BASE_PRICE,
availableStock=AVAILABLE_STOCK,
onSale=ON_SALE,
costPrice=COST_PRICE,
salePrice=SALE_PRICE,
url="PRODUCT_URL",
name="PRODUCT_NAME",
productType="PRODUCT_TYPE",
imageLink="IMAGE_LINK"
)
)
],
discount=CartSessionDiscountDTO(
discount=CART_DISCOUNT,
orderDiscount=ORDER_DISCOUNT,
shippingDiscount=SHIPPING_DISCOUNT,
discountOnTax=DISCOUNT_ON_TAX,
discountOnShippingTax=DISCOUNT_ON_SHIPPING_TAX
),
messages=CartSessionMessagesDTO(
discount=CartSessionDiscountMessageDTO(
message="DISCOUNT_MESSAGE",
status=DISCOUNT_STATUS
)
)
)
)
Applying a Gift Card to a Cart
Function: cart_gift_apply()
Purpose
The cart_gift_apply()
function applies a gift card to an existing shopping cart. This is useful during the checkout process when a customer wants to redeem a gift card for partial or full payment of their order.
Parameters
Parameter | Type | Description |
---|---|---|
customerID | Integer | ID of the customer applying the gift card. |
giftCardCode | String | Code of the gift card to be redeemed. |
paymentGateway | String | Payment gateway identifier for the gift card transaction. |
carts_id | String | The ID of the cart to which the gift card is applied. |
Use Case
Use this function when a customer wants to apply a gift card to their cart. It validates the gift card and, if successful, deducts the applicable amount from the total payable in the cart. This function ensures the gift card is valid and within its usable amount limits
.
def cart_gift_apply():
SDKConfig.PRINT_REQUEST_DATA = True
SDKConfig.PRINT_RAW_RESPONSE = True
webcommander_sdk: WebCommanderSDK = WebCommanderSDK().init_sdk(
request_token_dto=CommonData.get_request_token_dto()
)
try:
request_data = CartDetailsDTO(
customerID="CUSTOMER_ID",
giftCardCode="GIFT_CARD_CODE",
paymentGateway="PAYMENT_GATEWAY",
)
response = webcommander_sdk.carts.cart_gift_cart_apply(request_data=request_data, carts_id="CART_ID")
print(response)
except WCException as ab:
print(ab)
print(ab.get_errors())
print(ab.raw_response)
Response
GiftCardResponseDTO(
giftCard=GiftCardDataDTO(
redeemStatus="REDEEM_STATUS",
redeemMessage="REDEEM_MESSAGE",
applicableAmount="APPLICABLE_AMOUNT"
)
)
Placing an Order from Cart
Function: admin_cart_order()
Purpose
The admin_cart_order()
function is used to place an order from a specific cart. It processes the cart by validating customer details, applying gift cards if present, and generating an order with a pending payment status. This is essential for converting a prepared cart into an active order within the admin interface.
Parameters
Parameter | Type | Description |
---|---|---|
customerId | Integer | ID of the customer placing the order. |
giftCardCode | String | Code of the gift card to be applied during the order placement. |
paymentGateway | String | Identifier of the payment gateway used for the transaction. |
carts_id | String | The ID of the cart from which the order is placed. |
Use Case
Use this function when an admin needs to finalize a customer's cart into an order. It is helpful in scenarios such as admin-assisted checkouts, placing phone or in-store orders on behalf of customers, or testing gift card transactions within the order pipeline.
def admin_cart_order():
SDKConfig.PRINT_REQUEST_DATA = True
SDKConfig.PRINT_RAW_RESPONSE = True
webcommander_sdk: WebCommanderSDK = WebCommanderSDK().init_sdk(
request_token_dto=CommonData.get_request_token_dto()
)
try:
request_data = CartDetailsDTO(
customerId="CUSTOMER_ID",
giftCardCode="GIFT_CARD_CODE",
paymentGateway="PAYMENT_GATEWAY"
)
response = webcommander_sdk.carts.cart_order(request_data=request_data, carts_id="CART_ID")
print(response)
except WCException as ab:
print(ab)
print(ab.get_errors())
print(ab.raw_response)
Response
CartOrderResponseDTO(
status="STATUS",
order=OrderDTO(
orderId="ORDER_ID",
orderStatus="ORDER_STATUS",
subTotal="SUB_TOTAL",
shippingCost="SHIPPING_COST",
shippingTax="SHIPPING_TAX",
handlingCost="HANDLING_COST",
totalSurcharge="TOTAL_SURCHARGE",
totalDiscount="TOTAL_DISCOUNT",
totalTax="TOTAL_TAX",
grandTotal="GRAND_TOTAL",
paid="PAID_AMOUNT",
due="DUE_AMOUNT",
itemsTotal="ITEMS_TOTAL",
paymentStatus="PAYMENT_STATUS",
ipAddress="IP_ADDRESS",
customerSummary=CustomerSummaryDTO(
firstName="FIRST_NAME",
lastName="LAST_NAME",
customerGroup="CUSTOMER_GROUP",
customerId="CUSTOMER_ID",
gender="GENDER",
email="EMAIL_ADDRESS",
addressLine1="ADDRESS_LINE_1",
city="CITY",
country=CountryDTO(id="COUNTRY_ID", name="COUNTRY_NAME", code="COUNTRY_CODE"),
state=StateDTO(id="STATE_ID", name="STATE_NAME", code="STATE_CODE"),
postCode="POST_CODE"
),
orderLineDetails=[
OrderLineDetailDTO(
itemId="ITEM_ID",
productName="PRODUCT_NAME",
productId="PRODUCT_ID",
quantity="QUANTITY",
price="PRICE",
totalAmount="TOTAL_AMOUNT",
tax="TAX",
discount="DISCOUNT",
isTaxable="IS_TAXABLE",
isShippable="IS_SHIPPABLE"
)
],
payments=[
PaymentResponseDTO(
id="PAYMENT_ID",
status="PAYMENT_STATUS",
amount="AMOUNT",
gatewayCode="GATEWAY_CODE",
payingDate="PAYING_DATE"
)
]
)
)
Deleting a Cart
Function: carts_delete()
Purpose
The carts_delete()
function is used to permanently delete an entire cart by its ID. This action removes all associated cart data, including items, pricing, and customer information tied to the cart. It's useful for clearing abandoned or test carts to maintain a clean system state.
Parameters
Parameter | Type | Description |
---|---|---|
carts_id | String | The unique identifier of the cart. |
Use Case
Use this function when an entire cart needs to be deleted from the system, such as after testing, order cancellation, or cleanup of inactive user sessions.
def carts_delete():
SDKConfig.PRINT_REQUEST_DATA = True
SDKConfig.PRINT_RAW_RESPONSE = True
webcommander_sdk: WebCommanderSDK = WebCommanderSDK().init_sdk(request_token_dto=CommonData.get_request_token_dto())
try:
response = webcommander_sdk.carts.cart_delete(carts_id="CART_ID")
print(response)
except WCException as ab:
print(ab)
print(ab.get_errors())
print(ab.raw_response)
Response
The function returns a success message indicating that the cart has been successfully deleted.
Deleting a Cart Item
Function: carts_item_delete()
Purpose
The carts_item_delete()
function deletes a specific item from a cart using the cart ID and the item ID. This allows for fine-grained control over cart contents without needing to delete the entire cart.
Parameters
Parameter | Type | Description |
---|---|---|
carts_id | String | The unique identifier of the cart. |
carts_item_id | String | The unique identifier of the cart item. |
Use Case
Use this function to remove an individual product from a customer's cart — for example, when a product is out of stock, a user wants to modify their selection, or an admin is adjusting the cart contents.
def carts_item_delete():
SDKConfig.PRINT_REQUEST_DATA = True
SDKConfig.PRINT_RAW_RESPONSE = True
webcommander_sdk: WebCommanderSDK = WebCommanderSDK().init_sdk(request_token_dto=CommonData.get_request_token_dto())
try:
response = webcommander_sdk.carts.cart_item_delete(carts_id="CART_ID", carts_item_id="CART_ITEM_ID")
print(response)
except WCException as ab:
print(ab)
print(ab.get_errors())
print(ab.raw_response)
Response
The function returns a success message indicating that the cart item has been successfully deleted.