public function action_commit() { $user_id = \Session::get(self::SESSION_KEY_USER_ID); $user = Model_Member::find($user_id); $address = \Session::get(self::SESSION_KEY_ADDRESS); /*------make order----------------------------------------------------------*/ $order = new Model_Order(); $order->member_id = $user->id; $order->postalcode = $address['postalcode']; $order->destination = $address['address'] . $address['billname'] . $address['companyname']; $date = time(); $order->order_date = date('Y-m-d H:i:s', $date); $order->print_flag = 0; $order->status = 0; $order->save(); /*-----make orderline------------------------*/ $cart = \Session::get(self::SESSION_KEY_CART); foreach ($cart['orders'] as $orderline) { $item_id = $orderline['item_id']; $item = Model_Item::find($item_id); $num = $orderline['quantity']; $size = $orderline['size']; $neworderline = new Model_Orderline(); $neworderline->order_id = $order->id; $neworderline->item_id = $item_id; $neworderline->num = $num; $neworderline->size = $size; $neworderline->save(); $earning = new Model_Earning(); $earning->member_id = $user->id; $earning->item_id = $item_id; $earning->size = $size; switch ($size) { case 'S': $unit_price = $neworderline->item->unit_price_s; break; case 'M': $unit_price = $neworderline->item->unit_price_m; break; case 'L': $unit_price = $neworderline->item->unit_price_m; break; default: $unit_price = $neworderline->item->unit_price; break; } $earning->unit_price = $unit_price; $earning->num = $num; $earning->date = date('Y-m-d H:i:s', $date); $earning->category = $item->category; $earning->item_name = $item->name; $now = date('Ymd'); $birthday = date('Ymd', strtotime($user->birthday)); $earning->age = (int) floor(($now - $birthday) / 10000); $earning->save(); } \Session::delete(self::SESSION_KEY_CART); return Response::redirect('index.php/message/commit'); }
public function action_commit() { $orders = \Session::get(self::ORDER); if (count($orders['cart']) == 0) { Response::redirect('index.php/controlsystem/order/order'); } $post = $_POST; $order = new Model_Order(); $order->postalcode = $post['postalcode1'] . '-' . $post['postalcode2']; $order->destination = $post['address']; $order->print_flag = false; $order->status = false; $date = date("Y-m-d", time()); $order->order_date = $date; $customer = Model_Member::query()->where('name', $post['customer_name'])->get_one(); if (!empty($customer)) { $order->member_id = $customer->id; } else { $order->member_id = null; } $order->save(); $order_id = $order->id; //make orderlines $orders = \Session::get(self::ORDER); foreach ($orders['cart'] as $orderline) { $item_id = $orderline['item_id']; $item = Model_Item::find($item_id); $num = $orderline['num']; $size = strtoupper($orderline['size']); $neworderline = new Model_Orderline(); $neworderline->order_id = $order->id; $neworderline->item_id = $item_id; $neworderline->num = $num; $neworderline->size = $size; $neworderline->save(); $earning = new Model_Earning(); if (!empty($customer)) { $earning->member_id = $customer->id; } else { $earning->member_id = null; } $earning->item_id = $item_id; $earning->size = $size; switch ($size) { case 'S': $unit_price = $neworderline->item->unit_price_s; break; case 'M': $unit_price = $neworderline->item->unit_price_m; break; case 'L': $unit_price = $neworderline->item->unit_price_m; break; default: $unit_price = $neworderline->item->unit_price; break; } $earning->unit_price = $unit_price; $earning->num = $num; $earning->date = $date; $earning->category = $item->category; $earning->item_name = $item->name; $now = date('Ymd'); if (!empty($customer)) { $birthday = date('Ymd', strtotime($customer->birthday)); $earning->age = (int) floor(($now - $birthday) / 10000); } else { $birthday = null; $earning->age = 0; } $earning->save(); } return View::forge('controlsystem/order/commit'); }