#Product builder tutorial

2 messages · Page 1 of 1 (latest)

worthy urchin
#

tutorial: https://docs.medusajs.com/resources/how-to-tutorials/tutorials/product-builder#content

Thanks for the helpful tutorial on Product builder! I’m a bit confused about one step: where does cartWithMainProduct come from?

In the workflows/add-product-builder-to-cart.ts file, it seems to skip directly from step 2 to step 5 for adding complementary and add-on products.

Is cartWithMainProduct simply a refetch of the cart after adding the main product(s)?

      entity: "cart",
      filters: { id: input.cart_id },
      fields: ["id", "items.*"],
    }).config({ name: "refetch-cart-after-main-add" })

    // convenience: resolve the single cart object
    const cartWithMainProduct = transform({ cartRows: cartRows as any }, ({ cartRows }) => cartRows?.[0] as any) ```

Explore Medusa's recipes, API references, configurations, storefront guides, and more.

simple turret
#

Nice catch! The following step is missing after the addToCartWorkflow:

const { data: cartWithMainProduct } = useQueryGraphStep({
  entity: "cart",
  fields: ["*", "items.*"],
  filters: {
    id: input.cart_id,
  },
  options: {
    throwIfKeyNotFound: true,
  },
})

Will open a PR to fix the guide