diff --git a/README.md b/README.md index fd5dff3f..23b1ee36 100644 --- a/README.md +++ b/README.md @@ -47,23 +47,34 @@ 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 getProductByHandle(String handle, + {bool deleteThisPartOfCache = false}) + 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 getCollectionByHandle(String handle, + {bool deleteThisPartOfCache = false}) + Future getXProductsAfterCursorWithinCollection(String id, int limit, String startCursor, SortKeyProduct sortKey) + Future getXProductsAfterCursorByCollectionHandle( + String handle, int limit, String? startCursor, + {bool deleteThisPartOfCache = false, + bool reverse = false, + SortKeyProductCollection sortKeyProductCollection = SortKeyProductCollection.RELEVANCE}) 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}) + Future getPageByHandle(String handle) ``` ```dart ShopifyCheckout shopifyCheckout = ShopifyCheckout.instance; 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 deleted file mode 100644 index 4c0447e2..00000000 --- a/example/lib/collection_tab.dart +++ /dev/null @@ -1,113 +0,0 @@ -import 'package:flutter/material.dart'; -import 'package:flutter_simple_shopify/flutter_simple_shopify.dart'; - -class CollectionTab extends StatefulWidget { - @override - _CollectionTabState createState() => _CollectionTabState(); -} - -class _CollectionTabState extends State { - List collections = []; - bool _isLoading = true; - - @override - void initState() { - _fetchCollections(); - super.initState(); - } - - @override - Widget build(BuildContext context) { - return Scaffold( - appBar: AppBar(title: Text("Collections")), - body: Center( - child: _isLoading ? CircularProgressIndicator() : - ListView.builder( - itemCount: collections.length, - itemBuilder: (_,int index) => ListTile( - onTap: () => _navigateToCollectionDetailScreen(collections[index].id,collections[index].title), - title: Text(collections[index].title), - ), - ), - ), - ); - } - - Future _fetchCollections() async { - try{ - ShopifyStore shopifyStore = ShopifyStore.instance; - final collections = await shopifyStore.getAllCollections(); - if(mounted){ - setState(() { - this.collections = collections; - _isLoading = false; - }); - } - }catch(e){ - print(e); - } - } - - void _navigateToCollectionDetailScreen(String collectionId,String collectionTitle){ - Navigator.push(context, MaterialPageRoute( - builder: (context) => CollectionDetailScreen( - collectionId: collectionId, - collectionTitle: collectionTitle))); - } -} - -class CollectionDetailScreen extends StatefulWidget { - final String collectionId; - final String collectionTitle; - - const CollectionDetailScreen({Key key,@required this.collectionId,@required this.collectionTitle}) - : super(key: key); - @override - _CollectionDetailScreenState createState() => _CollectionDetailScreenState(); -} - -class _CollectionDetailScreenState extends State { - List products = []; - bool _isLoading = true; - - @override - void initState() { - _fetchProductsByCollectionId(); - super.initState(); - } - - @override - Widget build(BuildContext context) { - return Scaffold( - appBar: AppBar(title: Text(widget.collectionTitle),), - body: Center( - child: _isLoading ? CircularProgressIndicator() : - ListView.builder( - itemCount: products.length, - itemBuilder: (_,int index) => - ListTile(title: Text(products[index].title),)), - ), - ); - } - - Future _fetchProductsByCollectionId() async{ - try{ - ShopifyStore shopifyStore = ShopifyStore.instance; - final products = await shopifyStore.getXProductsAfterCursorWithinCollection( - widget.collectionId, - 4, - null, - SortKeyProduct.RELEVANCE, - ); - if(mounted){ - setState(() { - this.products = products; - _isLoading = false; - }); - } - }catch(e){ - print(e); - } - } -} - diff --git a/example/lib/home_tab.dart b/example/lib/home_tab.dart deleted file mode 100644 index e0059023..00000000 --- a/example/lib/home_tab.dart +++ /dev/null @@ -1,88 +0,0 @@ -import 'package:flutter/material.dart'; -import 'package:flutter_simple_shopify/flutter_simple_shopify.dart'; -import 'product_detail_screen.dart'; - -class HomeTab extends StatefulWidget { - @override - _HomeTabState createState() => _HomeTabState(); -} - -class _HomeTabState extends State { - List products = []; - bool _isLoading = true; - - @override - void initState() { - _fetchProducts(); - super.initState(); - } - - @override - Widget build(BuildContext context) { - return Scaffold( - appBar: AppBar( - title: const Text("Home"), - ), - body: Center( - child: _isLoading - ? CircularProgressIndicator() - : GridView.builder( - padding: const EdgeInsets.all(8), - gridDelegate: SliverGridDelegateWithFixedCrossAxisCount( - crossAxisCount: 2, - mainAxisSpacing: 8, - crossAxisSpacing: 8, - ), - itemCount: products.length, - itemBuilder: (_, int index) => - _buildProductThumbnail(products[index]), - ), - ), - ); - } - - Future _fetchProducts() async { - try { - ShopifyStore shopifyStore = ShopifyStore.instance; - final List bestSellingProducts = await shopifyStore - .getNProducts(false, n: 6, sortKey: SortKeyProduct.BEST_SELLING); - if (mounted) { - setState(() { - products = bestSellingProducts; - _isLoading = false; - }); - } - } catch (e) { - print(e); - } - } - - Widget _buildProductThumbnail(Product product) { - return InkWell( - onTap: () => _navigateToProductDetailScreen(product), - child: Container( - alignment: Alignment.bottomCenter, - width: MediaQuery.of(context).size.width, - height: MediaQuery.of(context).size.height, - decoration: product?.images?.first?.originalSource != null - ? BoxDecoration( - image: DecorationImage( - fit: BoxFit.cover, - image: NetworkImage( - product.images.first.originalSource, - ))) - : BoxDecoration(), - child: Container( - width: MediaQuery.of(context).size.width, - alignment: Alignment.bottomCenter, - child: Text(product.title,style: TextStyle(color: Colors.white,fontSize: 20,fontWeight: FontWeight.bold),), - ), - ), - ); - } - - void _navigateToProductDetailScreen(Product product) { - Navigator.push(context, - MaterialPageRoute(builder: (context) => ProductDetailScreen(product: product,))); - } -} diff --git a/example/lib/main.dart b/example/lib/main.dart deleted file mode 100644 index 1c190276..00000000 --- a/example/lib/main.dart +++ /dev/null @@ -1,73 +0,0 @@ -import 'package:flutter/material.dart'; -import 'package:flutter_simple_shopify/flutter_simple_shopify.dart'; -import 'collection_tab.dart'; -import 'home_tab.dart'; -import 'profile_tab.dart'; -import 'search_tab.dart'; - -void main() { - ShopifyConfig.setConfig( - "STOREFRONT-API-ACCESS-TOKEN", - "YOUR-SHOPIFY-WEBSITE", - "2020-04", - ); - runApp(MyApp()); -} - -class MyApp extends StatelessWidget { - @override - Widget build(BuildContext context) { - return MaterialApp( - title: 'Shopify Example', - theme: ThemeData(primaryColor: Colors.redAccent), - home: MyHomePage(), - ); - } -} - -class MyHomePage extends StatefulWidget { - @override - _MyHomePageState createState() => _MyHomePageState(); -} - -class _MyHomePageState extends State { - int _currentIndex = 0; - - final _tabs = [ - HomeTab(), - CollectionTab(), - SearchTab(), - ProfileTab(), - ]; - - @override - Widget build(BuildContext context) { - return Scaffold( - body: IndexedStack( - index: _currentIndex, - children: _tabs, - ), - bottomNavigationBar: BottomNavigationBar( - currentIndex: _currentIndex, - onTap: _onNavigationBarItemClick, - fixedColor: Theme.of(context).primaryColor, - unselectedItemColor: Colors.black, - items: [ - BottomNavigationBarItem(icon: Icon(Icons.home), title: Text("Home")), - BottomNavigationBarItem( - icon: Icon(Icons.category), title: Text("Collections")), - BottomNavigationBarItem( - icon: Icon(Icons.search), title: Text("Search")), - BottomNavigationBarItem( - icon: Icon(Icons.person), title: Text("Profile")), - ], - ), - ); - } - - void _onNavigationBarItemClick(int index) { - setState(() { - _currentIndex = index; - }); - } -} diff --git a/example/lib/product_detail_screen.dart b/example/lib/product_detail_screen.dart deleted file mode 100644 index 1c55157f..00000000 --- a/example/lib/product_detail_screen.dart +++ /dev/null @@ -1,54 +0,0 @@ -import 'package:flutter/material.dart'; -import 'package:flutter_simple_shopify/flutter_simple_shopify.dart'; - -class ProductDetailScreen extends StatefulWidget { - final Product product; - - const ProductDetailScreen({Key key,@required this.product}) : super(key: key); - @override - _ProductDetailScreenState createState() => _ProductDetailScreenState(product); -} - -class _ProductDetailScreenState extends State { - final Product product; - - _ProductDetailScreenState(this.product); - - @override - Widget build(BuildContext context) { - return Scaffold( - appBar: AppBar(title: Text(product.title),), - body: ListView( - children: [ - product?.images?.first?.originalSource != null ? - Image.network(product.images.first.originalSource, - width: MediaQuery.of(context).size.width, - height: MediaQuery.of(context).size.height/3, - fit: BoxFit.cover, - ) : - Container(), - Column(children: _buildProductVariants(),) - ], - ), - ); - } - - List _buildProductVariants(){ - List widgetList = []; - product.productVariants.forEach( - (variant) => widgetList.add(ListTile( - title: Text(variant.title), - trailing: Text(variant.price.formattedPrice), - ))); - return widgetList; - } - - ///Adds a product variant to the checkout - Future _addProductToShoppingCart(ProductVariant variant)async{ - ShopifyCheckout shopifyCheckout = ShopifyCheckout.instance; - String checkoutId = await shopifyCheckout.createCheckout(); - print(checkoutId); - //Adds a product variant to a specific checkout id - await shopifyCheckout.checkoutLineItemsReplace(checkoutId, [variant.id]); - } -} diff --git a/example/lib/profile_tab.dart b/example/lib/profile_tab.dart deleted file mode 100644 index dc7e135d..00000000 --- a/example/lib/profile_tab.dart +++ /dev/null @@ -1,15 +0,0 @@ -import 'package:flutter/material.dart'; - -class ProfileTab extends StatefulWidget { - @override - _ProfileTabState createState() => _ProfileTabState(); -} - -class _ProfileTabState extends State { - @override - Widget build(BuildContext context) { - return Scaffold( - appBar: AppBar(title: Text("Profile"),), - ); - } -} diff --git a/example/lib/search_tab.dart b/example/lib/search_tab.dart deleted file mode 100644 index 8aab4fc7..00000000 --- a/example/lib/search_tab.dart +++ /dev/null @@ -1,83 +0,0 @@ -import 'package:flutter/material.dart'; -import 'package:flutter_simple_shopify/flutter_simple_shopify.dart'; - -class SearchTab extends StatefulWidget { - @override - _SearchTabState createState() => _SearchTabState(); -} - -class _SearchTabState extends State { - final _controller = TextEditingController(text: ""); - List products = []; - bool _isLoading = false; - - @override - Widget build(BuildContext context) { - return Scaffold( - appBar: AppBar( - title: Text("Search"), - ), - body: Padding( - padding: const EdgeInsets.all(8.0), - child: Column( - children: [ - Row( - children: [ - Expanded( - child: TextFormField( - controller: _controller, - decoration: InputDecoration( - labelText: "Search...", - fillColor: Colors.white, - border: OutlineInputBorder( - borderRadius: BorderRadius.circular(12.0), - borderSide: BorderSide(), - ), - //fillColor: Colors.green - )), - ), - Padding(padding: const EdgeInsets.all(8)), - IconButton( - icon: Icon(Icons.search), - onPressed: () => _searchForProduct(_controller.text)), - ], - ), - Padding(padding: const EdgeInsets.all(10)), - Center( - child: _isLoading ? CircularProgressIndicator() : Column( - children: _buildProductList(), - ), - ) - ], - ), - ), - ); - } - - Future _searchForProduct(String searchKeyword) async { - setState(() { - _isLoading = true; - }); - try { - ShopifyStore shopifyStore = ShopifyStore.instance; - final products = await shopifyStore.getXProductsOnQueryAfterCursor( - null, 4, SortKeyProduct.RELEVANCE, searchKeyword); - if (mounted) { - setState(() { - this.products = products; - _isLoading = false; - }); - } - } catch (e) { - print(e); - } - } - - List _buildProductList() { - List widgetList = []; - products.forEach((product) => widgetList.add(ListTile( - title: Text(product.title), - ))); - return widgetList; - } -} diff --git a/lib/enums/enums.dart b/lib/enums/enums.dart index 1bba996b..6c47064b 100644 --- a/lib/enums/enums.dart +++ b/lib/enums/enums.dart @@ -2,4 +2,5 @@ export 'src/sort_key_product.dart'; export 'src/sort_key_article.dart'; export 'src/sort_key_order.dart'; export 'src/sort_key_blog.dart'; -export 'src/sort_key_product_collection.dart'; \ No newline at end of file +export 'src/sort_key_product_collection.dart'; +export 'src/order_enums.dart'; \ No newline at end of file diff --git a/lib/enums/src/order_enums.dart b/lib/enums/src/order_enums.dart new file mode 100644 index 00000000..baf5b62f --- /dev/null +++ b/lib/enums/src/order_enums.dart @@ -0,0 +1,43 @@ +enum OrderCancelReason { + CUSTOMER, + DECLINED, + FRAUD, + INVENTORY, + OTHER, +} +extension ParseToStringOrderCancelReason on OrderCancelReason{ + String parseToString(){ + return this.toString().split('.')[1]; + } +} + +enum OrderFulfillmentStatus { + FULFILLED, + IN_PROGRESS, + OPEN, + PARTIALLY_FULFILLED, + PENDING_FULFILLMENT, + RESTOCKED, + UNFULFILLED, +} +extension ParseToStringOrderFulfillmentStatus on OrderFulfillmentStatus{ + String parseToString(){ + return this.toString().split('.')[1]; + } +} + +enum OrderFinancialStatus { + AUTHORIZED, + PAID, + PARTIALLY_PAID, + PARTIALLY_REFUNDED, + PENDING, + REFUNDED, + VOIDED, +} +extension ParseToStringOrderFinancialStatus on OrderFinancialStatus{ + String parseToString(){ + return this.toString().split('.')[1]; + } +} + diff --git a/lib/enums/src/sort_key_product.dart b/lib/enums/src/sort_key_product.dart index 349a19d1..eb3dee63 100644 --- a/lib/enums/src/sort_key_product.dart +++ b/lib/enums/src/sort_key_product.dart @@ -10,7 +10,7 @@ enum SortKeyProduct { RELEVANCE, } -extension ParseToStringProduct on SortKeyProduct{ +extension ParseToStringProduct on SortKeyProduct?{ String parseToString(){ return this.toString().split('.')[1]; } diff --git a/lib/graphql_operations/mutations/checkout_discount_code_apply.dart b/lib/graphql_operations/mutations/checkout_discount_code_apply.dart index ef3001b1..95a16fe1 100644 --- a/lib/graphql_operations/mutations/checkout_discount_code_apply.dart +++ b/lib/graphql_operations/mutations/checkout_discount_code_apply.dart @@ -1,6 +1,95 @@ const String checkoutDiscountCodeApplyMutation = r''' -mutation checkoutDiscountCodeApply($checkoutId : ID!, $discountCode : String!) { - checkoutDiscountCodeApplyV2(checkoutId: $checkoutId, discountCode: $discountCode) { +mutation checkoutDiscountCodeApplyV2($checkoutId: ID!, $discountCode: String!) { + checkoutDiscountCodeApplyV2( + checkoutId: $checkoutId + discountCode: $discountCode + ) { + checkout { + id + email + requiresShipping + currencyCode + webUrl + orderStatusUrl + shippingLine { + handle + title + priceV2 { + amount + currencyCode + } + } + shippingAddress { + address1 + address2 + city + company + country + countryCodeV2 + firstName + formattedArea + id + lastName + latitude + longitude + name + phone + province + provinceCode + zip + } + appliedGiftCards { + amountUsedV2 { + amount + currencyCode + } + balanceV2 { + amount + currencyCode + } + lastCharacters + id + } + discountApplications(first: 10) { + edges { + node { + allocationMethod + targetSelection + targetType + value { + ... on MoneyV2 { + amount + currencyCode + } + ... on PricingPercentageValue { + percentage + } + } + } + } + } + lineItemsSubtotalPrice { + amount + currencyCode + } + paymentDueV2 { + amount + currencyCode + } + taxesIncluded + totalTaxV2 { + amount + currencyCode + } + totalPriceV2 { + amount + currencyCode + } + subtotalPriceV2 { + amount + currencyCode + } + } checkoutUserErrors { message field @@ -8,4 +97,5 @@ mutation checkoutDiscountCodeApply($checkoutId : ID!, $discountCode : String!) { } } } + '''; \ No newline at end of file diff --git a/lib/graphql_operations/mutations/checkout_discount_code_remove.dart b/lib/graphql_operations/mutations/checkout_discount_code_remove.dart index a95ce956..065331a9 100644 --- a/lib/graphql_operations/mutations/checkout_discount_code_remove.dart +++ b/lib/graphql_operations/mutations/checkout_discount_code_remove.dart @@ -1,6 +1,92 @@ const String checkoutDiscountCodeRemoveMutation = r''' mutation checkoutDiscountCodeRemove($checkoutId : ID!) { checkoutDiscountCodeRemove(checkoutId: $checkoutId) { + checkout { + id + email + requiresShipping + currencyCode + webUrl + orderStatusUrl + shippingLine { + handle + title + priceV2 { + amount + currencyCode + } + } + shippingAddress { + address1 + address2 + city + company + country + countryCodeV2 + firstName + formattedArea + id + lastName + latitude + longitude + name + phone + province + provinceCode + zip + } + appliedGiftCards { + amountUsedV2 { + amount + currencyCode + } + balanceV2 { + amount + currencyCode + } + lastCharacters + id + } + discountApplications(first: 10) { + edges { + node { + allocationMethod + targetSelection + targetType + value { + ... on MoneyV2 { + amount + currencyCode + } + ... on PricingPercentageValue { + percentage + } + } + } + } + } + lineItemsSubtotalPrice { + amount + currencyCode + } + paymentDueV2 { + amount + currencyCode + } + taxesIncluded + totalTaxV2 { + amount + currencyCode + } + totalPriceV2 { + amount + currencyCode + } + subtotalPriceV2 { + amount + currencyCode + } + } checkoutUserErrors { code field diff --git a/lib/graphql_operations/mutations/checkout_email_update.dart b/lib/graphql_operations/mutations/checkout_email_update.dart index 50ec5062..d18e2e5c 100644 --- a/lib/graphql_operations/mutations/checkout_email_update.dart +++ b/lib/graphql_operations/mutations/checkout_email_update.dart @@ -1,9 +1,98 @@ const String checkoutEmailUpdateMutation = r''' -mutation checkoutEmailUpdate($checkoutId : ID!, $email : String!) { +mutation checkoutEmailUpdate($checkoutId: ID!, $email: String!) { checkoutEmailUpdateV2(checkoutId: $checkoutId, email: $email) { + checkout { + id + email + requiresShipping + currencyCode + webUrl + orderStatusUrl + shippingLine { + handle + title + priceV2 { + amount + currencyCode + } + } + shippingAddress { + address1 + address2 + city + company + country + countryCodeV2 + firstName + formattedArea + id + lastName + latitude + longitude + name + phone + province + provinceCode + zip + } + appliedGiftCards { + amountUsedV2 { + amount + currencyCode + } + balanceV2 { + amount + currencyCode + } + lastCharacters + id + } + discountApplications(first: 10) { + edges { + node { + allocationMethod + targetSelection + targetType + value { + ... on MoneyV2 { + amount + currencyCode + } + ... on PricingPercentageValue { + percentage + } + } + } + } + } + lineItemsSubtotalPrice { + amount + currencyCode + } + paymentDueV2 { + amount + currencyCode + } + taxesIncluded + totalTaxV2 { + amount + currencyCode + } + totalPriceV2 { + amount + currencyCode + } + subtotalPriceV2 { + amount + currencyCode + } + } checkoutUserErrors { code + field + message } } } + '''; \ No newline at end of file diff --git a/lib/graphql_operations/mutations/checkout_giftcard_remove.dart b/lib/graphql_operations/mutations/checkout_giftcard_remove.dart index 3ba29833..b8977a2b 100644 --- a/lib/graphql_operations/mutations/checkout_giftcard_remove.dart +++ b/lib/graphql_operations/mutations/checkout_giftcard_remove.dart @@ -1,6 +1,92 @@ const String checkoutGiftCardRemoveMutation = r''' -mutation checkoutGiftCard($appliedGiftCardId : ID!, $checkoutId: ID!) { +mutation checkoutGiftCardRemoveV2($appliedGiftCardId: ID!, $checkoutId: ID!) { checkoutGiftCardRemoveV2(appliedGiftCardId: $appliedGiftCardId, checkoutId: $checkoutId) { + checkout { + id + email + requiresShipping + currencyCode + webUrl + orderStatusUrl + shippingLine { + handle + title + priceV2 { + amount + currencyCode + } + } + shippingAddress { + address1 + address2 + city + company + country + countryCodeV2 + firstName + formattedArea + id + lastName + latitude + longitude + name + phone + province + provinceCode + zip + } + appliedGiftCards { + amountUsedV2 { + amount + currencyCode + } + balanceV2 { + amount + currencyCode + } + lastCharacters + id + } + discountApplications(first: 10) { + edges { + node { + allocationMethod + targetSelection + targetType + value { + ... on MoneyV2 { + amount + currencyCode + } + ... on PricingPercentageValue { + percentage + } + } + } + } + } + lineItemsSubtotalPrice { + amount + currencyCode + } + paymentDueV2 { + amount + currencyCode + } + taxesIncluded + totalTaxV2 { + amount + currencyCode + } + totalPriceV2 { + amount + currencyCode + } + subtotalPriceV2 { + amount + currencyCode + } + } checkoutUserErrors { code field diff --git a/lib/graphql_operations/mutations/checkout_giftcards_append.dart b/lib/graphql_operations/mutations/checkout_giftcards_append.dart index d3077b9a..adb8a49e 100644 --- a/lib/graphql_operations/mutations/checkout_giftcards_append.dart +++ b/lib/graphql_operations/mutations/checkout_giftcards_append.dart @@ -1,6 +1,92 @@ const String checkoutGiftCardsAppendMutation = r''' mutation checkoutGiftCardsAppend($checkoutId : ID!, $giftCardCodes : [String!]!) { checkoutGiftCardsAppend(checkoutId: $checkoutId, giftCardCodes: $giftCardCodes) { + checkout { + id + email + requiresShipping + currencyCode + webUrl + orderStatusUrl + shippingLine { + handle + title + priceV2 { + amount + currencyCode + } + } + shippingAddress { + address1 + address2 + city + company + country + countryCodeV2 + firstName + formattedArea + id + lastName + latitude + longitude + name + phone + province + provinceCode + zip + } + appliedGiftCards { + amountUsedV2 { + amount + currencyCode + } + balanceV2 { + amount + currencyCode + } + lastCharacters + id + } + discountApplications(first: 10) { + edges { + node { + allocationMethod + targetSelection + targetType + value { + ... on MoneyV2 { + amount + currencyCode + } + ... on PricingPercentageValue { + percentage + } + } + } + } + } + lineItemsSubtotalPrice { + amount + currencyCode + } + paymentDueV2 { + amount + currencyCode + } + taxesIncluded + totalTaxV2 { + amount + currencyCode + } + totalPriceV2 { + amount + currencyCode + } + subtotalPriceV2 { + amount + currencyCode + } + } checkoutUserErrors { code field diff --git a/lib/graphql_operations/mutations/checkout_shipping_address_update.dart b/lib/graphql_operations/mutations/checkout_shipping_address_update.dart index 3b391bd9..cc684e01 100644 --- a/lib/graphql_operations/mutations/checkout_shipping_address_update.dart +++ b/lib/graphql_operations/mutations/checkout_shipping_address_update.dart @@ -1,11 +1,168 @@ const String checkoutShippingAddressUpdateMutation = r''' -mutation checkoutShippingAddressUpdate($checkoutId : ID!, $address1 : String, $address2 : String, $company : String, $city : String, $country : String, $firstName: String, $lastName : String, $phone : String, $province : String, $zip : String) { - checkoutShippingAddressUpdateV2(checkoutId: $checkoutId, shippingAddress: {address1: $address1, address2: $address2, company: $company, city: $city, country: $country, firstName: $firstName, lastName: $lastName, phone: $phone, province: $province, zip: $zip}) { - checkoutUserErrors { +mutation checkoutShippingAddressUpdateV2( + $checkoutId: ID! + $address1: String + $address2: String + $company: String + $city: String + $country: String + $firstName: String + $lastName: String + $phone: String + $province: String + $zip: String +) { + checkoutShippingAddressUpdateV2( + checkoutId: $checkoutId + shippingAddress: { + address1: $address1 + address2: $address2 + company: $company + city: $city + country: $country + firstName: $firstName + lastName: $lastName + phone: $phone + province: $province + zip: $zip + } + ) { + checkout { + id + email + requiresShipping + currencyCode + webUrl + orderStatusUrl + shippingLine { + handle + title + priceV2 { + amount + currencyCode + } + } + availableShippingRates { + ready + shippingRates { + handle + title + priceV2 { + amount + currencyCode + } + } + } + shippingAddress { + address1 + address2 + city + company + country + countryCodeV2 + firstName + formattedArea + id + lastName + latitude + longitude + name + phone + province + provinceCode + zip + } + lineItems(first: 10) { + edges { + node { + id + quantity + title + variant { + id + priceV2 { + amount + currencyCode + } + title + image { + altText + originalSrc + transformedSrc(maxWidth: 400, crop: CENTER) + id + } + compareAtPriceV2 { + amount + currencyCode + } + weight + weightUnit + availableForSale + sku + requiresShipping + } + } + } + } + appliedGiftCards { + amountUsedV2 { + amount + currencyCode + } + balanceV2 { + amount + currencyCode + } + lastCharacters + id + } + discountApplications(first: 10) { + edges { + node { + allocationMethod + targetSelection + targetType + value { + ... on MoneyV2 { + amount + currencyCode + } + ... on PricingPercentageValue { + percentage + } + } + } + } + } + lineItemsSubtotalPrice { + amount + currencyCode + } + paymentDueV2 { + amount + currencyCode + } + taxesIncluded + totalTaxV2 { + amount + currencyCode + } + totalPriceV2 { + amount + currencyCode + } + subtotalPriceV2 { + amount + currencyCode + } + } + checkoutUserErrors { code field message } } -}'''; +} + +'''; diff --git a/lib/graphql_operations/mutations/checkout_shipping_line_update.dart b/lib/graphql_operations/mutations/checkout_shipping_line_update.dart index 2366b302..624eb953 100644 --- a/lib/graphql_operations/mutations/checkout_shipping_line_update.dart +++ b/lib/graphql_operations/mutations/checkout_shipping_line_update.dart @@ -1,8 +1,140 @@ const String checkoutShippingLineUpdateMutation = r''' -mutation checkoutShippingLineUpdate($checkoutId: ID!, $shippingRateHandle: String!) { - checkoutShippingLineUpdate(checkoutId: $checkoutId, shippingRateHandle: $shippingRateHandle) { +mutation checkoutShippingLineUpdate( + $checkoutId: ID! + $shippingRateHandle: String! +) { + checkoutShippingLineUpdate( + checkoutId: $checkoutId + shippingRateHandle: $shippingRateHandle + ) { checkout { id + email + requiresShipping + currencyCode + webUrl + orderStatusUrl + shippingLine { + handle + title + priceV2 { + amount + currencyCode + } + } + availableShippingRates { + ready + shippingRates { + handle + title + priceV2 { + amount + currencyCode + } + } + } + shippingAddress { + address1 + address2 + city + company + country + countryCodeV2 + firstName + formattedArea + id + lastName + latitude + longitude + name + phone + province + provinceCode + zip + } + lineItems(first: 10) { + edges { + node { + id + quantity + title + variant { + id + priceV2 { + amount + currencyCode + } + title + image { + altText + originalSrc + transformedSrc(maxWidth: 400, crop: CENTER) + id + } + compareAtPriceV2 { + amount + currencyCode + } + weight + weightUnit + availableForSale + sku + requiresShipping + } + } + } + } + appliedGiftCards { + amountUsedV2 { + amount + currencyCode + } + balanceV2 { + amount + currencyCode + } + lastCharacters + id + } + discountApplications(first: 10) { + edges { + node { + allocationMethod + targetSelection + targetType + value { + ... on MoneyV2 { + amount + currencyCode + } + ... on PricingPercentageValue { + percentage + } + } + } + } + } + lineItemsSubtotalPrice { + amount + currencyCode + } + paymentDueV2 { + amount + currencyCode + } + taxesIncluded + totalTaxV2 { + amount + currencyCode + } + totalPriceV2 { + amount + currencyCode + } + subtotalPriceV2 { + amount + currencyCode + } } checkoutUserErrors { code @@ -11,4 +143,5 @@ mutation checkoutShippingLineUpdate($checkoutId: ID!, $shippingRateHandle: Strin } } } + '''; \ No newline at end of file diff --git a/lib/graphql_operations/mutations/create_checkout.dart b/lib/graphql_operations/mutations/create_checkout.dart index 8881de58..01c9d541 100644 --- a/lib/graphql_operations/mutations/create_checkout.dart +++ b/lib/graphql_operations/mutations/create_checkout.dart @@ -1,8 +1,129 @@ const String createCheckoutMutation = r''' -mutation MyMutation { - checkoutCreate(input: {}) { +mutation checkoutCreate($input: CheckoutCreateInput!) { + checkoutCreate(input: $input) { checkout { id + email + requiresShipping + currencyCode + webUrl + orderStatusUrl + note + shippingLine { + handle + title + priceV2 { + amount + currencyCode + } + } + shippingAddress { + address1 + address2 + city + company + country + countryCodeV2 + firstName + formattedArea + id + lastName + latitude + longitude + name + phone + province + provinceCode + zip + } + lineItems(first: 250) { + edges { + node { + id + quantity + title + variant { + id + priceV2 { + amount + currencyCode + } + title + image { + altText + originalSrc + transformedSrc(maxWidth: 400, crop: CENTER) + id + } + compareAtPriceV2 { + amount + currencyCode + } + weight + weightUnit + availableForSale + sku + requiresShipping + } + } + } + } + appliedGiftCards { + amountUsedV2 { + amount + currencyCode + } + balanceV2 { + amount + currencyCode + } + lastCharacters + id + } + discountApplications(first: 10) { + edges { + node { + allocationMethod + targetSelection + targetType + value { + ... on MoneyV2 { + amount + currencyCode + } + ... on PricingPercentageValue { + percentage + } + } + } + } + } + lineItemsSubtotalPrice { + amount + currencyCode + } + paymentDueV2 { + amount + currencyCode + } + taxesIncluded + totalTaxV2 { + amount + currencyCode + } + totalPriceV2 { + amount + currencyCode + } + subtotalPriceV2 { + amount + currencyCode + } + } + checkoutUserErrors { + code + field + message } } } diff --git a/lib/graphql_operations/mutations/customer_access_token_create.dart b/lib/graphql_operations/mutations/customer_access_token_create.dart index 56944981..e80b643b 100644 --- a/lib/graphql_operations/mutations/customer_access_token_create.dart +++ b/lib/graphql_operations/mutations/customer_access_token_create.dart @@ -5,5 +5,10 @@ mutation customerAccessTokenCreate($email : String!, $password: String!) { expiresAt accessToken } + customerUserErrors { + code + field + message + } } }'''; \ No newline at end of file diff --git a/lib/graphql_operations/mutations/customer_access_token_renew.dart b/lib/graphql_operations/mutations/customer_access_token_renew.dart new file mode 100644 index 00000000..12faf056 --- /dev/null +++ b/lib/graphql_operations/mutations/customer_access_token_renew.dart @@ -0,0 +1,14 @@ +const String customerAccessTokenRenewMutation = r''' +mutation customerAccessTokenRenew($customerAccessToken: String!) { + customerAccessTokenRenew(customerAccessToken: $customerAccessToken) { + customerAccessToken { + accessToken + expiresAt + } + userErrors { + field + message + } + } +} +'''; \ No newline at end of file diff --git a/lib/graphql_operations/mutations/customer_create.dart b/lib/graphql_operations/mutations/customer_create.dart index 77da7dd0..7879e6b4 100644 --- a/lib/graphql_operations/mutations/customer_create.dart +++ b/lib/graphql_operations/mutations/customer_create.dart @@ -1,102 +1,52 @@ const String customerCreateMutation = r''' -mutation MyMutation($email: String!, $password: String!) { - customerCreate(input: {email: $email, password: $password}) { - customer{ - acceptsMarketing - addresses(first: 10) { - edges { - node { - address1 - address2 - city - company - country - countryCodeV2 - firstName - id - lastName - latitude - longitude - name - phone - province - provinceCode - zip - } - } +mutation MyMutation( + $firstName: String! + $lastName: String! + $email: String! + $password: String! +) { + customerCreate( + input: { + firstName: $firstName + lastName: $lastName + email: $email + password: $password } - createdAt - defaultAddress { - address1 - address2 - city - company - country - countryCodeV2 - firstName + ) { + customer { id + email + firstName lastName - latitude - longitude - name - phone - province - zip - provinceCode - } - tags - displayName - email - firstName - id - lastIncompleteCheckout { - completedAt - createdAt - currencyCode - email - id - webUrl - totalPriceV2 { - amount - currencyCode - } - lineItemsSubtotalPrice { - amount - currencyCode - } - lineItems(first: 250) { - edges { - node { - id - quantity - title - variant { - priceV2 { - amount - currencyCode - } - title - image { - altText - id - originalSrc - } - compareAtPriceV2 { - amount - currencyCode - } - weight - weightUnit - availableForSale - sku - requiresShipping - id - } - } + addresses(first: 10) { + edges { + node { + address1 + address2 + city + company + country + countryCodeV2 + firstName + id + lastName + latitude + longitude + name + phone + province + provinceCode + zip } } } - } + } + customerUserErrors { + code + field + message + } } } + '''; diff --git a/lib/graphql_operations/mutations/customer_update.dart b/lib/graphql_operations/mutations/customer_update.dart index c79109ba..edd92f23 100644 --- a/lib/graphql_operations/mutations/customer_update.dart +++ b/lib/graphql_operations/mutations/customer_update.dart @@ -55,6 +55,6 @@ mutation myNewMutation($firstString) { } } '''; - print(customerUpdateMutation); + // print(customerUpdateMutation); return customerUpdateMutation; } diff --git a/lib/graphql_operations/queries/get_all_blogs.dart b/lib/graphql_operations/queries/get_all_blogs.dart index 330b73cf..7104a831 100644 --- a/lib/graphql_operations/queries/get_all_blogs.dart +++ b/lib/graphql_operations/queries/get_all_blogs.dart @@ -6,7 +6,7 @@ query getBlogs($reverseBlogs: Boolean, $reverseArticles: Boolean, $sortKey: Blog id handle title - url + onlineStoreUrl articles(first: 250, sortKey: TITLE, reverse: $reverseArticles) { edges { node { @@ -40,11 +40,12 @@ query getBlogs($reverseBlogs: Boolean, $reverseArticles: Boolean, $sortKey: Blog altText id originalSrc + transformedSrc(maxWidth: 400, crop: CENTER) } publishedAt tags title - url + onlineStoreUrl } } } diff --git a/lib/graphql_operations/queries/get_all_orders.dart b/lib/graphql_operations/queries/get_all_orders.dart index 5bdcb1db..57a5b50c 100644 --- a/lib/graphql_operations/queries/get_all_orders.dart +++ b/lib/graphql_operations/queries/get_all_orders.dart @@ -38,6 +38,7 @@ customer(customerAccessToken: $accessToken) { altText id originalSrc + transformedSrc(maxWidth: 400, crop: CENTER) } compareAtPriceV2 { amount diff --git a/lib/graphql_operations/queries/get_all_products_from_collection_by_id.dart b/lib/graphql_operations/queries/get_all_products_from_collection_by_id.dart index 0ad287b3..6be9e2a3 100644 --- a/lib/graphql_operations/queries/get_all_products_from_collection_by_id.dart +++ b/lib/graphql_operations/queries/get_all_products_from_collection_by_id.dart @@ -12,6 +12,7 @@ query($id : ID!, $cursor : String, $sortKey: ProductCollectionSortKeys){ altText id originalSrc + transformedSrc(maxWidth: 400, crop: CENTER) } products(first: 10, sortKey: $sortKey, after: $cursor) { edges { @@ -46,6 +47,7 @@ query($id : ID!, $cursor : String, $sortKey: ProductCollectionSortKeys){ altText id originalSrc + transformedSrc(maxWidth: 400, crop: CENTER) } } } @@ -64,6 +66,7 @@ query($id : ID!, $cursor : String, $sortKey: ProductCollectionSortKeys){ altText id originalSrc + transformedSrc(maxWidth: 400, crop: CENTER) } priceV2 { amount diff --git a/lib/graphql_operations/queries/get_all_products_on_query.dart b/lib/graphql_operations/queries/get_all_products_on_query.dart index c0cd709b..fe6bb396 100644 --- a/lib/graphql_operations/queries/get_all_products_on_query.dart +++ b/lib/graphql_operations/queries/get_all_products_on_query.dart @@ -27,6 +27,7 @@ query( $cursor: String, $sortKey : ProductSortKeys, $query: String, $reverse: Bo altText id originalSrc + transformedSrc(maxWidth: 400, crop: CENTER) } } } @@ -38,6 +39,7 @@ query( $cursor: String, $sortKey : ProductSortKeys, $query: String, $reverse: Bo altText id originalSrc + transformedSrc(maxWidth: 400, crop: CENTER) } priceV2 { amount diff --git a/lib/graphql_operations/queries/get_blog_by_handle.dart b/lib/graphql_operations/queries/get_blog_by_handle.dart index 2c20992b..59c4f5ea 100644 --- a/lib/graphql_operations/queries/get_blog_by_handle.dart +++ b/lib/graphql_operations/queries/get_blog_by_handle.dart @@ -14,13 +14,13 @@ query($handle : String!, $sortKey: ArticleSortKeys, $reverseArticles: Boolean){ comments(first: 250) { edges { node { - content - contentHtml - id author { email name } + content + contentHtml + id } } } @@ -28,24 +28,25 @@ query($handle : String!, $sortKey: ArticleSortKeys, $reverseArticles: Boolean){ contentHtml excerpt excerptHtml - id handle + id image { altText id originalSrc + transformedSrc(maxWidth: 400, crop: CENTER) } publishedAt tags title - url + onlineStoreUrl } } } handle id title - url + onlineStoreUrl } } '''; \ No newline at end of file diff --git a/lib/graphql_operations/queries/get_checkout_information.dart b/lib/graphql_operations/queries/get_checkout_information.dart index ac3fd700..8a4523a9 100644 --- a/lib/graphql_operations/queries/get_checkout_information.dart +++ b/lib/graphql_operations/queries/get_checkout_information.dart @@ -1,28 +1,76 @@ -const String getCheckoutInfo = r''' -query($id: ID!){ - node(id: $id) { +const String getCheckoutInfo = + ''' +query(\$id: ID!) { + node(id: \$id) { ... on Checkout { id email - appliedGiftCards { - amountUsedV2 { - amount - currencyCode - } - balanceV2 { - amount + requiresShipping + currencyCode + webUrl + orderStatusUrl + note + order { + id + email currencyCode - } - id + customerUrl + name + orderNumber + phone + processedAt + canceledAt + cancelReason + financialStatus + fulfillmentStatus + statusUrl + shippingAddress { + address1 + address2 + city + company + country + countryCodeV2 + firstName + formattedArea + id + lastName + latitude + longitude + name + phone + province + provinceCode + zip + } + subtotalPriceV2 { + amount + currencyCode + } + totalPriceV2 { + amount + currencyCode + } + totalRefundedV2 { + amount + currencyCode + } + totalShippingPriceV2 { + amount + currencyCode + } + totalTaxV2 { + amount + currencyCode + } } - requiresShipping shippingLine { handle + title priceV2 { amount currencyCode } - title } shippingAddress { address1 @@ -43,10 +91,7 @@ query($id: ID!){ provinceCode zip } - completedAt - createdAt - currencyCode - lineItems(first: 10) { + lineItems(first: 250) { edges { node { id @@ -62,6 +107,7 @@ query($id: ID!){ image { altText originalSrc + transformedSrc(maxWidth: 400, crop: CENTER) id } compareAtPriceV2 { @@ -77,9 +123,45 @@ query($id: ID!){ } } } - note - webUrl - updatedAt + appliedGiftCards { + amountUsedV2 { + amount + currencyCode + } + balanceV2 { + amount + currencyCode + } + lastCharacters + id + } + discountApplications(first: 10) { + edges { + node { + allocationMethod + targetSelection + targetType + value { + ... on MoneyV2 { + amount + currencyCode + } + ... on PricingPercentageValue { + percentage + } + } + } + } + } + lineItemsSubtotalPrice { + amount + currencyCode + } + paymentDueV2 { + amount + currencyCode + } + taxesIncluded totalTaxV2 { amount currencyCode @@ -88,18 +170,17 @@ query($id: ID!){ amount currencyCode } - taxesIncluded - taxExempt subtotalPriceV2 { amount currencyCode } - orderStatusUrl } } } + '''; + /* availableShippingRates { ready shippingRates { diff --git a/lib/graphql_operations/queries/get_checkout_information_with_shipping_rate.dart b/lib/graphql_operations/queries/get_checkout_information_with_shipping_rate.dart index be5da0a7..4ab3aff7 100644 --- a/lib/graphql_operations/queries/get_checkout_information_with_shipping_rate.dart +++ b/lib/graphql_operations/queries/get_checkout_information_with_shipping_rate.dart @@ -4,18 +4,18 @@ query($id: ID!){ ... on Checkout { id email - appliedGiftCards { - amountUsedV2 { - amount - currencyCode - } - balanceV2 { + requiresShipping + currencyCode + webUrl + orderStatusUrl + shippingLine { + handle + title + priceV2 { amount currencyCode } - id } - requiresShipping availableShippingRates { ready shippingRates { @@ -24,7 +24,9 @@ query($id: ID!){ priceV2 { amount currencyCode - }}} + } + } + } shippingAddress { address1 address2 @@ -44,51 +46,45 @@ query($id: ID!){ provinceCode zip } - shippingLine { - handle - priceV2 { + appliedGiftCards { + amountUsedV2 { amount currencyCode } - title + balanceV2 { + amount + currencyCode + } + lastCharacters + id } - completedAt - createdAt - currencyCode - lineItems(first: 10) { + discountApplications(first: 10) { edges { node { - id - quantity - title - variant { - id - priceV2 { + allocationMethod + targetSelection + targetType + value { + ... on MoneyV2 { amount currencyCode } - title - image { - altText - originalSrc - id - } - compareAtPriceV2 { - amount - currencyCode + ... on PricingPercentageValue { + percentage } - weight - weightUnit - availableForSale - sku - requiresShipping } } } } - note - webUrl - updatedAt + lineItemsSubtotalPrice { + amount + currencyCode + } + paymentDueV2 { + amount + currencyCode + } + taxesIncluded totalTaxV2 { amount currencyCode @@ -97,13 +93,10 @@ query($id: ID!){ amount currencyCode } - taxesIncluded - taxExempt subtotalPriceV2 { amount currencyCode } - orderStatusUrl } } } diff --git a/lib/graphql_operations/queries/get_checkout_without_shipping_rates.dart b/lib/graphql_operations/queries/get_checkout_without_shipping_rates.dart index b6b8e4f2..908c3491 100644 --- a/lib/graphql_operations/queries/get_checkout_without_shipping_rates.dart +++ b/lib/graphql_operations/queries/get_checkout_without_shipping_rates.dart @@ -4,6 +4,24 @@ query($id: ID!){ ... on Checkout { id email + discountApplications(first: 10) { + edges { + node { + allocationMethod + targetSelection + targetType + value { + ... on MoneyV2 { + amount + currencyCode + } + ... on PricingPercentageValue { + percentage + } + } + } + } + } appliedGiftCards { amountUsedV2 { amount @@ -13,6 +31,7 @@ query($id: ID!){ amount currencyCode } + lastCharacters id } requiresShipping @@ -46,7 +65,7 @@ query($id: ID!){ completedAt createdAt currencyCode - lineItems(first: 10) { + lineItems(first: 250) { edges { node { id @@ -62,6 +81,7 @@ query($id: ID!){ image { altText originalSrc + transformedSrc(maxWidth: 400, crop: CENTER) id } compareAtPriceV2 { @@ -80,6 +100,14 @@ query($id: ID!){ note webUrl updatedAt + lineItemsSubtotalPrice { + amount + currencyCode + } + paymentDueV2 { + amount + currencyCode + } totalTaxV2 { amount currencyCode diff --git a/lib/graphql_operations/queries/get_collection_by_handle.dart b/lib/graphql_operations/queries/get_collection_by_handle.dart new file mode 100644 index 00000000..97565ff8 --- /dev/null +++ b/lib/graphql_operations/queries/get_collection_by_handle.dart @@ -0,0 +1,15 @@ +const String getCollectionByHandleQuery = r''' +query($handle: String!) { + collectionByHandle(handle: $handle) { + title + handle + id + image { + altText + id + originalSrc + transformedSrc(maxWidth: 400, crop: CENTER) + } + } +} +'''; diff --git a/lib/graphql_operations/queries/get_collection_by_handle_with_products.dart b/lib/graphql_operations/queries/get_collection_by_handle_with_products.dart new file mode 100644 index 00000000..0b33c910 --- /dev/null +++ b/lib/graphql_operations/queries/get_collection_by_handle_with_products.dart @@ -0,0 +1,84 @@ +String getCollectionByHandleWithProductsQuery(int productsCount, int variantsCount) { + return ''' +query(\$handle: String!) { + collectionByHandle(handle: \$handle) { + title + handle + id + image { + altText + id + originalSrc + transformedSrc(maxWidth: 400, crop: CENTER) + } + products(first: $productsCount) { + edges { + node { + id + handle + title + availableForSale + tags + vendor + rating: metafield(namespace: "rview", key: "rating") { + key + namespace + value + type + } + review_count: metafield(namespace: "rview", key: "review-count") { + key + namespace + value + type + } + variants(first: $variantsCount) { + edges { + node { + id + title + requiresShipping + availableForSale + quantityAvailable + image { + altText + id + originalSrc + transformedSrc(maxWidth: 400, crop: CENTER) + } + priceV2 { + amount + currencyCode + } + compareAtPriceV2 { + amount + currencyCode + } + selectedOptions { + name + value + } + } + } + } + images(first: 10) { + edges { + node { + altText + id + originalSrc + transformedSrc(maxWidth: 400, crop: CENTER) + } + } + } + } + cursor + } + pageInfo { + hasNextPage + } + } + } +} +'''; +} diff --git a/lib/graphql_operations/queries/get_collections.dart b/lib/graphql_operations/queries/get_collections.dart index 52471bd9..a2d1d217 100644 --- a/lib/graphql_operations/queries/get_collections.dart +++ b/lib/graphql_operations/queries/get_collections.dart @@ -17,6 +17,7 @@ query($cursor: String, $sortKey: CollectionSortKeys, $reverse: Boolean){ altText id originalSrc + transformedSrc(maxWidth: 400, crop: CENTER) } products(first: 250) { edges { @@ -29,6 +30,7 @@ query($cursor: String, $sortKey: CollectionSortKeys, $reverse: Boolean){ altText id originalSrc + transformedSrc(maxWidth: 400, crop: CENTER) } priceV2 { amount @@ -71,6 +73,7 @@ query($cursor: String, $sortKey: CollectionSortKeys, $reverse: Boolean){ altText id originalSrc + transformedSrc(maxWidth: 400, crop: CENTER) } } } diff --git a/lib/graphql_operations/queries/get_collections_by_ids.dart b/lib/graphql_operations/queries/get_collections_by_ids.dart index 4966ded4..7d918561 100644 --- a/lib/graphql_operations/queries/get_collections_by_ids.dart +++ b/lib/graphql_operations/queries/get_collections_by_ids.dart @@ -8,6 +8,7 @@ query getCollectionsByIds($ids: [ID!]!){ image { src originalSrc + transformedSrc(maxWidth: 400, crop: CENTER) id altText } diff --git a/lib/graphql_operations/queries/get_customer.dart b/lib/graphql_operations/queries/get_customer.dart index c74f5d29..7ee249a7 100644 --- a/lib/graphql_operations/queries/get_customer.dart +++ b/lib/graphql_operations/queries/get_customer.dart @@ -1,7 +1,11 @@ const String getCustomerQuery = r''' -query($customerAccessToken : String!){ +query($customerAccessToken: String!) { customer(customerAccessToken: $customerAccessToken) { - acceptsMarketing + id + email + firstName + lastName + tags addresses(first: 10) { edges { node { @@ -20,82 +24,11 @@ query($customerAccessToken : String!){ phone province provinceCode + formattedArea zip } } } - createdAt - defaultAddress { - address1 - address2 - city - company - country - countryCodeV2 - firstName - id - lastName - latitude - longitude - name - phone - province - zip - provinceCode - } - displayName - email - tags - firstName - id - lastName - lastIncompleteCheckout { - completedAt - createdAt - currencyCode - email - id - webUrl - totalPriceV2 { - amount - currencyCode - } - lineItemsSubtotalPrice { - amount - currencyCode - } - lineItems(first: 250) { - edges { - node { - id - quantity - title - variant { - priceV2 { - amount - currencyCode - } - title - image { - altText - id - originalSrc - } - compareAtPriceV2 { - amount - currencyCode - } - weight - weightUnit - availableForSale - sku - requiresShipping - id - } - } - } - } - } } } '''; diff --git a/lib/graphql_operations/queries/get_featured_collections.dart b/lib/graphql_operations/queries/get_featured_collections.dart index 4467a78b..eb230caf 100644 --- a/lib/graphql_operations/queries/get_featured_collections.dart +++ b/lib/graphql_operations/queries/get_featured_collections.dart @@ -13,6 +13,7 @@ query getFeaturedCollectionQuery($query: String!){ altText id originalSrc + transformedSrc(maxWidth: 400, crop: CENTER) } products(first: 20) { edges { @@ -25,6 +26,7 @@ query getFeaturedCollectionQuery($query: String!){ altText id originalSrc + transformedSrc(maxWidth: 400, crop: CENTER) } priceV2 { amount @@ -67,6 +69,7 @@ query getFeaturedCollectionQuery($query: String!){ altText id originalSrc + transformedSrc(maxWidth: 400, crop: CENTER) } } } diff --git a/lib/graphql_operations/queries/get_metafileds_from_product.dart b/lib/graphql_operations/queries/get_metafileds_from_product.dart index 3cb75f0c..e0f9fdfe 100644 --- a/lib/graphql_operations/queries/get_metafileds_from_product.dart +++ b/lib/graphql_operations/queries/get_metafileds_from_product.dart @@ -8,7 +8,7 @@ query($handle: String!, $namespace: String!) { namespace key value - valueType + type description } } diff --git a/lib/graphql_operations/queries/get_n_articles_sorted.dart b/lib/graphql_operations/queries/get_n_articles_sorted.dart index 0fef3abd..e36e7dd7 100644 --- a/lib/graphql_operations/queries/get_n_articles_sorted.dart +++ b/lib/graphql_operations/queries/get_n_articles_sorted.dart @@ -33,11 +33,12 @@ query($x : Int, $sortKey : ArticleSortKeys, $reverse: Boolean){ altText id originalSrc + transformedSrc(maxWidth: 400, crop: CENTER) } publishedAt tags title - url + onlineStoreUrl } } } diff --git a/lib/graphql_operations/queries/get_n_products.dart b/lib/graphql_operations/queries/get_n_products.dart index 1b25206c..a8e9ddfb 100644 --- a/lib/graphql_operations/queries/get_n_products.dart +++ b/lib/graphql_operations/queries/get_n_products.dart @@ -7,21 +7,33 @@ query($n : Int, $sortKey : ProductSortKeys, $reverse: Boolean){ edges { cursor node { - options(first: 50) { - id - name - values - } - variants(first: 250) { + id + handle + title + availableForSale + tags + vendor + rating: metafield(namespace: "rview", key: "rating") { + key + namespace + value + type + } + review_count: metafield(namespace: "rview", key: "review-count") { + key + namespace + value + type + } + variants(first: 1) { edges { node { id title - image { - altText - id - originalSrc - } + availableForSale + sku + requiresShipping + quantityAvailable priceV2 { amount currencyCode @@ -30,49 +42,16 @@ query($n : Int, $sortKey : ProductSortKeys, $reverse: Boolean){ amount currencyCode } - weight - weightUnit - availableForSale - sku - requiresShipping - quantityAvailable } } - pageInfo { - hasNextPage - } } - availableForSale - collections(first: 250) { - edges { - node { - description - descriptionHtml - id - handle - updatedAt - title - } - } - } - createdAt - description - descriptionHtml - handle - id - onlineStoreUrl - productType - publishedAt - tags - title - updatedAt - vendor - images(first: 250) { + images(first: 1) { edges { node { altText id originalSrc + transformedSrc(maxWidth: 400, crop: CENTER) } } } diff --git a/lib/graphql_operations/queries/get_page_by_handle.dart b/lib/graphql_operations/queries/get_page_by_handle.dart new file mode 100644 index 00000000..a82488d9 --- /dev/null +++ b/lib/graphql_operations/queries/get_page_by_handle.dart @@ -0,0 +1,11 @@ +const String getPageByHandleQuery = r''' +query($handle : String!){ + pageByHandle(handle: $handle) { + id + handle + title + body + onlineStoreUrl + } +} +'''; \ No newline at end of file diff --git a/lib/graphql_operations/queries/get_product_by_handle.dart b/lib/graphql_operations/queries/get_product_by_handle.dart new file mode 100644 index 00000000..81d50b9c --- /dev/null +++ b/lib/graphql_operations/queries/get_product_by_handle.dart @@ -0,0 +1,74 @@ +const String getProductByHandleQuery = r''' +query($handle: String!) { + productByHandle(handle: $handle) { + id + handle + title + availableForSale + tags + onlineStoreUrl + productType + vendor + descriptionHtml + options(first: 50) { + id + name + values + } + vendor + rating: metafield(namespace: "rview", key: "rating") { + key + namespace + value + type + } + review_count: metafield(namespace: "rview", key: "review-count") { + key + namespace + value + type + } + variants(first: 250) { + edges { + node { + id + title + availableForSale + sku + requiresShipping + quantityAvailable + priceV2 { + amount + currencyCode + } + compareAtPriceV2 { + amount + currencyCode + } + selectedOptions { + name + value + } + image { + altText + id + originalSrc + transformedSrc(maxWidth: 400, crop: CENTER) + } + } + } + } + images(first: 20) { + edges { + node { + altText + id + originalSrc + transformedSrc(maxWidth: 400, crop: CENTER) + } + } + } + } +} + +'''; diff --git a/lib/graphql_operations/queries/get_product_by_handle_minimum_data.dart b/lib/graphql_operations/queries/get_product_by_handle_minimum_data.dart new file mode 100644 index 00000000..b9549c7a --- /dev/null +++ b/lib/graphql_operations/queries/get_product_by_handle_minimum_data.dart @@ -0,0 +1,55 @@ +const String getProductByHandleMinimumDataQuery = r''' +query($handle: String!) { + productByHandle(handle: $handle) { + id + handle + title + availableForSale + tags + vendor + rating: metafield(namespace: "rview", key: "rating") { + key + namespace + value + type + } + review_count: metafield(namespace: "rview", key: "review-count") { + key + namespace + value + type + } + variants(first: 1) { + edges { + node { + id + title + availableForSale + sku + requiresShipping + quantityAvailable + priceV2 { + amount + currencyCode + } + compareAtPriceV2 { + amount + currencyCode + } + } + } + } + images(first: 1) { + edges { + node { + altText + id + originalSrc + transformedSrc(maxWidth: 400, crop: CENTER) + } + } + } + } +} + +'''; diff --git a/lib/graphql_operations/queries/get_product_recommendations.dart b/lib/graphql_operations/queries/get_product_recommendations.dart index b55902a0..b21f6630 100644 --- a/lib/graphql_operations/queries/get_product_recommendations.dart +++ b/lib/graphql_operations/queries/get_product_recommendations.dart @@ -1,43 +1,44 @@ -const String getProductRecommendationsQuery = r''' -query getProductRecommentationsQuery($id: ID!){ - productRecommendations(productId: $id) { - availableForSale - createdAt - description - descriptionHtml - handle +String getProductRecommendationsQuery(int variantsCount) { + return ''' +query getProductRecommentationsQuery(\$id: ID!){ + productRecommendations(productId: \$id) { id - images(first: 250) { + handle + title + availableForSale + tags + vendor + rating: metafield(namespace: "rview", key: "rating") { + key + namespace + value + type + } + review_count: metafield(namespace: "rview", key: "review-count") { + key + namespace + value + type + } + images(first: 1) { edges { node { altText id originalSrc + transformedSrc(maxWidth: 400, crop: CENTER) } } } - onlineStoreUrl - options(first: 50) { - id - name - values - } - productType - publishedAt - tags - title - updatedAt - vendor - variants(first: 250) { + variants(first: $variantsCount) { edges { node { id title - image { - altText - id - originalSrc - } + availableForSale + requiresShipping + quantityAvailable + sku priceV2 { amount currencyCode @@ -46,15 +47,14 @@ query getProductRecommentationsQuery($id: ID!){ amount currencyCode } - weight - weightUnit - availableForSale - sku - requiresShipping - quantityAvailable + selectedOptions { + name + value + } } } } } } '''; +} \ No newline at end of file diff --git a/lib/graphql_operations/queries/get_products.dart b/lib/graphql_operations/queries/get_products.dart index 13506d79..3e2c8b26 100644 --- a/lib/graphql_operations/queries/get_products.dart +++ b/lib/graphql_operations/queries/get_products.dart @@ -19,7 +19,7 @@ query($cursor : String, $shouldFetchMetafields : Boolean = false, $metafieldsNa namespace key value - valueType + type description } } @@ -33,6 +33,7 @@ query($cursor : String, $shouldFetchMetafields : Boolean = false, $metafieldsNa altText id originalSrc + transformedSrc(maxWidth: 400, crop: CENTER) } priceV2 { amount @@ -85,6 +86,7 @@ query($cursor : String, $shouldFetchMetafields : Boolean = false, $metafieldsNa altText id originalSrc + transformedSrc(maxWidth: 400, crop: CENTER) } } } diff --git a/lib/graphql_operations/queries/get_products_by_handle.dart b/lib/graphql_operations/queries/get_products_by_handle.dart index 920461fe..77a03c2f 100644 --- a/lib/graphql_operations/queries/get_products_by_handle.dart +++ b/lib/graphql_operations/queries/get_products_by_handle.dart @@ -1,26 +1,81 @@ const String getProductByHandle = r''' -query getProductByHandle($handle : String!){ +query getProductByHandle($handle: String!) { productByHandle(handle: $handle) { id handle - images(first: 250) { + title + availableForSale + descriptionHtml + productType + tags + vendor + rating: metafield(namespace: "rview", key: "rating") { + key + namespace + value + type + } + review_count: metafield(namespace: "rview", key: "review-count") { + key + namespace + value + type + } + options(first: 50) { + id + name + values + } + images(first: 20) { edges { node { + altText + id originalSrc + transformedSrc(maxWidth: 400, crop: CENTER) } } } variants(first: 250) { edges { node { + id + title + availableForSale + quantityAvailable + requiresShipping + sku priceV2 { amount currencyCode } - quantityAvailable + compareAtPriceV2 { + amount + currencyCode + } + selectedOptions { + name + value + } + image { + altText + id + originalSrc + transformedSrc(maxWidth: 400, crop: CENTER) + } + } + } + } + collections(first: 250) { + edges { + node { + id + handle + title } } } } } + '''; \ No newline at end of file diff --git a/lib/graphql_operations/queries/get_products_by_ids.dart b/lib/graphql_operations/queries/get_products_by_ids.dart index 2cc9a629..05c793e4 100644 --- a/lib/graphql_operations/queries/get_products_by_ids.dart +++ b/lib/graphql_operations/queries/get_products_by_ids.dart @@ -1,74 +1,75 @@ const String getProductsByIdsQuery = r''' -query($ids : [ID!]!){ +query($ids: [ID!]!) { nodes(ids: $ids) { ... on Product { - options(first: 50) { - id - name - values - } id handle - collections(first: 250) { + title + availableForSale + descriptionHtml + productType + tags + onlineStoreUrl + vendor + rating: metafield(namespace: "rview", key: "rating") { + key + namespace + value + type + } + review_count: metafield(namespace: "rview", key: "review-count") { + key + namespace + value + type + } + options(first: 50) { + id + name + values + } + images(first: 20) { edges { node { - description - descriptionHtml - handle + altText id - updatedAt - title + originalSrc + transformedSrc(maxWidth: 400, crop: CENTER) } } } - title - availableForSale - createdAt - description - descriptionHtml - images(first: 250) { - edges { - node { - altText - id - originalSrc - } - } - } variants(first: 250) { edges { node { + id + title + availableForSale + quantityAvailable + requiresShipping + sku priceV2 { amount currencyCode } - title - image { - altText - originalSrc - id - } compareAtPriceV2 { amount currencyCode } - weightUnit - weight - availableForSale - sku - requiresShipping - id - quantityAvailable + selectedOptions { + name + value + } + image { + altText + id + originalSrc + transformedSrc(maxWidth: 400, crop: CENTER) + } } } } - onlineStoreUrl - productType - publishedAt - tags - updatedAt - vendor } } } + '''; diff --git a/lib/graphql_operations/queries/get_products_by_ids_minimum_data.dart b/lib/graphql_operations/queries/get_products_by_ids_minimum_data.dart new file mode 100644 index 00000000..e9e36625 --- /dev/null +++ b/lib/graphql_operations/queries/get_products_by_ids_minimum_data.dart @@ -0,0 +1,65 @@ +String getProductsByIdsMinimumDataQuery(int variantsCount) { + return ''' +query(\$ids: [ID!]!) { + nodes(ids: \$ids) { + ... on Product { + id + handle + title + tags + availableForSale + descriptionHtml + productType + vendor + rating: metafield(namespace: "rview", key: "rating") { + key + namespace + value + type + } + review_count: metafield(namespace: "rview", key: "review-count") { + key + namespace + value + type + } + images(first: 1) { + edges { + node { + altText + id + originalSrc + transformedSrc(maxWidth: 400, crop: CENTER) + } + } + } + variants(first: $variantsCount) { + edges { + node { + id + title + availableForSale + quantityAvailable + requiresShipping + sku + priceV2 { + amount + currencyCode + } + compareAtPriceV2 { + amount + currencyCode + } + selectedOptions { + name + value + } + } + } + } + } + } +} + +'''; +} \ No newline at end of file diff --git a/lib/graphql_operations/queries/get_recently_ordered_products.dart b/lib/graphql_operations/queries/get_recently_ordered_products.dart new file mode 100644 index 00000000..fad9adbb --- /dev/null +++ b/lib/graphql_operations/queries/get_recently_ordered_products.dart @@ -0,0 +1,94 @@ +String getRecentlyOrderedProductsQuery(int variantsCount) { + return ''' +query getOrders( + \$cursor: String + \$x: Int + \$sortKey: OrderSortKeys + \$accessToken: String! + \$reverse: Boolean +) { + customer(customerAccessToken: \$accessToken) { + id + orders(first: \$x, after: \$cursor, sortKey: \$sortKey, reverse: \$reverse) { + pageInfo { + hasNextPage + } + edges { + node { + id + processedAt + canceledAt + cancelReason + financialStatus + fulfillmentStatus + lineItems(first: 10) { + edges { + node { + title + variant { + product { + id + title + handle + availableForSale + vendor + rating: metafield(namespace: "rview", key: "rating") { + key + namespace + value + type + } + review_count: metafield(namespace: "rview", key: "review-count") { + key + namespace + value + type + } + images(first: 1) { + edges { + node { + altText + id + originalSrc + transformedSrc(maxWidth: 400, crop: CENTER) + } + } + } + variants(first: $variantsCount) { + edges { + node { + id + title + availableForSale + quantityAvailable + requiresShipping + sku + priceV2 { + amount + currencyCode + } + compareAtPriceV2 { + amount + currencyCode + } + selectedOptions { + name + value + } + } + } + } + } + } + } + } + } + + } + cursor + } + } + } +} +'''; +} diff --git a/lib/graphql_operations/queries/get_x_articles_after_cursor.dart b/lib/graphql_operations/queries/get_x_articles_after_cursor.dart new file mode 100644 index 00000000..4e906ec7 --- /dev/null +++ b/lib/graphql_operations/queries/get_x_articles_after_cursor.dart @@ -0,0 +1,36 @@ +const String getXArticlesAfterCursorQuery = r''' +query($cursor: String, $x: Int, $reverse: Boolean, $sortKey: ArticleSortKeys) { + articles(first: $x, after: $cursor, sortKey: $sortKey, reverse: $reverse) { + pageInfo { + hasNextPage + } + edges { + cursor + node { + id + handle + title + publishedAt + onlineStoreUrl + excerpt + excerptHtml + contentHtml + authorV2 { + bio + email + firstName + lastName + name + } + image { + altText + id + originalSrc + transformedSrc(maxWidth: 400, crop: CENTER) + } + } + } + } +} + +'''; diff --git a/lib/graphql_operations/queries/get_x_collections_and_n_products_sorted.dart b/lib/graphql_operations/queries/get_x_collections_and_n_products_sorted.dart index c4238ab9..f6f728fe 100644 --- a/lib/graphql_operations/queries/get_x_collections_and_n_products_sorted.dart +++ b/lib/graphql_operations/queries/get_x_collections_and_n_products_sorted.dart @@ -17,6 +17,7 @@ query($cursor: String, $sortKey: CollectionSortKeys, $sortKeyProduct: ProductCol altText id originalSrc + transformedSrc(maxWidth: 400, crop: CENTER) } products(first: $n, sortKey: $sortKeyProduct) { edges { @@ -29,6 +30,7 @@ query($cursor: String, $sortKey: CollectionSortKeys, $sortKeyProduct: ProductCol altText id originalSrc + transformedSrc(maxWidth: 400, crop: CENTER) } priceV2 { amount @@ -59,6 +61,7 @@ query($cursor: String, $sortKey: CollectionSortKeys, $sortKeyProduct: ProductCol altText id originalSrc + transformedSrc(maxWidth: 400, crop: CENTER) } } } 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..81ea3fb7 --- /dev/null +++ b/lib/graphql_operations/queries/get_x_orders_after_cursor.dart @@ -0,0 +1,98 @@ +const String getXOrdersAfterCursorQuery = r''' +query getOrders( + $cursor: String + $x: Int + $sortKey: OrderSortKeys + $accessToken: String! + $reverse: Boolean +) { + customer(customerAccessToken: $accessToken) { + id + orders(first: $x, after: $cursor, sortKey: $sortKey, reverse: $reverse) { + pageInfo { + hasNextPage + } + edges { + node { + id + email + currencyCode + customerUrl + name + orderNumber + phone + processedAt + canceledAt + cancelReason + financialStatus + fulfillmentStatus + statusUrl + lineItems(first: 250) { + edges { + node { + title + quantity + variant { + id + title + availableForSale + priceV2 { + amount + currencyCode + } + image { + altText + id + originalSrc + transformedSrc(maxWidth: 400, crop: CENTER) + } + } + } + } + } + shippingAddress { + address1 + address2 + city + company + country + countryCodeV2 + firstName + formattedArea + id + lastName + latitude + longitude + name + phone + province + provinceCode + zip + } + subtotalPriceV2 { + amount + currencyCode + } + totalPriceV2 { + amount + currencyCode + } + totalRefundedV2 { + amount + currencyCode + } + totalShippingPriceV2 { + amount + currencyCode + } + totalTaxV2 { + amount + currencyCode + } + } + cursor + } + } + } +} +'''; \ No newline at end of file diff --git a/lib/graphql_operations/queries/get_x_products_after_cursor.dart b/lib/graphql_operations/queries/get_x_products_after_cursor.dart index 004fd63a..f38c1f25 100644 --- a/lib/graphql_operations/queries/get_x_products_after_cursor.dart +++ b/lib/graphql_operations/queries/get_x_products_after_cursor.dart @@ -1,5 +1,5 @@ const String getXProductsAfterCursorQuery = r''' -query($cursor : String, $x : Int, $reverse: Boolean, $sortKey: ProductSortKeys){ +query($cursor: String, $x: Int, $reverse: Boolean, $sortKey: ProductSortKeys) { products(first: $x, after: $cursor, sortKey: $sortKey, reverse: $reverse) { pageInfo { hasNextPage @@ -7,20 +7,48 @@ query($cursor : String, $x : Int, $reverse: Boolean, $sortKey: ProductSortKeys){ edges { cursor node { - options(first: 50) { - id - name - values - } - variants(first: 250) { + id + handle + title + availableForSale + tags + vendor + rating: metafield(namespace: "rview", key: "rating") { + key + namespace + value + type + } + review_count: metafield(namespace: "rview", key: "review-count") { + key + namespace + value + type + } + images(first: 1) { + edges { + node { + altText + id + originalSrc + transformedSrc(maxWidth: 400, crop: CENTER) + } + } + } + variants(first: 1) { edges { node { id title + sku + availableForSale + quantityAvailable + requiresShipping image { altText id originalSrc + transformedSrc(maxWidth: 400, crop: CENTER) } priceV2 { amount @@ -30,53 +58,14 @@ query($cursor : String, $x : Int, $reverse: Boolean, $sortKey: ProductSortKeys){ amount currencyCode } - weight - weightUnit - availableForSale - sku - requiresShipping - quantityAvailable } } pageInfo { hasNextPage } } - availableForSale - collections(first: 250) { - edges { - node { - description - descriptionHtml - id - handle - updatedAt - title - } - } - } - createdAt - description - descriptionHtml - handle - id - onlineStoreUrl - productType - publishedAt - tags - title - updatedAt - vendor - images(first: 250) { - edges { - node { - altText - id - originalSrc - } - } - } } } } -}'''; +} +'''; diff --git a/lib/graphql_operations/queries/get_x_products_after_cursor_by_collection_handle.dart b/lib/graphql_operations/queries/get_x_products_after_cursor_by_collection_handle.dart new file mode 100644 index 00000000..419a3ec1 --- /dev/null +++ b/lib/graphql_operations/queries/get_x_products_after_cursor_by_collection_handle.dart @@ -0,0 +1,94 @@ +const String getXProductAfterCursorByCollectionHandleQuery = r''' +query( + $handle: String! + $cursor: String + $x: Int + $reverse: Boolean + $sortKey: ProductCollectionSortKeys + $filters: [ProductFilter!] +) { + collectionByHandle(handle: $handle) { + id + handle + title + descriptionHtml + image { + altText + id + originalSrc + transformedSrc(maxWidth: 400, crop: CENTER) + } + products(first: $x, after: $cursor, sortKey: $sortKey, reverse: $reverse, filters: $filters) { + pageInfo { + hasNextPage + } + filters { + id + label + type + values { + id + label + count + input + } + } + edges { + cursor + node { + id + handle + availableForSale + title + tags + vendor + rating: metafield(namespace: "rview", key: "rating") { + key + namespace + value + type + } + review_count: metafield(namespace: "rview", key: "review-count") { + key + namespace + value + type + } + images(first: 1) { + edges { + node { + altText + id + originalSrc + transformedSrc(maxWidth: 400, crop: CENTER) + } + } + } + variants(first: 1) { + edges { + node { + id + title + availableForSale + requiresShipping + quantityAvailable + priceV2 { + amount + currencyCode + } + compareAtPriceV2 { + amount + currencyCode + } + } + } + pageInfo { + hasNextPage + } + } + } + } + } + } +} +'''; diff --git a/lib/graphql_operations/queries/get_x_products_after_cursor_within_collection.dart b/lib/graphql_operations/queries/get_x_products_after_cursor_within_collection.dart index 57f0168a..3197808a 100644 --- a/lib/graphql_operations/queries/get_x_products_after_cursor_within_collection.dart +++ b/lib/graphql_operations/queries/get_x_products_after_cursor_within_collection.dart @@ -1,70 +1,53 @@ const String getXProductsAfterCursorWithinCollectionQuery = r''' -query($id : ID!, $cursor : String, $limit : Int, $sortKey : ProductCollectionSortKeys, $reverse: Boolean){ +query( + $id: ID! + $cursor: String + $limit: Int + $sortKey: ProductCollectionSortKeys + $reverse: Boolean +) { node(id: $id) { ... on Collection { id - description - descriptionHtml handle title - updatedAt image { altText id originalSrc + transformedSrc(maxWidth: 400, crop: CENTER) } - products(first: $limit, sortKey: $sortKey, after: $cursor, reverse: $reverse) { + products( + first: $limit + sortKey: $sortKey + after: $cursor + reverse: $reverse + ) { edges { cursor node { - options(first: 50) { id - name - values - } - availableForSale - collections(first: 1) { - edges { - node { - description - descriptionHtml - handle - id - title - updatedAt - } - } - } - createdAt - description - descriptionHtml handle - id - images(first: 20) { + title + availableForSale + images(first: 1) { edges { node { altText id originalSrc + transformedSrc(maxWidth: 400, crop: CENTER) } } } - onlineStoreUrl - productType - publishedAt - tags - title - updatedAt - vendor - variants(first: 25) { + variants(first: 1) { edges { node { + id title - image { - altText - id - originalSrc - } + requiresShipping + availableForSale + quantityAvailable priceV2 { amount currencyCode @@ -73,22 +56,17 @@ query($id : ID!, $cursor : String, $limit : Int, $sortKey : ProductCollectionSor amount currencyCode } - weight - weightUnit - sku - requiresShipping - availableForSale - id - quantityAvailable } } } } } - pageInfo{ - hasNextPage - }} + pageInfo { + hasNextPage + } + } } } } + '''; diff --git a/lib/graphql_operations/queries/get_x_products_on_query_after_cursor.dart b/lib/graphql_operations/queries/get_x_products_on_query_after_cursor.dart index 2e6d75be..96b4ef6d 100644 --- a/lib/graphql_operations/queries/get_x_products_on_query_after_cursor.dart +++ b/lib/graphql_operations/queries/get_x_products_on_query_after_cursor.dart @@ -3,41 +3,49 @@ query( $cursor: String, $limit : Int, $sortKey : ProductSortKeys, $query: String products(query: $query, first: $limit, after: $cursor, sortKey: $sortKey, reverse: $reverse) { edges { node { - options(first: 50) { - id - name - values - } id handle + title availableForSale - createdAt - description - descriptionHtml onlineStoreUrl productType - publishedAt tags - title - updatedAt vendor - images(first: 250) { + rating: metafield(namespace: "rview", key: "rating") { + key + namespace + value + type + } + review_count: metafield(namespace: "rview", key: "review-count") { + key + namespace + value + type + } + images(first: 1) { edges { node { altText id originalSrc + transformedSrc(maxWidth: 400, crop: CENTER) } } } variants(first: 250) { edges { node { + id title + requiresShipping + quantityAvailable + availableForSale image { altText id originalSrc + transformedSrc(maxWidth: 400, crop: CENTER) } priceV2 { amount @@ -47,13 +55,7 @@ query( $cursor: String, $limit : Int, $sortKey : ProductSortKeys, $query: String amount currencyCode } - weight - weightUnit - availableForSale - sku - requiresShipping - id - quantityAvailable + } } } @@ -64,4 +66,5 @@ query( $cursor: String, $limit : Int, $sortKey : ProductSortKeys, $query: String hasNextPage } } -}'''; +} +'''; diff --git a/lib/mixins/src/shopfiy_error.dart b/lib/mixins/src/shopfiy_error.dart index ee925588..6c65813d 100644 --- a/lib/mixins/src/shopfiy_error.dart +++ b/lib/mixins/src/shopfiy_error.dart @@ -1,45 +1,40 @@ import 'package:graphql/client.dart'; mixin ShopifyError { - void checkForError(QueryResult queryResult, {String key, String errorKey}) { - if (queryResult.hasException) - throw Exception(queryResult.exception.toString()); + /// throws a [OperationException] if the operation was wrong + /// throws a [ShopifyException] if shopify reports an error + void checkForError(QueryResult queryResult, {String? key, String? errorKey}) { + if (queryResult.hasException) throw queryResult.exception!; if (key != null && errorKey != null) { - Map data = (queryResult?.data as LazyCacheMap)?.data; - Map content = data[key]; - List errors = content[errorKey]; - if (errors.length != 0) { - throw Exception(errors); - } - } - } - - /// Checks and throws an [CheckoutCompleteException] when - /// the [QueryResult] contains checkout errors - /// also run [checkForError] for normal error handling - void checkForCheckoutError(QueryResult queryResult) { - checkForError(queryResult); - - final checkoutCompleteFreeData = queryResult.data['checkoutCompleteFree']; - if (checkoutCompleteFreeData != null) { - if (checkoutCompleteFreeData['checkoutUserErrors']?.isNotEmpty) { - checkoutCompleteFreeData['checkoutUserErrors'].forEach((error)=>print(error.data)); - throw CheckoutCompleteException('Error on checkoutCompleteFree', errors: checkoutCompleteFreeData['checkoutUserErrors']); + Map data = queryResult.data as Map; + final content = data[key] as dynamic; + if (content == null) return; + List? errors = content[errorKey] as List?; + if (errors != null && errors.isNotEmpty) { + errors.forEach((error) => print(error)); + throw ShopifyException(key, errorKey, errors: errors); } } } } - -/// Exception thrown when a checkout fails +/// Exception thrown when an api call fails /// like when some items are out of stock -class CheckoutCompleteException implements Exception { - /// A message describing the issue - final String message; +class ShopifyException implements Exception { + /// The shopify operation in which the error occurred + final String key; + + /// The type of the error + final String errorKey; /// The list of errors, might contains items out of stock or other item-related /// errors - final List errors; + final List? errors; - const CheckoutCompleteException(this.message, {this.errors}); -} + const ShopifyException(this.key, this.errorKey, {this.errors}); + + @override + String toString() { + return "$errorKey during $key: $errors"; + } +} \ No newline at end of file diff --git a/lib/models/models.dart b/lib/models/models.dart index 405d3080..a472ef52 100644 --- a/lib/models/models.dart +++ b/lib/models/models.dart @@ -5,4 +5,5 @@ export 'src/product.dart'; export 'src/shopify_user.dart'; export 'src/article.dart'; export 'src/blog.dart'; -export 'src/shop.dart'; \ No newline at end of file +export 'src/shop.dart'; +export 'src/page.dart'; \ No newline at end of file diff --git a/lib/models/src/article.dart b/lib/models/src/article.dart index 6fa44957..235026b3 100644 --- a/lib/models/src/article.dart +++ b/lib/models/src/article.dart @@ -2,64 +2,89 @@ import 'package:flutter_simple_shopify/models/src/product.dart'; class Articles { final List
articleList; + final bool? hasNextPage; - Articles({this.articleList}); + Articles({required this.articleList, required this.hasNextPage}); - static Articles fromJson(Map json){ + static Articles fromJson(Map json) { return Articles( - articleList: _getArticleList(json ?? const {}) - ); + articleList: _getArticleList(json), + hasNextPage: (json['pageInfo'] ?? const {})['hasNextPage']); } static _getArticleList(Map json) { List
articleList = []; - json['edges']?.forEach((article) => articleList.add(Article.fromJson(article ?? const {})) ); + json['edges']?.forEach( + (article) => articleList.add(Article.fromJson(article ?? const {}))); return articleList; } } class Article { - final AuthorV2 author; - final List commentList; - final String content; - final String contentHtml; - final String excerpt; - final String excerptHtml; - final String handle; - final String id; - final ShopifyImage image; - final String publishedAt; - final List tags; - final String title; - final String url; - - Article({this.author, this.commentList, this.content, this.contentHtml, this.excerpt, this.excerptHtml, this.handle, this.id, this.image, this.publishedAt, this.tags, this.title, this.url}); - - static Article fromJson(Map json){ + final String? cursor; + final AuthorV2? author; + final List? commentList; + final String? content; + final String? contentHtml; + final String? excerpt; + final String? excerptHtml; + final String? handle; + final String? id; + final ShopifyImage? image; + final DateTime? publishedAt; + final List? tags; + final String? title; + final String? url; + + Article( + {this.cursor, + this.author, + this.commentList, + this.content, + this.contentHtml, + this.excerpt, + this.excerptHtml, + this.handle, + this.id, + this.image, + this.publishedAt, + this.tags, + this.title, + this.url}); + + static Article fromJson(Map json) { + DateTime? publishedAt = (json['node'] ?? const {})['publishedAt'] != null + ? DateTime.parse((json['node'] ?? const {})['publishedAt']) + : null; return Article( - author: AuthorV2.fromJson(((json['node'] ?? const {})['authorV2']) ?? const {}), - commentList: _getCommentList((json['node'] ?? const {})['comments'] ?? const {}), + cursor: json['cursor'], + author: AuthorV2.fromJson( + ((json['node'] ?? const {})['authorV2']) ?? const {}), + commentList: + _getCommentList((json['node'] ?? const {})['comments'] ?? const {}), content: (json['node'] ?? const {})['content'], contentHtml: (json['node'] ?? const {})['contentHtml'], excerpt: (json['node'] ?? const {})['excerpt'], excerptHtml: (json['node'] ?? const {})['excerptHtml'], handle: (json['node'] ?? const {})['handle'], id: (json['node'] ?? const {})['id'], - image: ShopifyImage.fromJson((json['node'] ?? const {})['image'] ?? const {}), - publishedAt: (json['node'] ?? const {})['publishedAt'], - tags: _getTagsList(json ?? const {}), + image: ShopifyImage.fromJson( + (json['node'] ?? const {})['image'] ?? const {}), + publishedAt: publishedAt, + tags: _getTagsList(json), title: (json['node'] ?? const {})['title'], url: (json['node'] ?? const {})['url'], ); } - static _getCommentList(Map json){ + static _getCommentList(Map json) { List commentList = []; - json['edges']?.forEach((comment) => commentList.add(Comment.fromJson(comment ?? const {}))); + json['edges']?.forEach( + (comment) => commentList.add(Comment.fromJson(comment ?? const {}))); return commentList; } - static _getTagsList(Map json){ + static _getTagsList(Map json) { List tagsList = []; (json['node'] ?? const {})['tags']?.forEach((tag) => tagsList.add(tag)); return tagsList; @@ -67,43 +92,39 @@ class Article { } class Comment { - final String email; - final String name; - final String content; - final String contentHtml; - final String id; + final String? email; + final String? name; + final String? content; + final String? contentHtml; + final String? id; Comment({this.email, this.name, this.content, this.contentHtml, this.id}); - static Comment fromJson(Map json){ + static Comment fromJson(Map json) { return Comment( email: ((json['node'] ?? const {})['author'] ?? const {})['email'], name: ((json['node'] ?? const {})['author'] ?? const {})['name'], content: (json['node'] ?? const {})['content'], contentHtml: (json['node'] ?? const {})['contentHtml'], - id: (json['node'] ?? const {})['id'] - ); + id: (json['node'] ?? const {})['id']); } } class AuthorV2 { - final String bio; - final String email; - final String firstName; - final String lastName; - final String name; + final String? bio; + final String? email; + final String? firstName; + final String? lastName; + final String? name; AuthorV2({this.bio, this.email, this.firstName, this.lastName, this.name}); - static AuthorV2 fromJson(Map json){ + static AuthorV2 fromJson(Map json) { return AuthorV2( bio: json['bio'], email: json['email'], firstName: json['firstName'], lastName: json['lastName'], - name: json['name'] - ); + name: json['name']); } - - -} \ No newline at end of file +} diff --git a/lib/models/src/blog.dart b/lib/models/src/blog.dart index 3009626e..893d3f1a 100644 --- a/lib/models/src/blog.dart +++ b/lib/models/src/blog.dart @@ -3,13 +3,13 @@ import 'package:flutter_simple_shopify/models/src/article.dart'; class Blogs { - Blogs({this.blogList}); + Blogs({required this.blogList}); final List blogList; static Blogs fromJson(Map json){ return Blogs( - blogList: _getBlogList(json ?? const {}) + blogList: _getBlogList(json) ); } @@ -22,11 +22,11 @@ class Blogs { class Blog { - final String id; - final String handle; - final String title; - final String url; - final Articles articles; + final String? id; + final String? handle; + final String? title; + final String? url; + final Articles? articles; Blog({this.id, this.handle, this.title, this.url, this.articles}); diff --git a/lib/models/src/checkout.dart b/lib/models/src/checkout.dart index 58e2b69e..fc8c2211 100644 --- a/lib/models/src/checkout.dart +++ b/lib/models/src/checkout.dart @@ -1,242 +1,365 @@ +import 'package:flutter_simple_shopify/models/src/order.dart'; import 'package:flutter_simple_shopify/models/src/product.dart'; -class Checkout{ - final String id; - final String email; +import '../../flutter_simple_shopify.dart'; + +class Checkout { + final String? id; + final String? email; + final DiscountApplications discountApplications; final List appliedGiftcards; - final AvailableShippingRates availableShippingrates; - final ShippingRates shippingLine; + final AvailableShippingRates? availableShippingrates; + final ShippingRate shippingLine; final MailingAddress shippingAddress; - final String completedAt; - final String createdAt; - final String currencyCode; + final String? completedAt; + final String? createdAt; + final String? currencyCode; final LineItems lineItems; - final String note; - final String webUrl; - final String updatedAt; + final String? note; + final String? webUrl; + final String? updatedAt; + final PriceV2 lineItemsSubtotalPrice; + final PriceV2 discountAmount; + final PriceV2 paymentDueV2; final PriceV2 totalTaxV2; final PriceV2 totalPriceV2; - final bool taxesIncluded; - final bool taxExempt; + final bool? taxesIncluded; + final bool? taxExempt; final PriceV2 subtotalPriceV2; - final String orderStatusUrl; - final bool requiresShipping; - - Checkout({this.id, this.email, this.appliedGiftcards, - this.availableShippingrates, this.shippingLine,this.shippingAddress, this.completedAt, this.createdAt, - this.currencyCode, this.lineItems, this.note, this.webUrl, this.updatedAt, - this.totalTaxV2, this.totalPriceV2, this.taxesIncluded, this.taxExempt, - this.subtotalPriceV2, this.orderStatusUrl, this.requiresShipping}); - - - static Checkout fromJson(Map json){ + final String? orderStatusUrl; + final Order? order; + final bool? requiresShipping; + + Checkout( + {this.id, + this.email, + required this.discountApplications, + required this.appliedGiftcards, + this.availableShippingrates, + required this.shippingLine, + required this.shippingAddress, + this.completedAt, + this.createdAt, + this.currencyCode, + required this.lineItems, + this.note, + this.webUrl, + this.updatedAt, + required this.totalTaxV2, + required this.totalPriceV2, + required this.lineItemsSubtotalPrice, + required this.discountAmount, + required this.paymentDueV2, + this.taxesIncluded, + this.taxExempt, + required this.subtotalPriceV2, + this.orderStatusUrl, + this.order, + this.requiresShipping}); + + static Checkout fromJson(Map json) { + bool? taxesIncluded = json['taxesIncluded']; + PriceV2 totalTaxV2 = PriceV2.fromJson(json['totalTaxV2'] ?? const {}); + PriceV2 lineItemsSubtotalPrice = + PriceV2.fromJson(json['lineItemsSubtotalPrice'] ?? const {}); + PriceV2 totalPriceV2 = PriceV2.fromJson(json['totalPriceV2'] ?? const {}); + ShippingRate shippingLine = + ShippingRate.fromJson(json['shippingLine'] ?? const {}); + String? amount; + String? currencyCode; + if (lineItemsSubtotalPrice.amount != null && totalPriceV2.amount != null) { + double amt = (totalPriceV2.amount! - lineItemsSubtotalPrice.amount!); + if (totalTaxV2.amount != null && !taxesIncluded!) { + amt -= totalTaxV2.amount!; + } + if (shippingLine.priceV2.amount != null) { + amt -= shippingLine.priceV2.amount!; + } + amount = amt.abs().toStringAsFixed(2); + currencyCode = totalPriceV2.currencyCode; + } return Checkout( id: json['id'], email: json['email'], - appliedGiftcards: _getAppliedGiftCards(json ?? const {}), - availableShippingrates: AvailableShippingRates.fromJson(json['availableShippingRates'] ?? const {}), - shippingLine: ShippingRates.fromJson(json['shippingLine'] ?? const {}), - shippingAddress: MailingAddress.fromJson(json['shippingAddress'] ?? const {}), + discountApplications: + DiscountApplications.fromJson(json['discountApplications']), + appliedGiftcards: _getAppliedGiftCards(json), + availableShippingrates: AvailableShippingRates.fromJson( + json['availableShippingRates'] ?? const {}), + shippingLine: shippingLine, + shippingAddress: + MailingAddress.fromJson(json['shippingAddress'] ?? const {}), completedAt: json['completedAt'], createdAt: json['createdAt'], currencyCode: json['currencyCode'], - lineItems: LineItems.fromJson(json['lineItems']), + lineItems: json['lineItems'] != null ? LineItems.fromJson(json['lineItems']) : LineItems(lineItemList:[]), note: json['note'], webUrl: json['webUrl'], updatedAt: json['updatedAt'], - totalTaxV2: PriceV2.fromJson(json['totalTaxV2'] ?? const {}), - totalPriceV2: PriceV2.fromJson(json['totalPriceV2'] ?? const {}), - taxesIncluded: json['taxesIncluded'], + lineItemsSubtotalPrice: lineItemsSubtotalPrice, + discountAmount: PriceV2.fromJson( + {'amount': amount, 'currencyCode': currencyCode}), + paymentDueV2: PriceV2.fromJson(json['paymentDueV2'] ?? const {}), + totalTaxV2: totalTaxV2, + totalPriceV2: totalPriceV2, + taxesIncluded: taxesIncluded, taxExempt: json['taxExempt'], subtotalPriceV2: PriceV2.fromJson(json['subtotalPriceV2'] ?? const {}), orderStatusUrl: json['orderStatusUrl'], - requiresShipping: json['requiresShipping'] - ); + order: json['order']!=null ? Order.fromJson(json['order']) : null, + requiresShipping: json['requiresShipping']); } - static List _getAppliedGiftCards(Map json) { + static List _getAppliedGiftCards( + Map json) { List appliedGiftCardsList = []; - json['appliedGiftCards']?.forEach((e) => appliedGiftCardsList.add(AppliedGiftCards.fromJson(e ?? const {}))); + json['appliedGiftCards']?.forEach((e) => + appliedGiftCardsList.add(AppliedGiftCards.fromJson(e ?? const {}))); return appliedGiftCardsList; } - - - } - - class AvailableShippingRates { - final bool ready; - final List shippingRates; + final bool? ready; + final List shippingRates; + const AvailableShippingRates({this.ready, required this.shippingRates}); - const AvailableShippingRates({this.ready, this.shippingRates}); - - static AvailableShippingRates fromJson(Map json){ + static AvailableShippingRates fromJson(Map json) { return AvailableShippingRates( ready: json['ready'], - shippingRates: _getShippingRates(json ?? const {}), + shippingRates: _getShippingRates(json), ); } - static List _getShippingRates(Map json) { - List shippingRatesList = []; - json['shippingRates']?.forEach((e) => shippingRatesList.add(ShippingRates.fromJson(e ?? const {}))); + + static List _getShippingRates(Map json) { + List shippingRatesList = []; + json['shippingRates']?.forEach( + (e) => shippingRatesList.add(ShippingRate.fromJson(e ?? const {}))); return shippingRatesList; } - } - - -class ShippingRates { - final String handle; - final String title; +class ShippingRate { + final String? handle; + final String? title; final PriceV2 priceV2; - ShippingRates({this.handle, this.title, this.priceV2}); + ShippingRate({this.handle, this.title, required this.priceV2}); - static ShippingRates fromJson(Map json){ - return ShippingRates( + static ShippingRate fromJson(Map json) { + return ShippingRate( handle: json['handle'], title: json['title'], - priceV2: PriceV2.fromJson(json['priceV2'] ?? const {}) - ); + priceV2: PriceV2.fromJson(json['priceV2'] ?? const {})); } } + class MailingAddress { - final String address1; - final String address2; - final String city; - final String company; - final String country; - final String countryCodeV2; - final String firstName; - final String formattedArea; - final String id; - final String lastName; - final double latitude; - final double longitude; - final String name; - final String phone; - final String province; - final String provinceCode; - final String zip; - - MailingAddress({this.address1, this.address2, this.city,this.company, this.country, this.countryCodeV2,this.firstName, this.formattedArea, this.id,this.lastName, this.latitude, this.longitude, this.name, this.phone, this.province, this.provinceCode, this.zip}); - - static MailingAddress fromJson(Map json){ + final String? address1; + final String? address2; + final String? city; + final String? company; + final String? country; + final String? countryCodeV2; + final String? firstName; + final String? formattedArea; + final String? id; + final String? lastName; + final double? latitude; + final double? longitude; + final String? name; + final String? phone; + final String? province; + final String? provinceCode; + final String? zip; + + MailingAddress( + {this.address1, + this.address2, + this.city, + this.company, + this.country, + this.countryCodeV2, + this.firstName, + this.formattedArea, + this.id, + this.lastName, + this.latitude, + this.longitude, + this.name, + this.phone, + this.province, + this.provinceCode, + this.zip}); + + static MailingAddress fromJson(Map json) { return MailingAddress( - address1: json['address1'], - address2: json['address2'], - city: json['city'], - company: json['company'], - country: json['country'], - countryCodeV2: json['countryCodeV2'], - firstName: json['firstName'], - formattedArea: json['formattedArea'], - id: json['id'], - lastName: json['lastName'], - latitude: json['latitude'], - longitude: json['longitude'], - name: json['name'], - phone: json['phone'], - province: json['province'], - provinceCode: json['provinceCode'], - zip: json['zip'], + address1: json['address1'], + address2: json['address2'], + city: json['city'], + company: json['company'], + country: json['country'], + countryCodeV2: json['countryCodeV2'], + firstName: json['firstName'], + formattedArea: json['formattedArea'], + id: json['id'], + lastName: json['lastName'], + latitude: json['latitude'], + longitude: json['longitude'], + name: json['name'], + phone: json['phone'], + province: json['province'], + provinceCode: json['provinceCode'], + zip: json['zip'], ); } } -class LineItems{ + +class LineItems { final List lineItemList; - LineItems({this.lineItemList}); + LineItems({required this.lineItemList}); - static LineItems fromJson(Map json){ - return LineItems( - lineItemList: _getLineItemList(json) - ); + static LineItems fromJson(Map json) { + return LineItems(lineItemList: _getLineItemList(json)); } - static List _getLineItemList(Map json){ + + static List _getLineItemList(Map json) { List lineItemList = []; - json['edges']?.forEach((lineItem) => lineItemList.add(LineItem.fromJson(lineItem ?? const {}))); + json['edges']?.forEach((lineItem) => + lineItemList.add(LineItem.fromJson(lineItem ?? const {}))); return lineItemList; } } class LineItem { - final String id; - final int quantity; - final String title; - final ProductVariantCheckout variant; + final String? id; + final int? quantity; + final String? title; + final ProductVariantCheckout? variant; LineItem({this.id, this.quantity, this.variant, this.title}); - static LineItem fromJson(Map json){ + static LineItem fromJson(Map json) { return LineItem( id: (json['node'] ?? const {})['id'], quantity: (json['node'] ?? const {})['quantity'], - variant: ProductVariantCheckout.fromJson(((json['node'] ?? const {})['variant'] ?? const{})), + variant: ProductVariantCheckout.fromJson( + ((json['node'] ?? const {})['variant'] ?? const {})), title: (json['node'] ?? const {})['title'], ); } } +class DiscountApplications { + final List discountApplicationList; + + DiscountApplications({required this.discountApplicationList}); + + get length => discountApplicationList.length; + + static DiscountApplications fromJson(Map? json) { + return DiscountApplications( + discountApplicationList: _getDiscountApplicationList(json)); + } + + static List _getDiscountApplicationList( + Map? json) { + List discountApplicationList = []; + if (json != null) + json['edges']?.forEach((discountApplication) => discountApplicationList + .add(DiscountApplication.fromJson(discountApplication ?? const {}))); + return discountApplicationList; + } +} + +class DiscountApplication { + final String? allocationMethod; + final String? targetSelection; + final String? targetType; + final double? percentage; + final PriceV2 price; + + DiscountApplication( + {this.allocationMethod, + this.targetSelection, + this.targetType, + this.percentage, + required this.price}); + + static DiscountApplication fromJson(Map json) { + // print(json); + return DiscountApplication( + allocationMethod: (json['node'] ?? const {})['allocationMethod'], + targetSelection: (json['node'] ?? const {})['targetSelection'], + targetType: (json['node'] ?? const {})['targetType'], + percentage: + (((json['node'] ?? const {})['value'] ?? const {})['percentage'] ?? + null), + price: + PriceV2.fromJson(((json['node'] ?? const {})['value'] ?? const {})), + ); + } +} + class ProductVariantCheckout { final PriceV2 price; - final String title; + final String? title; final ShopifyImage image; final PriceV2 compareAtPrice; - final double weight; - final String weightUnit; - final bool availableForSale; - final String sku; - final bool requiresShipping; - final String id; + final double? weight; + final String? weightUnit; + final bool? availableForSale; + final String? sku; + final bool? requiresShipping; + final String? id; + final Product? product; const ProductVariantCheckout( - {this.price, - this.title, - this.image, - this.compareAtPrice, - this.weight, - this.weightUnit, - this.availableForSale, - this.sku, - this.requiresShipping, - this.id}); + {required this.price, + this.title, + required this.image, + required this.compareAtPrice, + this.weight, + this.weightUnit, + this.availableForSale, + this.sku, + this.requiresShipping, + this.id, + this.product}); static ProductVariantCheckout fromJson(Map json) { + print('object'); return ProductVariantCheckout( - price: - PriceV2.fromJson(json['priceV2'] ?? const {}), + price: PriceV2.fromJson(json['priceV2'] ?? const {}), title: json['title'], image: ShopifyImage.fromJson(json['image'] ?? const {}), - compareAtPrice: PriceV2.fromJson( - json['compareAtPriceV2'] ?? const {} ), - weight: json['weight'] , + compareAtPrice: PriceV2.fromJson(json['compareAtPriceV2'] ?? const {}), + weight: json['weight'], weightUnit: json['weightUnit'], - availableForSale: json['availableForSale'] , - sku: json['sku'] , + availableForSale: json['availableForSale'], + sku: json['sku'], requiresShipping: json['requiresShipping'], - id: json['id'] , + id: json['id'], + product: json['product'] !=null ? Product.fromProductHandleJson(json['product']) : null ); } } class AppliedGiftCards { - final PriceV2 amountUsedV2; final PriceV2 balanceV2; - final String id; + final String lastCharacters; + final String? id; - AppliedGiftCards({this.amountUsedV2, this.balanceV2, this.id}); + AppliedGiftCards({required this.amountUsedV2, required this.balanceV2, required this.lastCharacters, this.id}); - static AppliedGiftCards fromJson(Map json){ + static AppliedGiftCards fromJson(Map json) { return AppliedGiftCards( amountUsedV2: PriceV2.fromJson(json['amountUsedV2'] ?? const {}), balanceV2: PriceV2.fromJson(json['balanceV2'] ?? const {}), - id: json['id'] - ); + lastCharacters: json['lastCharacters'], + id: json['id']); } -} \ No newline at end of file +} diff --git a/lib/models/src/collection.dart b/lib/models/src/collection.dart index 1a9daca2..e8f32fff 100644 --- a/lib/models/src/collection.dart +++ b/lib/models/src/collection.dart @@ -2,13 +2,13 @@ import 'package:flutter_simple_shopify/models/src/product.dart'; class Collections { final List collectionList; - final bool hasNextPage; + final bool? hasNextPage; - Collections({this.collectionList, this.hasNextPage}); + Collections({required this.collectionList, required this.hasNextPage}); static Collections fromJson(Map json) { return Collections( - collectionList: _getCollectionList(json ?? const {}), + collectionList: _getCollectionList(json), hasNextPage: (json['pageInfo'] ?? const {})['hasNextPage']); } @@ -21,15 +21,15 @@ class Collections { } class Collection { - final String title; - final String description; - final String descriptionHtml; - final String handle; - final String id; - final String updatedAt; - final ShopifyImage image; - final Products products; - final String cursor; + final String? title; + final String? description; + final String? descriptionHtml; + final String? handle; + final String? id; + final String? updatedAt; + final ShopifyImage? image; + final Products? products; + final String? cursor; Collection( {this.title, @@ -57,4 +57,19 @@ class Collection { cursor: json['cursor'], ); } + static Collection fromCollectionHandleJson(Map json) { + return Collection( + title: json['title'], + description: json['description'], + descriptionHtml: json['descriptionHtml'], + handle: json['handle'], + id: json['id'], + updatedAt: json['updatedAt'], + image: ShopifyImage.fromJson( + json['image'] ?? const {}), + products: + Products.fromJson(json['products'] ?? const {}), + cursor: json['cursor'], + ); + } } diff --git a/lib/models/src/order.dart b/lib/models/src/order.dart index e452178d..ee17dc52 100644 --- a/lib/models/src/order.dart +++ b/lib/models/src/order.dart @@ -1,173 +1,251 @@ +import 'package:enum_to_string/enum_to_string.dart'; +import 'package:flutter_simple_shopify/enums/src/order_enums.dart'; +// import 'package:flutter_simple_shopify/enums/enums.dart'; import 'package:flutter_simple_shopify/models/src/product.dart'; import 'checkout.dart'; - class Orders { final List orderList; - final bool hasNextPage; + final bool? hasNextPage; - Orders({this.orderList, this.hasNextPage}); + Orders({required this.orderList, required this.hasNextPage}); - static Orders fromJson(Map json){ + static Orders fromJson(Map json) { return Orders( - orderList: _getOrderList(json ?? const {}), - hasNextPage: (json['pageInfo'] ?? const {})['hasNextPage'] - ); + orderList: _getOrderList(json), + hasNextPage: (json['pageInfo'] ?? const {})['hasNextPage']); } - static List_getOrderList(Map json) { + static List _getOrderList(Map json) { List orderList = []; - json['edges']?.forEach((e) => orderList.add(Order.fromJson(e ?? const {}))); + json['edges'] + ?.forEach((e) => orderList.add(Order.fromJson(e['node'] ?? const {}))); return orderList; } - } class Order { - final String id; - final String email; - final String currencyCode; - final String customerUrl; - final LineItemsOrder lineItems; - final String name; - final int orderNumber; - final String phone; - final String processedAt; - final ShippingAddress shippingAddress; - final String statusUrl; - final PriceV2 subtotalPriceV2; - final PriceV2 totalPriceV2; - final PriceV2 totalRefundedV2; - final PriceV2 totalShippingPriceV2; - final PriceV2 totalTaxV2; - final String cursor; - - Order({this.id, this.email, this.currencyCode, this.customerUrl, this.lineItems, this.name, this.orderNumber, this.phone, this.processedAt, this.shippingAddress, this.statusUrl, this.subtotalPriceV2, this.totalPriceV2, this.totalRefundedV2, this.totalShippingPriceV2, this.totalTaxV2, this.cursor}); - - static Order fromJson(Map json){ + final String? id; + final String? email; + final String? currencyCode; + final String? customerUrl; + final LineItemsOrder? lineItems; + final String? name; + final int? orderNumber; + final String? phone; + final DateTime? processedAt; + final DateTime? canceledAt; + final OrderCancelReason? cancelReason; + final OrderFinancialStatus? financialStatus; + final OrderFulfillmentStatus? fulfillmentStatus; + final MailingAddress? shippingAddress; + final String? statusUrl; + final DiscountApplications? discountApplications; + final PriceV2? subtotalPriceV2; + final PriceV2? totalPriceV2; + final PriceV2? totalRefundedV2; + final PriceV2? totalShippingPriceV2; + final PriceV2? totalTaxV2; + final String? cursor; + + Order( + {this.id, + this.email, + this.currencyCode, + this.customerUrl, + this.lineItems, + this.name, + this.orderNumber, + this.phone, + this.processedAt, + this.canceledAt, + this.cancelReason, + this.financialStatus, + this.fulfillmentStatus, + this.shippingAddress, + this.statusUrl, + this.discountApplications, + this.subtotalPriceV2, + this.totalPriceV2, + this.totalRefundedV2, + this.totalShippingPriceV2, + this.totalTaxV2, + this.cursor}); + + static Order fromJson(Map? json) { + DateTime processedAt = DateTime.parse((json ?? const {})['processedAt']); + DateTime? canceledAt = (json ?? const {})['canceledAt'] != null + ? DateTime.parse((json ?? const {})['canceledAt']) + : null; + OrderFinancialStatus? financialStatus = + (json ?? const {})['financialStatus'] != null + ? EnumToString.fromString(OrderFinancialStatus.values, + (json ?? const {})['financialStatus']) + : null; + OrderFulfillmentStatus? fulfillmentStatus = + (json ?? const {})['fulfillmentStatus'] != null + ? EnumToString.fromString(OrderFulfillmentStatus.values, + (json ?? const {})['fulfillmentStatus']) + : null; + OrderCancelReason? cancelReason = (json ?? const {})['cancelReason'] != null + ? EnumToString.fromString( + OrderCancelReason.values, (json ?? const {})['cancelReason']) + : null; + return Order( - id: (json['node'] ?? const {})['id'], - email: (json['node'] ?? const {})['email'], - currencyCode: (json['node'] ?? const {})['currencyCode'], - customerUrl: (json['node'] ?? const {})['customerUrl'], - lineItems: LineItemsOrder.fromJson((json['node'] ?? const {})['lineItems']), - name: (json['node'] ?? const {})['name'], - orderNumber: (json['node'] ?? const {})['orderNumber'], - phone: (json['node'] ?? const {})['phone'], - processedAt: (json['node'] ?? const {})['processedAt'], - shippingAddress: ShippingAddress.fromJson((json['node'] ?? const {})['shippingAddress'] ?? const {}), - statusUrl: (json['node'] ?? const {})['statusUrl'], - subtotalPriceV2: PriceV2.fromJson((json['node'] ?? const {})['subtotalPriceV2'] ?? const {}), - totalPriceV2: PriceV2.fromJson((json['node'] ?? const {})['totalPriceV2'] ?? const {}), - totalRefundedV2: PriceV2.fromJson((json['node'] ?? const {})['totalRefundedV2'] ?? const {}), - totalShippingPriceV2: PriceV2.fromJson((json['node'] ?? const {})['totalShippingPriceV2'] ?? const {}), - totalTaxV2: PriceV2.fromJson((json['node'] ?? const {})['totalTaxV2'] ?? const {}), - cursor: json['cursor'] - ); + id: (json ?? const {})['id'], + email: (json ?? const {})['email'], + currencyCode: (json ?? const {})['currencyCode'], + customerUrl: (json ?? const {})['customerUrl'], + lineItems: LineItemsOrder.fromJson((json ?? const {})['lineItems'] ?? {}), + name: (json ?? const {})['name'], + orderNumber: (json ?? const {})['orderNumber'], + phone: (json ?? const {})['phone'], + processedAt: processedAt, + canceledAt: canceledAt, + cancelReason: cancelReason, + financialStatus: financialStatus, + fulfillmentStatus: fulfillmentStatus, + shippingAddress: MailingAddress.fromJson( + (json ?? const {})['shippingAddress'] ?? const {}), + statusUrl: (json ?? const {})['statusUrl'], + discountApplications: DiscountApplications.fromJson( + (json ?? const {})['discountApplications']), + subtotalPriceV2: + PriceV2.fromJson((json ?? const {})['subtotalPriceV2'] ?? const {}), + totalPriceV2: + PriceV2.fromJson((json ?? const {})['totalPriceV2'] ?? const {}), + totalRefundedV2: + PriceV2.fromJson((json ?? const {})['totalRefundedV2'] ?? const {}), + totalShippingPriceV2: PriceV2.fromJson( + (json ?? const {})['totalShippingPriceV2'] ?? const {}), + totalTaxV2: + PriceV2.fromJson((json ?? const {})['totalTaxV2'] ?? const {}), + cursor: json?['cursor']); } } class LineItemsOrder { - final List lineItemOrderList; + final List? lineItemOrderList; LineItemsOrder({this.lineItemOrderList}); - static LineItemsOrder fromJson(Map json){ - return LineItemsOrder( - lineItemOrderList: _getLineItemOrderList(json) - ); + static LineItemsOrder fromJson(Map json) { + return LineItemsOrder(lineItemOrderList: _getLineItemOrderList(json)); } static _getLineItemOrderList(Map json) { List lineItemListOrder = []; - json['edges']?.forEach((lineItemOrder) => lineItemListOrder.add(LineItemOrder.fromJson(lineItemOrder))); + json['edges']?.forEach((lineItemOrder) => + lineItemListOrder.add(LineItemOrder.fromJson(lineItemOrder))); return lineItemListOrder; } - } class LineItemOrder { - final int currentQuantity; + final int? currentQuantity; final List discountAllocations; final PriceV2 discountedTotalPrice; final PriceV2 originalTotalPrice; - final int quantity; - final String title; + final int? quantity; + final String? title; final ProductVariantCheckout variant; - LineItemOrder({this.currentQuantity, this.discountAllocations, this.discountedTotalPrice, this.originalTotalPrice, this.quantity, this.title, this.variant}); + LineItemOrder( + {this.currentQuantity, + required this.discountAllocations, + required this.discountedTotalPrice, + required this.originalTotalPrice, + this.quantity, + this.title, + required this.variant}); - static LineItemOrder fromJson(Map json){ + static LineItemOrder fromJson(Map json) { return LineItemOrder( currentQuantity: (json['node'] ?? const {})['currentQuantity'], discountAllocations: _getDiscountAllocationsList(json), - discountedTotalPrice: PriceV2.fromJson((json['node'] ?? const {})['discountedTotalPrice']), - originalTotalPrice: PriceV2.fromJson((json['node'] ?? const {})['originalTotalPrice']), + discountedTotalPrice: PriceV2.fromJson( + (json['node'] ?? const {})['discountedTotalPrice'] ?? const {}), + originalTotalPrice: PriceV2.fromJson( + (json['node'] ?? const {})['originalTotalPrice'] ?? const {}), quantity: (json['node'] ?? const {})['quantity'], title: (json['node'] ?? const {})['title'], - variant: ProductVariantCheckout.fromJson((json['node'] ?? const {})['variant'] ?? const {}) - ); + variant: ProductVariantCheckout.fromJson((json['node'] ?? const {})['variant'] ?? {})); } static _getDiscountAllocationsList(Map json) { List discountList = []; - (json['node'] ?? const {})['discountAllocations']?.forEach((discount) => discountList.add(DiscountAllocations.fromJson(discount))); + (json['node'] ?? const {})['discountAllocations']?.forEach((discount) => + discountList.add(DiscountAllocations.fromJson(discount ?? const {}))); return discountList; } - } class DiscountAllocations { final PriceV2 allocatedAmount; - DiscountAllocations({this.allocatedAmount}); + DiscountAllocations({required this.allocatedAmount}); - static DiscountAllocations fromJson(Map json){ + static DiscountAllocations fromJson(Map json) { return DiscountAllocations( - allocatedAmount: PriceV2.fromJson(json['allocatedAmount'] ?? const {}) - ); + allocatedAmount: PriceV2.fromJson(json['allocatedAmount'] ?? const {})); } } -class ShippingAddress { - final String address1; - final String address2; - final String city; - final String company; - final String country; - final String countryCodeV2; - final String firstName; - final String id; - final String lastName; - final double latitude; - final double longitude; - final String name; - final String phone; - final String province; - final String provinceCode; - final String zip; - - ShippingAddress({this.address1, this.address2, this.city, this.company, this.country, this.countryCodeV2, this.firstName, this.id, this.lastName, this.latitude, this.longitude, this.name, this.phone, this.province, this.provinceCode, this.zip}); - - static ShippingAddress fromJson(Map json){ - return ShippingAddress( - address1: json['address1'], - address2: json['address2'], - city: json['city'], - company: json['company'], - country: json['country'], - countryCodeV2: json['countryCodeV2'], - firstName: json['firstName'], - id: json['id'], - lastName: json['lastName'], - latitude: json['latitude'], - longitude: json['longitude'], - name: json['name'], - phone: json['phone'], - province: json['province'], - provinceCode: json['provinceCode'], - zip: json['zip'] - ); - } -} \ No newline at end of file +// class ShippingAddress { +// final String address1; +// final String address2; +// final String city; +// final String company; +// final String country; +// final String countryCodeV2; +// final String firstName; +// final String id; +// final String lastName; +// final double latitude; +// final double longitude; +// final String name; +// final String phone; +// final String province; +// final String provinceCode; +// final String zip; + +// ShippingAddress( +// {this.address1, +// this.address2, +// this.city, +// this.company, +// this.country, +// this.countryCodeV2, +// this.firstName, +// this.id, +// this.lastName, +// this.latitude, +// this.longitude, +// this.name, +// this.phone, +// this.province, +// this.provinceCode, +// this.zip}); + +// static ShippingAddress fromJson(Map json) { +// return ShippingAddress( +// address1: json['address1'], +// address2: json['address2'], +// city: json['city'], +// company: json['company'], +// country: json['country'], +// countryCodeV2: json['countryCodeV2'], +// firstName: json['firstName'], +// id: json['id'], +// lastName: json['lastName'], +// latitude: json['latitude'], +// longitude: json['longitude'], +// name: json['name'], +// phone: json['phone'], +// province: json['province'], +// provinceCode: json['provinceCode'], +// zip: json['zip']); +// } +// } diff --git a/lib/models/src/page.dart b/lib/models/src/page.dart new file mode 100644 index 00000000..75c88740 --- /dev/null +++ b/lib/models/src/page.dart @@ -0,0 +1,23 @@ + + +class ShopifyPage { + + final String? id; + final String? handle; + final String? title; + final String? body; + final String? url; + + ShopifyPage({this.id, this.handle, this.title, this.body, this.url}); + + static ShopifyPage fromJson(Map json){ + return ShopifyPage( + id: json['id'], + handle: json['handle'], + title: json['title'], + body: json['body'], + url: json['onlineStoreUrl'], + ); + } + +} \ No newline at end of file diff --git a/lib/models/src/product.dart b/lib/models/src/product.dart index 72e4055f..878d1e75 100644 --- a/lib/models/src/product.dart +++ b/lib/models/src/product.dart @@ -1,13 +1,96 @@ +import 'dart:convert'; + +import 'package:collection/collection.dart'; +import 'package:flutter_simple_shopify/flutter_simple_shopify.dart'; +import 'package:intl/intl.dart'; + +class Filter { + final String id; + final String label; + final String type; + final List values; + + Filter( + {required this.id, + required this.label, + required this.type, + required this.values}); + + static Filter fromJson(Map json) { + return Filter( + id: json['id'], + label: json['label'], + type: json['type'], + values: FilterValue.getList(json['values']), + ); + } + + static List getList(List jsonList) { + List fList = []; + jsonList.forEach((e) => fList.add(Filter.fromJson(e ?? const {}))); + return fList; + } +} + +class FilterValue { + final String id; + final String label; + final int count; + final Map input; + + FilterValue( + {required this.id, + required this.label, + required this.count, + required this.input}); + + static FilterValue fromJson(Map json) { + return FilterValue( + id: json['id'], + label: json['label'], + count: json['count'], + input: jsonDecode(json['input']), + ); + } + + static List getList(List jsonList) { + List fvList = []; + jsonList.forEach((e) => fvList.add(FilterValue.fromJson(e ?? const {}))); + return fvList; + } + + Map toJson() => { + 'id': id, + 'label': label, + 'count': count, + 'input': jsonEncode(input), + }; + + FilterValue copyWith({String? id, String? label, int? count, Map? input}) { + return FilterValue( + id: id ?? this.id, + label: label ?? this.label, + count: count ?? this.count, + input: input ?? this.input, + ); + } +} + class Products { final List productList; - final bool hasNextPage; + final bool? hasNextPage; + final List? filters; - Products({this.productList, this.hasNextPage}); + Products( + {required this.productList, required this.hasNextPage, this.filters}); static Products fromJson(Map json) { + var a = json['filters']; + print('object'); return Products( - productList: _getProductList(json ?? const {}), - hasNextPage: (json['pageInfo'] ?? const {})['hasNextPage']); + productList: _getProductList(json), + hasNextPage: (json['pageInfo'] ?? const {})['hasNextPage'], + filters: Filter.getList(json['filters'] ?? [])); } static List _getProductList(Map json) { @@ -19,102 +102,169 @@ class Products { } class Product { - final List collectionList; - final String title; - final String id; - final bool availableForSale; - final String createdAt; - final String description; - final List productVariants; - final String descriptionHtml; - final String handle; - final String onlineStoreUrl; - final String productType; - final String publishedAt; - final List tags; - final String updatedAt; - final String cursor; - final List images; - final List