Created
June 30, 2015 11:25
-
-
Save wecc/ab2093892217bda17322 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?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