Vue Storefront is now Alokai! Learn More
SetCustomerEmail

SetCustomerEmail

Implements SetCustomerEmail Unified Method.

Source

import { defineApi, getCartId, query } from "@vsf-enterprise/unified-api-magento";
import type { Cart } from "@vue-storefront/magento-types";
import { getNormalizers } from "@vue-storefront/unified-data-model";

export const setCustomerEmail = defineApi.setCustomerEmail(async (context, args) => {
  const { email } = args;
  const cartId = getCartId(context);
  const { normalizeCart } = getNormalizers(context);

  const data = await query(
    context.api.setGuestEmailOnCart({
      cart_id: cartId,
      email,
    }),
  );

  return normalizeCart(data.setGuestEmailOnCart?.cart as Cart);
});