1
我使用的是基於Drupal 8的Drupal商務2.x。我想通過程序在我的自定義模塊中訪問商店的詳細信息,如商店名稱,電子郵件。如何獲得Drupal 8商店的商店設置
我使用的是基於Drupal 8的Drupal商務2.x。我想通過程序在我的自定義模塊中訪問商店的詳細信息,如商店名稱,電子郵件。如何獲得Drupal 8商店的商店設置
首先你需要加載存儲對象:
$entity_manager = \Drupal::entityManager();
$store = $entity_manager->getStorage('commerce_store')->loadDefault();
$mail = $store->getEmail();
$name = $store->getName();
如果你有一個以上的店鋪:
$store_id = 1;
$store = \Drupal\commerce_store\Entity\Store::load($store_id);
下面的代碼將要給大家介紹的負載店,購物車和產品對象的想法
$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);