这是indexloc提供的服务,不要输入任何密码
Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,246 @@
/// mutation to update cart discount codes
const String updateGiftCardCodesMutation = r'''
mutation cartGiftCardCodesUpdate($cartId: ID!, $giftCardCodes: [String!]!, $country: CountryCode) @inContext(country: $country) {
cartGiftCardCodesUpdate(cartId: $cartId, giftCardCodes: $giftCardCodes) {
cart {
id
checkoutUrl
createdAt
totalQuantity
cost {
checkoutChargeAmount {
amount
currencyCode
}
subtotalAmount {
amount
currencyCode
}
subtotalAmountEstimated
totalAmount {
amount
currencyCode
}
totalAmountEstimated
totalDutyAmount {
amount
currencyCode
}
totalDutyAmountEstimated
totalTaxAmount {
amount
currencyCode
}
totalTaxAmountEstimated
}
discountAllocations {
discountedAmount {
amount
currencyCode
}
}
discountCodes {
applicable
code
}
appliedGiftCards {
amountUsed {
amount
currencyCode
}
balance {
amount
currencyCode
}
id
lastCharacters
}
note
buyerIdentity {
countryCode
email
phone
deliveryAddressPreferences {
... on MailingAddress {
id
name
address1
address2
city
company
country
countryCodeV2
firstName
formattedArea
formatted
lastName
latitude
longitude
phone
province
provinceCode
zip
}
}
}
lines(first: 250, reverse: true) {
edges {
cursor
node {
id
quantity
cost {
amountPerQuantity {
amount
currencyCode
}
compareAtAmountPerQuantity {
amount
currencyCode
}
subtotalAmount {
amount
currencyCode
}
totalAmount {
amount
currencyCode
}
}
discountAllocations {
discountedAmount {
amount
currencyCode
}
}
sellingPlanAllocation {
sellingPlan {
id
}
}
merchandise {
... on ProductVariant {
id
price {
amount
currencyCode
}
title
image {
altText
originalSrc
id
}
compareAtPrice {
amount
currencyCode
}
weight
weightUnit
availableForSale
quantityAvailable
sku
requiresShipping
product {
options(first: 5) {
id
name
values
}
variants(first: 250) {
edges {
node {
id
title
image {
altText
id
originalSrc
}
priceV2 {
amount
currencyCode
}
compareAtPriceV2 {
amount
currencyCode
}
weight
weightUnit
availableForSale
sku
requiresShipping
quantityAvailable
selectedOptions {
name
value
}
}
}
pageInfo {
hasNextPage
}
}
availableForSale
collections(first: 5) {
edges {
node {
description
descriptionHtml
id
handle
updatedAt
title
}
}
}
createdAt
description
descriptionHtml
handle
id
onlineStoreUrl
productType
publishedAt
tags
title
updatedAt
vendor
images(first: 5) {
edges {
node {
altText
id
originalSrc
}
}
}
media(first: 250) {
edges {
node {
alt
id
mediaContentType
previewImage {
altText
id
originalSrc
}
}
}
}
}
}
}
}
}
}
}
userErrors {
code
field
message
}
}
}
''';
25 changes: 24 additions & 1 deletion lib/shopify/src/shopify_cart.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:graphql_flutter/graphql_flutter.dart';
import 'package:shopify_flutter/graphql_operations/storefront/mutations/cart/cart_buyer_identity_update.dart';
import 'package:shopify_flutter/graphql_operations/storefront/mutations/cart/cart_create.dart';
import 'package:shopify_flutter/graphql_operations/storefront/mutations/cart/cart_discount_code_update_mutation.dart';
Expand All @@ -7,10 +8,10 @@ import 'package:shopify_flutter/graphql_operations/storefront/mutations/cart/car
import 'package:shopify_flutter/graphql_operations/storefront/mutations/cart/cart_note_update.dart';
import 'package:shopify_flutter/graphql_operations/storefront/queries/get_cart_by_id.dart';
import 'package:shopify_flutter/mixins/src/shopify_error.dart';
import 'package:graphql_flutter/graphql_flutter.dart';
import 'package:shopify_flutter/models/src/cart/cart_model.dart';
import 'package:shopify_flutter/shopify/src/shopify_localization.dart';

import '../../graphql_operations/storefront/mutations/cart/cart_gift_card_code_update_mutation.dart';
import '../../shopify_config.dart';

/// ShopifyCart provides various method in order to work with carts.
Expand Down Expand Up @@ -170,6 +171,28 @@ class ShopifyCart with ShopifyError {
const {}));
}

/// update cart Gift Card codes
Future<Cart> updateCartGiftCardCodes({
required String cartId,
required List<String> giftCardCodes,
}) async {
final MutationOptions updateGiftCardCodes = MutationOptions(
document: gql(updateGiftCardCodesMutation),
variables: {
'cartId': cartId,
'giftCardCodes': giftCardCodes,
'country': ShopifyLocalization.countryCode,
},
);
QueryResult result = await _graphQLClient!.mutate(updateGiftCardCodes);
checkForError(result,
key: 'cartGiftCardCodesUpdate', errorKey: 'userErrors');

return Cart.fromJson(
((result.data!['cartGiftCardCodesUpdate'] ?? const {})['cart'] ??
const {}));
}

/// update Buyer identity in cart
Future<Cart> updateBuyerIdentityInCart({
required String cartId,
Expand Down