/**
* type [String] - [DEFAULT = 'online']
* Foreign key for the store type to yse.
*
* uid [Integer]
* The user id that created the store.
*
* name [String]
* The store's name.
*
* mail [String]
* The store's email address.
*
* address [\Drupal\address\AddressInterface]
* The store's address.
*
* default_currency [String]
* The currency the store uses.
*
* billing_countries [Array(String)]
* Array of country codes selected for the store.
*/
// The store's address.
$address = [
'country_code' => 'US',
'address_line1' => '123 Street Drive',
'locality' => 'Beverly Hills',
'administrative_area' => 'CA',
'postal_code' => '90210',
];
// The currency code.
$currency = 'USD';
// If needed, this will import the currency.
$currency_importer = \Drupal::service('commerce_price.currency_importer');
$currency_importer->import($currency);
$store = \Drupal\commerce_store\Entity\Store::create([
'type' => 'custom_store_type',
'uid' => 1,
'name' => 'My Store',
'mail' => 'admin@example.com',
'address' => $address,
'default_currency' => $currency,
'billing_countries' => ['US'],
]);
$store->save();
// If needed, this sets the store as the default store.
$store_storage = \Drupal::service('entity_type.manager')->getStorage('commerce_store');
$store_storage->markAsDefault($store);
// Loading is based off of the primary key [Integer]
// 1 would be the first one saved, 2 the next, etc.
$store = \Drupal\commerce_store\Entity\Store::load(1);
Found errors? Think you can improve this documentation?
edit this page