Skip to content

Commit

Permalink
Applied gift card (#2298)
Browse files Browse the repository at this point in the history
Co-authored-by: Michelle Chen <michelle.chen@shopify.com>
  • Loading branch information
wizardlyhel and michenly authored Aug 16, 2024
1 parent 6e8e2ef commit d929b56
Show file tree
Hide file tree
Showing 35 changed files with 6,358 additions and 12 deletions.
7 changes: 7 additions & 0 deletions .changeset/selfish-frogs-change.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'skeleton': patch
'@shopify/hydrogen': patch
'@shopify/create-hydrogen': patch
---

createCartHandler supplies updateGiftCardCodes method
6 changes: 6 additions & 0 deletions docs/shopify-dev/analytics-setup/js/app/lib/fragments.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,12 @@ export const CART_QUERY_FRAGMENT = `#graphql
updatedAt
// [END query]
id
appliedGiftCards {
lastCharacters
amountUsed {
...Money
}
}
checkoutUrl
totalQuantity
buyerIdentity {
Expand Down
12 changes: 12 additions & 0 deletions docs/shopify-dev/analytics-setup/js/app/routes/cart.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,18 @@ export async function action({request, context}) {
result = await cart.updateDiscountCodes(discountCodes);
break;
}
case CartForm.ACTIONS.GiftCardCodesUpdate: {
const formGiftCardCode = inputs.giftCardCode;

// User inputted gift card code
const giftCardCodes = formGiftCardCode ? [formGiftCardCode] : [];

// Combine gift card codes already applied on cart
giftCardCodes.push(...inputs.giftCardCodes);

result = await cart.updateGiftCardCodes(giftCardCodes);
break;
}
case CartForm.ACTIONS.BuyerIdentityUpdate: {
result = await cart.updateBuyerIdentity({
...inputs.buyerIdentity,
Expand Down
6 changes: 6 additions & 0 deletions docs/shopify-dev/analytics-setup/ts/app/lib/fragments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,12 @@ export const CART_QUERY_FRAGMENT = `#graphql
updatedAt
// [END query]
id
appliedGiftCards {
lastCharacters
amountUsed {
...Money
}
}
checkoutUrl
totalQuantity
buyerIdentity {
Expand Down
14 changes: 14 additions & 0 deletions docs/shopify-dev/analytics-setup/ts/app/routes/cart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,20 @@ export async function action({request, context}: ActionFunctionArgs) {
result = await cart.updateDiscountCodes(discountCodes);
break;
}
case CartForm.ACTIONS.GiftCardCodesUpdate: {
const formGiftCardCode = inputs.giftCardCode;

// User inputted gift card code
const giftCardCodes = (
formGiftCardCode ? [formGiftCardCode] : []
) as string[];

// Combine gift card codes already applied on cart
giftCardCodes.push(...inputs.giftCardCodes);

result = await cart.updateGiftCardCodes(giftCardCodes);
break;
}
case CartForm.ACTIONS.BuyerIdentityUpdate: {
result = await cart.updateBuyerIdentity({
...inputs.buyerIdentity,
Expand Down
6 changes: 6 additions & 0 deletions examples/b2b/app/lib/fragments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,12 @@ export const CART_QUERY_FRAGMENT = `#graphql
fragment CartApiQuery on Cart {
updatedAt
id
appliedGiftCards {
lastCharacters
amountUsed {
...Money
}
}
checkoutUrl
totalQuantity
buyerIdentity {
Expand Down
5 changes: 5 additions & 0 deletions examples/b2b/storefrontapi.generated.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ export type CartApiQueryFragment = Pick<
StorefrontAPI.Cart,
'updatedAt' | 'id' | 'checkoutUrl' | 'totalQuantity' | 'note'
> & {
appliedGiftCards: Array<
Pick<StorefrontAPI.AppliedGiftCard, 'lastCharacters'> & {
amountUsed: Pick<StorefrontAPI.MoneyV2, 'currencyCode' | 'amount'>;
}
>;
buyerIdentity: Pick<
StorefrontAPI.CartBuyerIdentity,
'countryCode' | 'email' | 'phone'
Expand Down
6 changes: 6 additions & 0 deletions examples/custom-cart-method/app/lib/fragments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@ export const CART_QUERY_FRAGMENT = `#graphql
fragment CartApiQuery on Cart {
updatedAt
id
appliedGiftCards {
lastCharacters
amountUsed {
...Money
}
}
checkoutUrl
totalQuantity
buyerIdentity {
Expand Down
14 changes: 14 additions & 0 deletions examples/custom-cart-method/app/routes/cart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,20 @@ export async function action({request, context}: ActionFunctionArgs) {
result = await cart.updateDiscountCodes(discountCodes);
break;
}
case CartForm.ACTIONS.GiftCardCodesUpdate: {
const formGiftCardCode = inputs.giftCardCode;

// User inputted gift card code
const giftCardCodes = (
formGiftCardCode ? [formGiftCardCode] : []
) as string[];

// Combine gift card codes already applied on cart
giftCardCodes.push(...inputs.giftCardCodes);

result = await cart.updateGiftCardCodes(giftCardCodes);
break;
}
case CartForm.ACTIONS.BuyerIdentityUpdate: {
result = await cart.updateBuyerIdentity({
...inputs.buyerIdentity,
Expand Down
5 changes: 5 additions & 0 deletions examples/custom-cart-method/storefrontapi.generated.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ export type CartApiQueryFragment = Pick<
StorefrontAPI.Cart,
'updatedAt' | 'id' | 'checkoutUrl' | 'totalQuantity' | 'note'
> & {
appliedGiftCards: Array<
Pick<StorefrontAPI.AppliedGiftCard, 'lastCharacters'> & {
amountUsed: Pick<StorefrontAPI.MoneyV2, 'currencyCode' | 'amount'>;
}
>;
buyerIdentity: Pick<
StorefrontAPI.CartBuyerIdentity,
'countryCode' | 'email' | 'phone'
Expand Down
14 changes: 14 additions & 0 deletions examples/legacy-customer-account-flow/app/routes/cart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,20 @@ export async function action({request, context}: ActionFunctionArgs) {
result = await cart.updateDiscountCodes(discountCodes);
break;
}
case CartForm.ACTIONS.GiftCardCodesUpdate: {
const formGiftCardCode = inputs.giftCardCode;

// User inputted gift card code
const giftCardCodes = (
formGiftCardCode ? [formGiftCardCode] : []
) as string[];

// Combine gift card codes already applied on cart
giftCardCodes.push(...inputs.giftCardCodes);

result = await cart.updateGiftCardCodes(giftCardCodes);
break;
}
case CartForm.ACTIONS.BuyerIdentityUpdate: {
result = await cart.updateBuyerIdentity({
...inputs.buyerIdentity,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@ export type CartApiQueryFragment = Pick<
StorefrontAPI.Cart,
'updatedAt' | 'id' | 'checkoutUrl' | 'totalQuantity' | 'note'
> & {
appliedGiftCards: Array<
Pick<StorefrontAPI.AppliedGiftCard, 'lastCharacters'> & {
amountUsed: Pick<StorefrontAPI.MoneyV2, 'currencyCode' | 'amount'>;
}
>;
buyerIdentity: Pick<
StorefrontAPI.CartBuyerIdentity,
'countryCode' | 'email' | 'phone'
Expand Down
5 changes: 5 additions & 0 deletions examples/metaobjects/storefrontapi.generated.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@ export type CartApiQueryFragment = Pick<
StorefrontAPI.Cart,
'updatedAt' | 'id' | 'checkoutUrl' | 'totalQuantity' | 'note'
> & {
appliedGiftCards: Array<
Pick<StorefrontAPI.AppliedGiftCard, 'lastCharacters'> & {
amountUsed: Pick<StorefrontAPI.MoneyV2, 'currencyCode' | 'amount'>;
}
>;
buyerIdentity: Pick<
StorefrontAPI.CartBuyerIdentity,
'countryCode' | 'email' | 'phone'
Expand Down
14 changes: 14 additions & 0 deletions examples/multipass/app/routes/cart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,20 @@ export async function action({request, context}: ActionFunctionArgs) {
result = await cart.updateDiscountCodes(discountCodes);
break;
}
case CartForm.ACTIONS.GiftCardCodesUpdate: {
const formGiftCardCode = inputs.giftCardCode;

// User inputted gift card code
const giftCardCodes = (
formGiftCardCode ? [formGiftCardCode] : []
) as string[];

// Combine gift card codes already applied on cart
giftCardCodes.push(...inputs.giftCardCodes);

result = await cart.updateGiftCardCodes(giftCardCodes);
break;
}
case CartForm.ACTIONS.BuyerIdentityUpdate: {
result = await cart.updateBuyerIdentity({
...inputs.buyerIdentity,
Expand Down
5 changes: 5 additions & 0 deletions examples/multipass/storefrontapi.generated.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@ export type CartApiQueryFragment = Pick<
StorefrontAPI.Cart,
'updatedAt' | 'id' | 'checkoutUrl' | 'totalQuantity' | 'note'
> & {
appliedGiftCards: Array<
Pick<StorefrontAPI.AppliedGiftCard, 'lastCharacters'> & {
amountUsed: Pick<StorefrontAPI.MoneyV2, 'currencyCode' | 'amount'>;
}
>;
buyerIdentity: Pick<
StorefrontAPI.CartBuyerIdentity,
'countryCode' | 'email' | 'phone'
Expand Down
6 changes: 6 additions & 0 deletions examples/subscriptions/app/lib/fragments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,12 @@ export const CART_QUERY_FRAGMENT = `#graphql
fragment CartApiQuery on Cart {
updatedAt
id
appliedGiftCards {
lastCharacters
amountUsed {
...Money
}
}
checkoutUrl
totalQuantity
buyerIdentity {
Expand Down
5 changes: 5 additions & 0 deletions examples/subscriptions/storefrontapi.generated.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ export type CartApiQueryFragment = Pick<
StorefrontAPI.Cart,
'updatedAt' | 'id' | 'checkoutUrl' | 'totalQuantity' | 'note'
> & {
appliedGiftCards: Array<
Pick<StorefrontAPI.AppliedGiftCard, 'lastCharacters'> & {
amountUsed: Pick<StorefrontAPI.MoneyV2, 'currencyCode' | 'amount'>;
}
>;
buyerIdentity: Pick<
StorefrontAPI.CartBuyerIdentity,
'countryCode' | 'email' | 'phone'
Expand Down
16 changes: 8 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit d929b56

Please sign in to comment.