Skip to content

Instantly share code, notes, and snippets.

@wecc
Created June 30, 2015 11:25
Show Gist options
  • Select an option

  • Save wecc/ab2093892217bda17322 to your computer and use it in GitHub Desktop.

Select an option

Save wecc/ab2093892217bda17322 to your computer and use it in GitHub Desktop.
<?php
Database::beginTransaction();
if ($order = Order::create($data)) {
$items = $cart->getItems();
$orderLines = array();
foreach ($items as $item) {
$data = array(
'number' => $item->article->number,
'number_supplier' => $item->article->number_supplier,
'text' => $item->article->name,
'quantity_ordered' => ( $item->quantity * $item->article->quantity_multiplier ),
'price_in' => $item->article->price_in,
'price_out' => $item->article->price(false, false, false),
'order_id' => $order->id,
'supplier_id' => $item->article->supplier_id,
);
if (!$orderLine = OrderLine::create($data)) {
Database::rollbackTransaction();
throw new \Exception('Could not create order line');
}
$orderLines[$orderLine->id] = $orderLine;
}
} else {
Database::rollbackTransaction();
throw new \Exception('Could not create order');
}
if (Database::commitTransaction()) {
$cart->clear();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment