-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #22 from deco-cx/chore/migrate-shopify
chore: migrate shopify
- Loading branch information
Showing
30 changed files
with
524 additions
and
459 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"imports": { | ||
"$live/": "https://deno.land/x/[email protected].2/", | ||
"$live/": "https://denopkg.com/deco-cx/[email protected].3/", | ||
"$fresh/": "https://denopkg.com/denoland/[email protected]/", | ||
"preact": "https://esm.sh/[email protected]", | ||
"preact/": "https://esm.sh/[email protected]/", | ||
|
@@ -9,7 +9,7 @@ | |
"@preact/signals-core": "https://esm.sh/@preact/[email protected]", | ||
"std/": "https://deno.land/[email protected]/", | ||
"partytown/": "https://deno.land/x/[email protected]/", | ||
"deco-sites/std/": "https://denopkg.com/deco-sites/[email protected].6/", | ||
"deco/": "https://deno.land/x/[email protected].2/" | ||
"deco-sites/std/": "https://denopkg.com/deco-sites/[email protected].7/", | ||
"deco/": "https://denopkg.com/deco-cx/[email protected].3/" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,35 @@ | ||
import { getCookies } from "std/http/mod.ts"; | ||
import { AppContext } from "../../mod.ts"; | ||
import { SHOPIFY_COOKIE_NAME } from "../../utils/constants.ts"; | ||
import type { Cart } from "../../utils/types.ts"; | ||
|
||
export interface updateCartQueryProps { | ||
cartLinesUpdate: Cart; | ||
} | ||
import { getCartCookie, setCartCookie } from "../../utils/cart.ts"; | ||
import { Data as CartData } from "../../utils/queries/cart.ts"; | ||
import { Data, query, Variables } from "../../utils/queries/updateCart.ts"; | ||
|
||
type UpdateLineProps = { | ||
lines: { | ||
lines: Array<{ | ||
id: string; | ||
quantity?: number; | ||
}; | ||
}>; | ||
}; | ||
|
||
const action = async ( | ||
props: UpdateLineProps, | ||
{ lines }: UpdateLineProps, | ||
req: Request, | ||
ctx: AppContext, | ||
): Promise<Cart> => { | ||
const { client } = ctx; | ||
): Promise<CartData["cart"]> => { | ||
const { storefront } = ctx; | ||
const cartId = getCartCookie(req.headers); | ||
|
||
if (!cartId) { | ||
throw new Error("Missing cart id"); | ||
} | ||
|
||
const { payload: { cart } } = await storefront.query<Data, Variables>({ | ||
variables: { cartId, lines }, | ||
query, | ||
}); | ||
|
||
const reqCookies = getCookies(req.headers); | ||
const cartId = reqCookies[SHOPIFY_COOKIE_NAME]; | ||
const response: updateCartQueryProps | undefined = await client.cart | ||
.updateItems({ | ||
cartId: cartId, | ||
lines: [props.lines], | ||
}); | ||
setCartCookie(ctx.response.headers, cartId); | ||
|
||
return response?.cartLinesUpdate || { cart: { id: cartId } }; | ||
return cart; | ||
}; | ||
|
||
export default action; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.