StoreCreationTrait.php in Commerce Core 8.2
File
modules/store/src/StoreCreationTrait.php
View source
<?php
namespace Drupal\commerce_store;
use Drupal\commerce_store\Entity\Store;
trait StoreCreationTrait {
protected function createStore($name = NULL, $mail = NULL, $type = 'online', $default = TRUE, $country = 'US', $currency = 'USD') {
if (!$name) {
$name = $this
->randomMachineName(8);
}
if (!$mail) {
$mail = \Drupal::currentUser()
->getEmail();
}
$currency_importer = \Drupal::service('commerce_price.currency_importer');
$currency_importer
->import($currency);
$store = Store::create([
'type' => $type,
'uid' => 1,
'name' => $name,
'mail' => $mail,
'default_currency' => $currency,
'timezone' => 'Australia/Sydney',
'address' => [
'country_code' => $country,
'address_line1' => $this
->randomString(),
'locality' => $this
->randomString(5),
'administrative_area' => 'WI',
'postal_code' => '53597',
],
'billing_countries' => [
$country,
],
'is_default' => $default,
]);
$store
->save();
$store = Store::load($store
->id());
return $store;
}
}