Skip to content

Medusa all in nextjs #3805

Answered by olivermrbl
samyarkd asked this question in Q&A
Apr 11, 2023 · 3 comments · 6 replies
Discussion options

You must be logged in to vote

To give you an idea of what this modularization would look like, consider the following code snippet:

import { initialize } from "@medusajs/cart"
import { NextApiRequest, NextApiResponse } from "next"

const cartService = await initialize()

export default async (req: NextApiRequest, res: NextApiResponse) => {
  const { cart_id } = req.query
  const { quantity, variant_id } = req.body

  try {
    const cart = await cartService.addLineItem(cart_id, { quantity, variant_id })

    res.json({ cart })
  } catch (e) {
    res.status(400).json({ error: e.message })
  }
}

I can't guarantee, that this is what it will look like, but it will be pretty close.

Replies: 3 comments 6 replies

Comment options

You must be logged in to vote
2 replies
@samyarkd
Comment options

@durdenx
Comment options

Comment options

You must be logged in to vote
4 replies
@olivermrbl
Comment options

Answer selected by samyarkd
@samyarkd
Comment options

@olivermrbl
Comment options

@samyarkd
Comment options

Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
4 participants