[英]How to get Drupal 8 commerce store setting
我正在使用基于Drupal 8的Drupal Commerce2.x。我想在自定义模块中以编程方式访问商店详细信息,例如商店名称,通过电子邮件发送。
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);
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);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.