drupaldrupal-commerce

How to get Drupal 8 commerce store setting


I am using Drupal commerce 2.x which is based on Drupal 8. I want to access store detail like store name,email programmatically in my custom module.


Solution

  • First you need to load the store object:

    $entity_manager = \Drupal::entityManager();
    $store = $entity_manager->getStorage('commerce_store')->loadDefault();
    $mail = $store->getEmail();
    $name = $store->getName();
    

    If you have more than one store:

    $store_id = 1;
    $store = \Drupal\commerce_store\Entity\Store::load($store_id);