You are here

protected function UbercartTestBase::createOrder in Ubercart 8.4

Creates a new order directly, without going through checkout.

Parameters

array $edit: (optional) An associative array of order fields to change from the defaults, keys are order field names. For example, 'price' => '12.34'.

Return value

\Drupal\uc_order\OrderInterface Product node object.

File

uc_store/src/Tests/UbercartTestBase.php, line 334

Class

UbercartTestBase
Base class for Ubercart Simpletest tests.

Namespace

Drupal\uc_store\Tests

Code

protected function createOrder(array $edit = []) {
  if (empty($edit['primary_email'])) {
    $edit['primary_email'] = $this
      ->randomString() . '@example.org';
  }
  $order = Order::create($edit);
  if (!isset($edit['products'])) {
    $order->products[] = OrderProduct::create([
      'nid' => $this->product->nid->target_id,
      'title' => $this->product->title->value,
      'model' => $this->product->model,
      'qty' => 1,
      'cost' => $this->product->cost->value,
      'price' => $this->product->price->value,
      'weight' => $this->product->weight,
      'data' => [],
    ]);
  }
  $order
    ->save();
  return Order::load($order
    ->id());
}