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.
How to get Drupal 8 commerce store setting
3.3k views Asked by amol challawar At
2
There are 2 answers
0
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);
First you need to load the store object:
If you have more than one store: