Пример #1
0
 public function as_array()
 {
     $model = $this->_orm->as_array();
     $model['new_product'] = Product::findById($this->new_product_id)->name;
     $model['old_product'] = Product::findById($this->old_product_id)->name;
     $model['order'] = OrderItem::findById($this->item_id)->order->id;
     $model['user'] = OrderItem::findById($this->item_id)->order->user->profile->fullname;
     return $model;
 }
Пример #2
0
 public static function post()
 {
     return function ($request, $response) {
         $user_id = $request->session('id');
         if ($user_id) {
             $id = $request->id;
             $item = OrderItem::findById($id);
             if ($item) {
                 $data = $request->data();
                 $item->product = $data->new_product->id ? $data->new_product->id : $item->product;
                 $item->price = $data->new_product->price ? $data->new_product->price : $item->price;
                 $item->save();
                 $response->json($item->as_array());
             } else {
                 $response->code(404);
             }
         } else {
             $response->code(403);
         }
     };
 }