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.
Asked
Active
Viewed 3,216 times
1
-
You can subscribe to that event. Please see [this link.](https://stackoverflow.com/questions/50830689/how-to-subscribe-to-drupalcommerce-2x-events-for-every-new-order-product-etc-is/50832275#50832275) – Saurabh Chopra Jun 18 '18 at 13:06
2 Answers
3
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);

silverskater
- 821
- 1
- 6
- 7
1
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);

Swapnil Bijwe
- 347
- 2
- 7