How to get Drupal 8 commerce store setting

3.3k views Asked by At

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.

2

There are 2 answers

0
silverskater On BEST ANSWER

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);
0
Swapnil Bijwe On

Following code will give you idea about Load store, cart and product object

$cart_manager   = \Drupal::service('commerce_cart.cart_manager');
$cartProvider   = \Drupal::service('commerce_cart.cart_provider');

$storeId      = $productObj->get('stores')->getValue()[0]['target_id'];
$variationobj = \Drupal::entityTypeManager()
     ->getStorage('commerce_product_variation')
     ->load($product_variation_id);
  $store = \Drupal::entityTypeManager()
     ->getStorage('commerce_store')
     ->load($storeId);

  $cart = $cartProvider->getCart('default', $store);