Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Applied gift card #2298

Merged
merged 19 commits into from
Aug 16, 2024
Merged
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
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
Loading