Skip to content
Snippets Groups Projects
Commit 39830349 authored by Andrei Vesterli's avatar Andrei Vesterli Committed by Nick Murza
Browse files

Issue #3278001 by andrei.vesterli, mrkolea: Fix the NULL store when running tests

parent 48d97f80
No related branches found
No related tags found
1 merge request!12Issue #3278001: Fix the NULL store when running tests
...@@ -5,6 +5,7 @@ namespace Drupal\devel_generate_commerce\Plugin\DevelGenerate; ...@@ -5,6 +5,7 @@ namespace Drupal\devel_generate_commerce\Plugin\DevelGenerate;
use Drupal\commerce_order\Adjustment; use Drupal\commerce_order\Adjustment;
use Drupal\commerce_price\Price; use Drupal\commerce_price\Price;
use Drupal\commerce_store\Entity\StoreInterface; use Drupal\commerce_store\Entity\StoreInterface;
use Drupal\commerce_store\StoreCreationTrait;
use Drupal\Component\Datetime\TimeInterface; use Drupal\Component\Datetime\TimeInterface;
use Drupal\Core\Datetime\DateFormatterInterface; use Drupal\Core\Datetime\DateFormatterInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface; use Drupal\Core\Entity\EntityTypeManagerInterface;
...@@ -37,6 +38,8 @@ use Symfony\Component\DependencyInjection\ContainerInterface; ...@@ -37,6 +38,8 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
*/ */
class CommerceDevelGenerate extends DevelGenerateBase implements ContainerFactoryPluginInterface { class CommerceDevelGenerate extends DevelGenerateBase implements ContainerFactoryPluginInterface {
use StoreCreationTrait;
/** /**
* The user storage. * The user storage.
* *
...@@ -105,25 +108,9 @@ class CommerceDevelGenerate extends DevelGenerateBase implements ContainerFactor ...@@ -105,25 +108,9 @@ class CommerceDevelGenerate extends DevelGenerateBase implements ContainerFactor
->getStorage('commerce_store') ->getStorage('commerce_store')
->loadDefault(); ->loadDefault();
// If there is no store, we need to create one and set it as default. // If there is no default store, we need to create one.
if (!$this->store instanceof StoreInterface) { if (!$this->store instanceof StoreInterface) {
// Set a random store name. $this->store = $this->createStore('Default store', 'default_store@example.com');
$name = $this->getRandom()->word(mt_rand(6, 12));
// Set a random store email address.
$email = $name . '@example.com';
$this->store = $this
->entityTypeManager
->getStorage('commerce_store')
->create([
'type' => 'online',
'uid' => 1,
'name' => $name,
'mail' => $email,
'default_currency' => 'USD',
'is_default' => TRUE,
]);
$this->store->save();
} }
} }
...@@ -239,7 +226,7 @@ class CommerceDevelGenerate extends DevelGenerateBase implements ContainerFactor ...@@ -239,7 +226,7 @@ class CommerceDevelGenerate extends DevelGenerateBase implements ContainerFactor
'#type' => 'select', '#type' => 'select',
'#name' => 'order_workflow', '#name' => 'order_workflow',
'#options' => $order_workflows, '#options' => $order_workflows,
// '#title' => $this->t('Order workflow'), '#title' => '',
'#description' => $this->t('Select the order workflow.'), '#description' => $this->t('Select the order workflow.'),
'#weight' => -1, '#weight' => -1,
]; ];
...@@ -415,7 +402,6 @@ class CommerceDevelGenerate extends DevelGenerateBase implements ContainerFactor ...@@ -415,7 +402,6 @@ class CommerceDevelGenerate extends DevelGenerateBase implements ContainerFactor
// Get a random order workflow status. // Get a random order workflow status.
$order_workflow_status = array_rand($order_workflow_statuses, 1); $order_workflow_status = array_rand($order_workflow_statuses, 1);
$email = $this->store->getEmail(); $email = $this->store->getEmail();
// Order data preparation for saving. // Order data preparation for saving.
$order = $this->entityTypeManager $order = $this->entityTypeManager
->getStorage('commerce_order')->create([ ->getStorage('commerce_order')->create([
...@@ -427,7 +413,6 @@ class CommerceDevelGenerate extends DevelGenerateBase implements ContainerFactor ...@@ -427,7 +413,6 @@ class CommerceDevelGenerate extends DevelGenerateBase implements ContainerFactor
'placed' => $this->time->getRequestTime() - mt_rand(0, $time_range), 'placed' => $this->time->getRequestTime() - mt_rand(0, $time_range),
]); ]);
$currency = $this->store->getDefaultCurrencyCode(); $currency = $this->store->getDefaultCurrencyCode();
// Add a dummy order adjustment. // Add a dummy order adjustment.
$order->addAdjustment(new Adjustment([ $order->addAdjustment(new Adjustment([
'type' => 'tax', 'type' => 'tax',
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment