Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Best way to access the customer group id/name across checkout? #574

Open
ff4500 opened this issue May 6, 2021 · 2 comments
Open

Best way to access the customer group id/name across checkout? #574

ff4500 opened this issue May 6, 2021 · 2 comments

Comments

@ff4500
Copy link

ff4500 commented May 6, 2021

In the customers.mock.ts file, there's a line item for the id/name of the Customer's group membership:

customerGroup: {
id: 1,
name: 'Customer group',
},

Since it's not already implemented in the project, what's the best way to go about getting this information into the checkout flow? I realize that it would be fairly simple to tack it onto the existing customer data, say in CustomerInfo.tsx, but I'd like to have that data available for the whole Checkout process, in order to conditionally show some messages to certain customer groups, and not others.

It looks like it was implemented in the checkout-sdk-js awhile back. As I'm stumbling my way through Typescript on this trying to make it work, I've been relatively successful, but it seemed like this was the place to ask to get it implemented the right way.

I have already thrown some data into a file named CustomerGroup.tsx (based on CustomerInfo.tsx), and am able to pull the customer group info now, but exporting a component is clunky. I'd really like to be able to use the state info in other files in the repo: (truncated, but you get the idea)

...

interface WithCheckoutCustomerGroupProps {
  group: string;
}

const CustomerGroup: FunctionComponent<CustomerGroupProps & WithCheckoutCustomerGroupProps> = ({
  group,
  isSignedIn,
}) => {

  return (
    <>
      { isSignedIn && <>
        { group }
      </> }
    </>
  );
};

function mapToWithCheckoutCustomerGroupProps(
  { checkoutService, checkoutState }: CheckoutContextProps
): WithCheckoutCustomerGroupProps | null {
  const {
    data: { getCheckout, getCustomer },
    statuses: { isSigningOut },
  } = checkoutState;

 ...

  const { customerGroup } = customer;

  const group = (() => {
    if (customerGroup) {
      const { name } = customerGroup;
      if (name) {
        return name;
      } else {
        return '';
      }
    } else {
      return 'No Group';
    }
  })();

  return {
    group,
    methodId,
    isSignedIn: canSignOut(customer, checkout, methodId),
    isSigningOut: isSigningOut(),
    signOut: checkoutService.signOutCustomer,
  };
}

Thoughts on the best way to get this group info propagated across the project, for use in other places? It seems like the ability to get the group data exported on WithCheckout(CustomerGroup) is where the magic needs to happen.

Thanks.

@Laban1
Copy link

Laban1 commented Jan 1, 2022

I have the same question...

@bc-0dp
Copy link
Collaborator

bc-0dp commented Feb 13, 2024

@bigcommerce/team-checkout could you have a look at this one 🙇

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants