You are here

public function Products::addBlank in Ubercart 8.4

Form submit callback: add a blank line product to an order.

File

uc_order/src/Plugin/Ubercart/OrderPane/Products.php, line 502

Class

Products
Manage the products an order contains.

Namespace

Drupal\uc_order\Plugin\Ubercart\OrderPane

Code

public function addBlank($form, FormStateInterface $form_state) {
  $form_state
    ->set('refresh_products', TRUE);
  $form_state
    ->setRebuild();
  $order = $form['#order'];
  $product = OrderProduct::create([
    'qty' => 1,
    'order_id' => $order
      ->id(),
  ]);
  $product
    ->save();
  $order->products[] = $product;
  $order
    ->logChanges([
    'add' => $this
      ->t('Added new product line to order.'),
  ]);
}