vendure-ecommerce/storefront-remix-starter

Able to proceed to checkout even after removing all items at checkout page

KeetTechSol opened this issue · 5 comments

Steps to reproduce:

  1. Navigate to https://remix-storefront.vendure.io
  2. Add an items to cart
  3. Navigate to checkout page
  4. Remove all items from the cart
  5. Enter all required details, select shipping method
  6. Click proceed to payment
  7. Proceed to Payment

Expected result:
Proceed to payment button disabled

Actual Result:
Proceeding to payment and getting an 400 Bad request after payment

Hi, thanks for the report!
Would you be interested in attempting a fix to this?

I will give a try

I don't have the time to make a PR but a solution could look like the following:

import { getActiveOrder } from '~/providers/orders/order';

export async function loader({ request, context }: DataFunctionArgs) {
    const session = await sessionStorage.getSession(
        request?.headers.get('Cookie'),
    );

    const activeOrder = await getActiveOrder({ request, context });
    if (
        !session ||
        !activeOrder ||
        !activeOrder.active ||
        activeOrder.lines.length === 0
    ) {
        return redirect('/');
    }
    ...
}

This would need to be included in the routes/checkout/index.tsx and routes/checkout/payment.tsx pages

Thanks @kyunal. I have raised a PR.

closed in #28

Thanks both for your help!