Android Developer Android Developer - 6 months ago 42
iOS Question

How to print the cart items,remove cart items in shopify ios sdk?

Hi I'm using Shopify ios sdk for my e-commerce app.I created login,signup and even list out the products in table view.I need to view products in my cart.So far I found only

in shopify which clears all the cart item. I tried to print cart items by
BUYProductVariant *variant = cartArray[i];
but it produces error.I struck here and don't know how to proceed further. Can any one help me to solve this and thanks in advance.


This is how you get BUYProduct from BUYCart

BUYCart *cartvalue = yourCart;

NSMutableArray *arrCartProducts = [NSMutableArray new];

arrCartProducts = [[cartvalue lineItems]mutableCopy];

// I am assuming you have at least one product in your cart

if (arrCartProducts.count !=0 ) {
    BUYCartLineItem *cartLintItemvalue=[arrCartProducts objectAtIndex:0] ;
    BUYProductVariant *variantsValue=[cartLintItemvalue variant];
    BUYProduct *product= [variantsValue product];

and this is how you remove BUYProductVariant from BUYCart

BUYCartLineItem *cartLintItemvalue=[arrCartProducts objectAtIndex:0];
BUYProductVariant *variantsValue=[cartLintItemvalue variant];
[cartvalue removeVariant:variantsValue];