How to print the cart items,remove cart items in s

2019-05-30 20:35发布

问题:

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 buyCart.clear; 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.

回答1:

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];