From ffef1e40759c6da7bf0758528403913f515e83ee Mon Sep 17 00:00:00 2001 From: rupam4 Date: Mon, 2 Nov 2020 12:56:24 +0530 Subject: [PATCH 01/80] checkout emailUpdate --- .../mutations/checkout_email_update.dart | 5 + lib/shopify/src/shopify_checkout.dart | 175 +++++++++++------- 2 files changed, 110 insertions(+), 70 deletions(-) diff --git a/lib/graphql_operations/mutations/checkout_email_update.dart b/lib/graphql_operations/mutations/checkout_email_update.dart index 50ec5062..ba4ec11e 100644 --- a/lib/graphql_operations/mutations/checkout_email_update.dart +++ b/lib/graphql_operations/mutations/checkout_email_update.dart @@ -1,8 +1,13 @@ const String checkoutEmailUpdateMutation = r''' mutation checkoutEmailUpdate($checkoutId : ID!, $email : String!) { checkoutEmailUpdateV2(checkoutId: $checkoutId, email: $email) { + checkout { + id + } checkoutUserErrors { code + field + message } } } diff --git a/lib/shopify/src/shopify_checkout.dart b/lib/shopify/src/shopify_checkout.dart index a5800435..0699b757 100644 --- a/lib/shopify/src/shopify_checkout.dart +++ b/lib/shopify/src/shopify_checkout.dart @@ -1,5 +1,6 @@ import 'package:flutter_simple_shopify/enums/src/sort_key_order.dart'; import 'package:flutter_simple_shopify/graphql_operations/mutations/checkout_complete_free.dart'; +import 'package:flutter_simple_shopify/graphql_operations/mutations/checkout_email_update.dart'; import 'package:flutter_simple_shopify/graphql_operations/mutations/checkout_shipping_address_update.dart'; import 'package:flutter_simple_shopify/graphql_operations/mutations/create_checkout.dart'; import 'package:flutter_simple_shopify/graphql_operations/queries/get_checkout_info_is_ready.dart'; @@ -23,7 +24,7 @@ import '../../models/src/checkout.dart'; import '../../shopify_config.dart'; /// ShopifyCheckout provides various method in order to work with checkouts. -class ShopifyCheckout with ShopifyError{ +class ShopifyCheckout with ShopifyError { ShopifyCheckout._(); static final ShopifyCheckout instance = ShopifyCheckout._(); @@ -32,46 +33,56 @@ class ShopifyCheckout with ShopifyError{ /// Returns a [Checkout] object. /// /// Returns the Checkout object of the checkout with the [checkoutId]. - Future getCheckoutInfoQuery(String checkoutId, {bool deleteThisPartOfCache = false}) async { - final WatchQueryOptions _optionsRequireShipping = - WatchQueryOptions(documentNode: gql(getCheckoutInfoAboutShipping), variables: { - 'id': checkoutId, - }); + Future getCheckoutInfoQuery(String checkoutId, + {bool deleteThisPartOfCache = false}) async { + final WatchQueryOptions _optionsRequireShipping = WatchQueryOptions( + documentNode: gql(getCheckoutInfoAboutShipping), + variables: { + 'id': checkoutId, + }); QueryResult result = await _graphQLClient.query(_optionsRequireShipping); print((result?.data as LazyCacheMap)?.data); - final WatchQueryOptions _options = - WatchQueryOptions(documentNode: gql(_requiresShipping(result) == true ? getCheckoutInfo : getCheckoutInfoWithoutShipping), variables: { - 'id': checkoutId, - }); + final WatchQueryOptions _options = WatchQueryOptions( + documentNode: gql(_requiresShipping(result) == true + ? getCheckoutInfo + : getCheckoutInfoWithoutShipping), + variables: { + 'id': checkoutId, + }); final QueryResult _queryResult = (await _graphQLClient.query(_options)); checkForError(_queryResult); - if(deleteThisPartOfCache) { + if (deleteThisPartOfCache) { _graphQLClient.cache.write(_options.toKey(), null); } - return Checkout.fromJson( - _queryResult?.data['node']); + return Checkout.fromJson(_queryResult?.data['node']); } - Future getCheckoutInfoWithAvailableShippingRatesQuery(String checkoutId, {bool deleteThisPartOfCache = false}) async { - final WatchQueryOptions _optionsRequireShipping = - WatchQueryOptions(documentNode: gql(getCheckoutInfoAboutShipping), variables: { - 'id': checkoutId, - }); + + Future getCheckoutInfoWithAvailableShippingRatesQuery( + String checkoutId, + {bool deleteThisPartOfCache = false}) async { + final WatchQueryOptions _optionsRequireShipping = WatchQueryOptions( + documentNode: gql(getCheckoutInfoAboutShipping), + variables: { + 'id': checkoutId, + }); QueryResult result = await _graphQLClient.query(_optionsRequireShipping); print((result?.data as LazyCacheMap)?.data); - final WatchQueryOptions _options = - WatchQueryOptions(documentNode: gql(_requiresShipping(result) == true ? getCheckoutInfoWithShippingRate : getCheckoutInfoWithoutShipping), variables: { - 'id': checkoutId, - }); + final WatchQueryOptions _options = WatchQueryOptions( + documentNode: gql(_requiresShipping(result) == true + ? getCheckoutInfoWithShippingRate + : getCheckoutInfoWithoutShipping), + variables: { + 'id': checkoutId, + }); final QueryResult _queryResult = (await _graphQLClient.query(_options)); checkForError(_queryResult); - if(deleteThisPartOfCache) { + if (deleteThisPartOfCache) { _graphQLClient.cache.write(_options.toKey(), null); } - return Checkout.fromJson( - _queryResult?.data['node']); + return Checkout.fromJson(_queryResult?.data['node']); } - bool _requiresShipping(QueryResult result){ + bool _requiresShipping(QueryResult result) { return ((result?.data ?? const {})['node'] ?? const {})['requiresShipping']; } @@ -91,21 +102,24 @@ class ShopifyCheckout with ShopifyError{ /// /// Returns a List of Orders from the Customer with the [customerAccessToken]. Future> getAllOrders(String customerAccessToken, - { SortKeyOrder sortKey = SortKeyOrder.ID, bool reverse = true, bool deleteThisPartOfCache = false}) async { - final QueryOptions _options = WatchQueryOptions( - documentNode: gql(getAllOrdersQuery), - variables: { - 'accessToken': customerAccessToken, - 'sortKey': sortKey.parseToString(), - 'reverse': reverse - } - ); - final QueryResult result = await ShopifyConfig.graphQLClient.query(_options); - checkForError(result); - Orders orders = Orders.fromJson(((((result?.data ?? const {}))['customer'] ?? const {})['orders'] ?? const {})); - if(deleteThisPartOfCache) { - _graphQLClient.cache.write(_options.toKey(), null); - } + {SortKeyOrder sortKey = SortKeyOrder.ID, + bool reverse = true, + bool deleteThisPartOfCache = false}) async { + final QueryOptions _options = + WatchQueryOptions(documentNode: gql(getAllOrdersQuery), variables: { + 'accessToken': customerAccessToken, + 'sortKey': sortKey.parseToString(), + 'reverse': reverse + }); + final QueryResult result = + await ShopifyConfig.graphQLClient.query(_options); + checkForError(result); + Orders orders = Orders.fromJson( + ((((result?.data ?? const {}))['customer'] ?? const {})['orders'] ?? + const {})); + if (deleteThisPartOfCache) { + _graphQLClient.cache.write(_options.toKey(), null); + } return orders.orderList; } @@ -113,16 +127,17 @@ class ShopifyCheckout with ShopifyError{ /// /// [checkoutLineItems] is a List of Variant Ids Future checkoutLineItemsReplace( - String checkoutId, List variantIdList, {bool deleteThisPartOfCache = false}) async { + String checkoutId, List variantIdList, + {bool deleteThisPartOfCache = false}) async { var checkoutLineItems = transformVariantIdListIntoListOfMaps(variantIdList); final MutationOptions _options = - MutationOptions(documentNode: gql(replaceCheckoutItems), variables: { + MutationOptions(documentNode: gql(replaceCheckoutItems), variables: { 'checkoutId': checkoutId, 'checkoutLineItems': checkoutLineItems, }); final QueryResult result = await _graphQLClient.mutate(_options); checkForError(result); - if(deleteThisPartOfCache) { + if (deleteThisPartOfCache) { _graphQLClient.cache.write(_options.toKey(), null); } } @@ -140,8 +155,7 @@ class ShopifyCheckout with ShopifyError{ String phone, String province, String zip, - {bool deleteThisPartOfCache = false} - ) async { + {bool deleteThisPartOfCache = false}) async { final MutationOptions _options = MutationOptions( documentNode: gql(checkoutShippingAddressUpdateMutation), variables: { @@ -158,8 +172,9 @@ class ShopifyCheckout with ShopifyError{ 'zip': zip }); final QueryResult result = await _graphQLClient.mutate(_options); - checkForError(result, key: 'checkoutShippingAddressUpdateV2', errorKey:'checkoutUserErrors'); - if(deleteThisPartOfCache) { + checkForError(result, + key: 'checkoutShippingAddressUpdateV2', errorKey: 'checkoutUserErrors'); + if (deleteThisPartOfCache) { _graphQLClient.cache.write(_options.toKey(), null); } } @@ -167,19 +182,23 @@ class ShopifyCheckout with ShopifyError{ /// Helper method for transforming a list of variant ids into a List Of Map which looks like this: /// /// [{"quantity":AMOUNT,"variantId":"YOUR_VARIANT_ID"}] - List> transformVariantIdListIntoListOfMaps(List variantIdList){ + List> transformVariantIdListIntoListOfMaps( + List variantIdList) { List> lineItemList = []; - variantIdList.forEach((e){ - if(lineItemList.indexWhere((test) => e == test['variantId']) == -1) - lineItemList.add({"quantity": variantIdList.where((id) => e == id).toList().length,"variantId":e} - ); + variantIdList.forEach((e) { + if (lineItemList.indexWhere((test) => e == test['variantId']) == -1) + lineItemList.add({ + "quantity": variantIdList.where((id) => e == id).toList().length, + "variantId": e + }); }); return lineItemList; } /// Associates the [Customer] that [customerAccessToken] belongs to, to the [Checkout] that [checkoutId] belongs to. Future checkoutCustomerAssociate( - String checkoutId, String customerAccessToken, {bool deleteThisPartOfCache = false}) async { + String checkoutId, String customerAccessToken, + {bool deleteThisPartOfCache = false}) async { final MutationOptions _options = MutationOptions( documentNode: gql(associateCustomer), variables: { @@ -188,57 +207,60 @@ class ShopifyCheckout with ShopifyError{ }); final QueryResult result = await _graphQLClient.mutate(_options); checkForError(result); - if(deleteThisPartOfCache) { + if (deleteThisPartOfCache) { _graphQLClient.cache.write(_options.toKey(), null); } } /// Disassociates the [Customer] from the [Checkout] that [checkoutId] belongs to. - Future checkoutCustomerDisassociate(String checkoutId, {bool deleteThisPartOfCache = false}) async { + Future checkoutCustomerDisassociate(String checkoutId, + {bool deleteThisPartOfCache = false}) async { final MutationOptions _options = MutationOptions( documentNode: gql(checkoutCustomerDisassociateMutation), variables: {'id': checkoutId}); final QueryResult result = await _graphQLClient.mutate(_options); checkForError(result); - if(deleteThisPartOfCache) { + if (deleteThisPartOfCache) { _graphQLClient.cache.write(_options.toKey(), null); } } /// Applies [discountCode] to the [Checkout] that [checkoutId] belongs to. - Future checkoutDiscountCodeApply( - String checkoutId, String discountCode, {bool deleteThisPartOfCache = false}) async { + Future checkoutDiscountCodeApply(String checkoutId, String discountCode, + {bool deleteThisPartOfCache = false}) async { final MutationOptions _options = MutationOptions( documentNode: gql(checkoutDiscountCodeApplyMutation), variables: {'checkoutId': checkoutId, 'discountCode': discountCode}); final QueryResult result = await _graphQLClient.mutate(_options); checkForError(result); - if(deleteThisPartOfCache) { + if (deleteThisPartOfCache) { _graphQLClient.cache.write(_options.toKey(), null); } } /// Removes the applied discount from the [Checkout] that [checkoutId] belongs to. - Future checkoutDiscountCodeRemove(String checkoutId, {bool deleteThisPartOfCache = false}) async { + Future checkoutDiscountCodeRemove(String checkoutId, + {bool deleteThisPartOfCache = false}) async { final MutationOptions _options = MutationOptions( documentNode: gql(checkoutDiscountCodeRemoveMutation), variables: {'checkoutId': checkoutId}); QueryResult result = await _graphQLClient.mutate(_options); checkForError(result); - if(deleteThisPartOfCache) { + if (deleteThisPartOfCache) { _graphQLClient.cache.write(_options.toKey(), null); } } /// Appends the [giftCardCodes] to the [Checkout] that [checkoutId] belongs to. Future checkoutGiftCardAppend( - String checkoutId, List giftCardCodes, {bool deleteThisPartOfCache = false}) async { + String checkoutId, List giftCardCodes, + {bool deleteThisPartOfCache = false}) async { final MutationOptions _options = MutationOptions( documentNode: gql(checkoutGiftCardsAppendMutation), variables: {'checkoutId': checkoutId, 'giftCardCodes': giftCardCodes}); final QueryResult result = await _graphQLClient.mutate(_options); checkForError(result); - if(deleteThisPartOfCache) { + if (deleteThisPartOfCache) { _graphQLClient.cache.write(_options.toKey(), null); } } @@ -252,18 +274,17 @@ class ShopifyCheckout with ShopifyError{ ); final QueryResult result = await _graphQLClient.mutate(_options); checkForError(result); - if(deleteThisPartOfCache) { + if (deleteThisPartOfCache) { _graphQLClient.cache.write(_options.toKey(), null); } - return ((result?.data['checkoutCreate'] ?? - const {})['checkout'] ?? + return ((result?.data['checkoutCreate'] ?? const {})['checkout'] ?? const {})['id']; - } /// Removes the Gift card that [appliedGiftCardId] belongs to, from the [Checkout] that [checkoutId] belongs to. Future checkoutGiftCardRemove( - String appliedGiftCardId, String checkoutId, {bool deleteThisPartOfCache = false}) async { + String appliedGiftCardId, String checkoutId, + {bool deleteThisPartOfCache = false}) async { final MutationOptions _options = MutationOptions( documentNode: gql(checkoutGiftCardRemoveMutation), variables: { @@ -272,7 +293,7 @@ class ShopifyCheckout with ShopifyError{ }); final QueryResult result = await _graphQLClient.mutate(_options); checkForError(result); - if(deleteThisPartOfCache) { + if (deleteThisPartOfCache) { _graphQLClient.cache.write(_options.toKey(), null); } } @@ -307,4 +328,18 @@ class ShopifyCheckout with ShopifyError{ _graphQLClient.cache.write(_options.toKey(), null); } } + + Future emailUpdate(String checkoutId, String email, + {bool deleteThisPartOfCache = false}) async { + final MutationOptions _options = MutationOptions( + documentNode: gql(checkoutEmailUpdateMutation), + variables: {'checkoutId': checkoutId, 'email': email}); + final QueryResult result = await _graphQLClient.mutate(_options); + checkForError(result, + key: 'checkoutEmailUpdateV2', errorKey: 'checkoutUserErrors'); + print((result?.data as LazyCacheMap)?.data); + if (deleteThisPartOfCache) { + _graphQLClient.cache.write(_options.toKey(), null); + } + } } From c1f1a970dcbfafd963f97fbad7ab467af8bbd6da Mon Sep 17 00:00:00 2001 From: rupam4 Date: Tue, 10 Nov 2020 11:14:37 +0530 Subject: [PATCH 02/80] Products instead for List --- README.md | 6 +++--- lib/shopify/src/shopify_store.dart | 33 ++++++++++++++---------------- 2 files changed, 18 insertions(+), 21 deletions(-) diff --git a/README.md b/README.md index a959d252..6056d529 100644 --- a/README.md +++ b/README.md @@ -37,16 +37,16 @@ The goal is to make creating an mobile app from your Shopify website easier. ```dart ShopifyStore shopifyStore = ShopifyStore.instance; Future> getProductsByIds() - Future> getXProductsAfterCursor(int limit,String startCursor) + Future getXProductsAfterCursor(int limit,String startCursor) Future> getAllProducts() Future> getNProducts({@required int n, @required SortKey sortKey}) Future getShop() Future getFeaturedCollection() Future> getAllCollections() - Future> getXProductsAfterCursorWithinCollection(String id, int limit, String startCursor, SortKeyProduct sortKey) + Future getXProductsAfterCursorWithinCollection(String id, int limit, String startCursor, SortKeyProduct sortKey) Future> getAllProductsFromCollectionById(String id) Future> getAllProductsOnQuery(String cursor, SortKeyProduct sortKey, String query) - Future> getXProductsOnQueryAfterCursor(String cursor, int limit, SortKeyProduct sortKey, String query) + Future getXProductsOnQueryAfterCursor(String cursor, int limit, SortKeyProduct sortKey, String query) Future> getMetafieldsFromProduct(String productHandle, {String namespace}) ``` ```dart diff --git a/lib/shopify/src/shopify_store.dart b/lib/shopify/src/shopify_store.dart index ce794641..d21f8917 100644 --- a/lib/shopify/src/shopify_store.dart +++ b/lib/shopify/src/shopify_store.dart @@ -22,6 +22,7 @@ import '../../graphql_operations/queries/get_n_products.dart'; import '../../graphql_operations/queries/get_products.dart'; import '../../models/src/collection.dart'; import '../../shopify_config.dart'; +import 'dart:developer'; /// ShopifyStore provides various methods related to the shopify store. class ShopifyStore with ShopifyError{ @@ -60,30 +61,27 @@ class ShopifyStore with ShopifyError{ return productList; } - /// Returns a List of [Product]. + /// Returns [Products]. /// /// Returns the first [limit] Products after the given [startCursor]. /// [limit] has to be in the range of 0 and 250. - Future> getXProductsAfterCursor( + Future getXProductsAfterCursor( int limit, String startCursor, {bool deleteThisPartOfCache = false, bool reverse = false, SortKeyProduct sortKeyProduct = SortKeyProduct.TITLE}) async { - List productList = []; - Products tempProduct; String cursor = startCursor; final WatchQueryOptions _options = WatchQueryOptions( documentNode: gql(getXProductsAfterCursorQuery), variables: {'x': limit ?? 50, 'cursor': cursor, 'reverse': reverse, 'sortKey': sortKeyProduct.parseToString()}); final QueryResult result = await _graphQLClient.query(_options); checkForError(result); - tempProduct = (Products.fromJson( - (result?.data ?? - const {})["products"] ?? - {})); - productList += tempProduct?.productList ?? const []; + if(deleteThisPartOfCache) { _graphQLClient.cache.write(_options.toKey(), null); } - return productList; + return (Products.fromJson( + (result?.data ?? + const {})["products"] ?? + {})); } /// Returns a List of [Product]. @@ -333,11 +331,11 @@ class ShopifyStore with ShopifyError{ return productList; } - /// Returns a List of [Product]. + /// Returns [Products]. /// /// Returns the first [limit] Products after the given [startCursor]. /// [limit] has to be in the range of 0 and 250. - Future> getXProductsAfterCursorWithinCollection( + Future getXProductsAfterCursorWithinCollection( String id, int limit, String startCursor, {SortKeyProductCollection sortKey = SortKeyProductCollection.BEST_SELLING, bool deleteThisPartOfCache = false, bool reverse = false}) async { String cursor = startCursor; final WatchQueryOptions _options = WatchQueryOptions( @@ -356,8 +354,7 @@ class ShopifyStore with ShopifyError{ } return (Collection.fromJson( result?.data)) - .products - .productList; + .products; } /// Returns a List of [Product]. @@ -395,10 +392,10 @@ class ShopifyStore with ShopifyError{ return productList; } - /// Returns a List of [Product]. + /// Returns [Products]. /// /// Gets [limit] amount of [Product] from the [query] search, sorted by [sortKey]. - Future> getXProductsOnQueryAfterCursor( + Future getXProductsOnQueryAfterCursor( String query, int limit, String cursor, {SortKeyProduct sortKey, bool deleteThisPartOfCache = false, bool reverse = false}) async { final WatchQueryOptions _options = WatchQueryOptions( documentNode: gql(getXProductsOnQueryAfterCursorQuery), @@ -414,10 +411,10 @@ class ShopifyStore with ShopifyError{ if(deleteThisPartOfCache) { _graphQLClient.cache.write(_options.toKey(), null); } + return Products.fromJson( (result?.data ?? - const {})['products']) - ?.productList; + const {})['products']); } /// Returns a List of [Metafield]. From 465a47586429914e9f583d2886bbd732c0b9a988 Mon Sep 17 00:00:00 2001 From: rupam4 Date: Tue, 10 Nov 2020 11:48:52 +0530 Subject: [PATCH 03/80] getXOrdersAfterCursor --- README.md | 1 + example/lib/collection_tab.dart | 5 +- example/lib/home_tab.dart | 2 +- example/lib/search_tab.dart | 4 +- .../queries/get_x_orders_after_cursor.dart | 109 ++++++++++++++++++ lib/shopify/src/shopify_checkout.dart | 26 +++++ 6 files changed, 141 insertions(+), 6 deletions(-) create mode 100644 lib/graphql_operations/queries/get_x_orders_after_cursor.dart diff --git a/README.md b/README.md index 6056d529..53d828f6 100644 --- a/README.md +++ b/README.md @@ -54,6 +54,7 @@ The goal is to make creating an mobile app from your Shopify website easier. Future getCheckoutInfoQuery({String checkoutId}) Future getCheckoutInfoWithAvailableShippingRatesQuery({String checkoutId}) Future> getAllOrders({String customerAccessToken}) + Future getXOrdersAfterCursor({String customerAccessToken, int limit, String startCursor}) Future checkoutLineItemsReplace({String checkoutId, List> checkoutLineItems}) Future checkoutCustomerAssociate({String checkoutId, String customerAccessToken}) Future checkoutCustomerDisassociate({String checkoutId}) diff --git a/example/lib/collection_tab.dart b/example/lib/collection_tab.dart index 4c0447e2..8ff7a470 100644 --- a/example/lib/collection_tab.dart +++ b/example/lib/collection_tab.dart @@ -96,12 +96,11 @@ class _CollectionDetailScreenState extends State { final products = await shopifyStore.getXProductsAfterCursorWithinCollection( widget.collectionId, 4, - null, - SortKeyProduct.RELEVANCE, + null ); if(mounted){ setState(() { - this.products = products; + this.products = products.productList; _isLoading = false; }); } diff --git a/example/lib/home_tab.dart b/example/lib/home_tab.dart index e0059023..0348db6a 100644 --- a/example/lib/home_tab.dart +++ b/example/lib/home_tab.dart @@ -45,7 +45,7 @@ class _HomeTabState extends State { try { ShopifyStore shopifyStore = ShopifyStore.instance; final List bestSellingProducts = await shopifyStore - .getNProducts(false, n: 6, sortKey: SortKeyProduct.BEST_SELLING); + .getNProducts(6, sortKey: SortKeyProduct.BEST_SELLING); if (mounted) { setState(() { products = bestSellingProducts; diff --git a/example/lib/search_tab.dart b/example/lib/search_tab.dart index 8aab4fc7..180db389 100644 --- a/example/lib/search_tab.dart +++ b/example/lib/search_tab.dart @@ -61,10 +61,10 @@ class _SearchTabState extends State { try { ShopifyStore shopifyStore = ShopifyStore.instance; final products = await shopifyStore.getXProductsOnQueryAfterCursor( - null, 4, SortKeyProduct.RELEVANCE, searchKeyword); + null, 4, searchKeyword); if (mounted) { setState(() { - this.products = products; + this.products = products.productList; _isLoading = false; }); } diff --git a/lib/graphql_operations/queries/get_x_orders_after_cursor.dart b/lib/graphql_operations/queries/get_x_orders_after_cursor.dart new file mode 100644 index 00000000..6ea0e5b9 --- /dev/null +++ b/lib/graphql_operations/queries/get_x_orders_after_cursor.dart @@ -0,0 +1,109 @@ +const String getXOrdersAfterCursorQuery = r''' +query getOrders($cursor : String, $x : Int,$sortKey : OrderSortKeys, $accessToken : String!, $reverse: Boolean){ +customer(customerAccessToken: $accessToken) { + orders(first: $x, after: $cursor, sortKey: $sortKey, reverse: $reverse) { + pageInfo { + hasNextPage + } + edges { + node { + id + email + currencyCode + customerUrl + lineItems(first: 250) { + edges { + node { + currentQuantity + discountAllocations { + allocatedAmount { + amount + currencyCode + } + } + discountedTotalPrice { + amount + currencyCode + } + originalTotalPrice { + amount + currencyCode + } + quantity + title + variant { + priceV2 { + amount + currencyCode + } + title + image { + altText + id + originalSrc + } + compareAtPriceV2 { + amount + currencyCode + } + weight + weightUnit + availableForSale + sku + requiresShipping + id + } + } + } + } + name + orderNumber + phone + processedAt + shippingAddress { + address1 + address2 + city + company + country + countryCodeV2 + firstName + id + lastName + latitude + longitude + name + phone + province + provinceCode + zip + } + statusUrl + subtotalPriceV2 { + amount + currencyCode + } + totalPriceV2 { + amount + currencyCode + } + totalRefundedV2 { + amount + currencyCode + } + totalShippingPriceV2 { + amount + currencyCode + } + totalTaxV2 { + amount + currencyCode + } + } + cursor + } + } + id + } +} +'''; \ No newline at end of file diff --git a/lib/shopify/src/shopify_checkout.dart b/lib/shopify/src/shopify_checkout.dart index 0699b757..db318ac7 100644 --- a/lib/shopify/src/shopify_checkout.dart +++ b/lib/shopify/src/shopify_checkout.dart @@ -123,6 +123,32 @@ class ShopifyCheckout with ShopifyError { return orders.orderList; } + Future getXOrdersAfterCursor( + String customerAccessToken, int limit, String startCursor, + {SortKeyOrder sortKey = SortKeyOrder.ID, + bool reverse = true, + bool deleteThisPartOfCache = false}) async { + String cursor = startCursor; + final QueryOptions _options = + WatchQueryOptions(documentNode: gql(getAllOrdersQuery), variables: { + 'accessToken': customerAccessToken, + 'sortKey': sortKey.parseToString(), + 'reverse': reverse, + 'cursor': cursor, + 'x': limit + }); + final QueryResult result = + await ShopifyConfig.graphQLClient.query(_options); + checkForError(result); + Orders orders = Orders.fromJson( + ((((result?.data ?? const {}))['customer'] ?? const {})['orders'] ?? + const {})); + if (deleteThisPartOfCache) { + _graphQLClient.cache.write(_options.toKey(), null); + } + return orders; + } + /// Replaces the [LineItems] in the [Checkout] associated to the [checkoutId]. /// /// [checkoutLineItems] is a List of Variant Ids From 63350e80455176cbdb1ceedb32a6db2e91bb62ab Mon Sep 17 00:00:00 2001 From: rupam4 Date: Thu, 12 Nov 2020 15:23:47 +0530 Subject: [PATCH 04/80] getXOrdersAfterCursorQuery --- lib/shopify/src/shopify_checkout.dart | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/shopify/src/shopify_checkout.dart b/lib/shopify/src/shopify_checkout.dart index db318ac7..45d024a1 100644 --- a/lib/shopify/src/shopify_checkout.dart +++ b/lib/shopify/src/shopify_checkout.dart @@ -7,6 +7,7 @@ import 'package:flutter_simple_shopify/graphql_operations/queries/get_checkout_i import 'package:flutter_simple_shopify/graphql_operations/queries/get_checkout_info_requires_shipping.dart'; import 'package:flutter_simple_shopify/graphql_operations/queries/get_checkout_information_with_shipping_rate.dart'; import 'package:flutter_simple_shopify/graphql_operations/queries/get_checkout_without_shipping_rates.dart'; +import 'package:flutter_simple_shopify/graphql_operations/queries/get_x_orders_after_cursor.dart'; import 'package:flutter_simple_shopify/mixins/src/shopfiy_error.dart'; import 'package:flutter_simple_shopify/models/src/order.dart'; import 'package:graphql/client.dart'; @@ -130,7 +131,7 @@ class ShopifyCheckout with ShopifyError { bool deleteThisPartOfCache = false}) async { String cursor = startCursor; final QueryOptions _options = - WatchQueryOptions(documentNode: gql(getAllOrdersQuery), variables: { + WatchQueryOptions(documentNode: gql(getXOrdersAfterCursorQuery), variables: { 'accessToken': customerAccessToken, 'sortKey': sortKey.parseToString(), 'reverse': reverse, From f263e66a35a9832be4fbc3ff67e03239eae7d7f2 Mon Sep 17 00:00:00 2001 From: rupam4 Date: Fri, 13 Nov 2020 16:54:44 +0530 Subject: [PATCH 05/80] product variants selectedOptions --- .../queries/get_products_by_ids.dart | 6 +- lib/models/src/product.dart | 66 +++++++++++++++++-- 2 files changed, 67 insertions(+), 5 deletions(-) diff --git a/lib/graphql_operations/queries/get_products_by_ids.dart b/lib/graphql_operations/queries/get_products_by_ids.dart index 2cc9a629..859a9272 100644 --- a/lib/graphql_operations/queries/get_products_by_ids.dart +++ b/lib/graphql_operations/queries/get_products_by_ids.dart @@ -6,7 +6,7 @@ query($ids : [ID!]!){ id name values - } + } id handle collections(first: 250) { @@ -59,6 +59,10 @@ query($ids : [ID!]!){ requiresShipping id quantityAvailable + selectedOptions { + name + value + } } } } diff --git a/lib/models/src/product.dart b/lib/models/src/product.dart index a74dc5a2..1547fc6f 100644 --- a/lib/models/src/product.dart +++ b/lib/models/src/product.dart @@ -1,3 +1,5 @@ +import 'package:collection/collection.dart'; + class Products { final List productList; final bool hasNextPage; @@ -35,7 +37,7 @@ class Product { final String updatedAt; final String cursor; final List images; - final List