1

I am building a multi-seller commerce site, where a user can register and sell their product. I need to display a menu link if the user is anonymous to "become a seller", where they are directed to log in and a create store form.

If the user is logged in, I want to display a menu link that displays "My Store" if they previously created a store. To determine if they have a store, how can I load a store via their user ID?

I have been unable to find an example where someone can load a user's store.

1

The user ID is saved on the store when it's created. Therefore you can load it with code similar to the following one.

$store = \Drupal::entityTypeManager()->getStorage('commerce_store')->loadByProperties(['uid' => \Drupal::currentUser()->id()]);

That will load the store based on the currently logged-in user.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.