RegisterCustomer
Implements RegisterCustomer
Unified Method.
Source
import { defineApi, getCartFromContext, query } from "@vsf-enterprise/unified-api-magento";
import { loginCustomer } from "../loginCustomer";
export const registerCustomer = defineApi.registerCustomer(async (context, args) => {
const { email, firstName, lastName, password } = args;
const guestCart = await getCartFromContext(context);
await query(
context.api.createCustomer({
firstname: firstName,
lastname: lastName,
email,
password: password,
}),
);
const loggedInCustomer = await loginCustomer(context, { email, password });
if (guestCart.total_quantity && guestCart.id) {
const { customerCart } = await query(context.api.customerCart());
await query(
context.api.mergeCarts({ sourceCartId: guestCart.id, destinationCartId: customerCart.id }),
);
}
return loggedInCustomer;
});