/** * @SWG\Api( * path="/addon/get/{id}", * @SWG\Operation( * nickname="Get addon", * method="GET", * summary="Find addon by ID", * notes="Returns addon", * type="Addon", * authorizations={}, * @SWG\Parameter( * name="id", * description="ID of addon", * required=true, * type="integer", * format="int64", * paramType="path", * allowMultiple=false * ), * @SWG\ResponseMessage(code=404, message="Format not found"), * @SWG\ResponseMessage(code=500, message="Internal server error") * ) * ) */ public function get($id) { $statusCode = 200; $response = []; try { $validator = Validator::make(['id' => $id], ['id' => 'required|numeric']); if ($validator->fails()) { $response = ['error' => $validator->errors()]; $statusCode = 500; } else { $addonModel = Models\Addon::where('id', $id)->first(); if (!isset($addonModel)) { throw new ModelNotFoundException(); } $addonView = new ModelViews\Addon($addonModel); $addonsTypeView = new ModelViews\AddonsType($addonModel->type()->first()); $addon = $addonView->get(); $addon['type'] = $addonsTypeView->get(); $response = $addon; } } catch (ModelNotFoundException $e) { $response = ['error' => 'Addon doesn\'t exists']; $statusCode = 404; } finally { return \Response::json($response, $statusCode); } }
/** * @return string */ public function render() { $model = $this->form->instance; $formats = []; foreach (Models\Format::get() as $format) { $formats[$format->id] = $format->width . 'x' . $format->height; } $photos = []; $itemsAddons = []; $itemsField = []; foreach ($model->items()->get() as $key => $item) { $itemsField[$key] = [HtmlBuilder::text('items[' . $key . '][qty]', 'Qty', $item->qty, ['data-parsley-required' => true, 'data-parsley-type' => 'number', 'data-parsley-min' => '1']), HtmlBuilder::text('items[' . $key . '][price_per_item]', 'Price per item', $item->price_per_item, ['data-parsley-required' => true, 'data-parsley-type' => 'number']), HtmlBuilder::select('items[' . $key . '][format_id]', 'Format', $formats, $item->format_id, ['data-parsley-required' => true]), $this->formBuilder->hidden('items[' . $key . '][photo_id]', $item->photo_id, ['data-parsley-required' => true])]; $photos[$key] = $item->photo()->first(); foreach ($item->ordersItemsAddons()->get() as $ordersItemsAddon) { $itemsAddons[$key][$ordersItemsAddon->addon_id] = $ordersItemsAddon->qty; } } return view('admin/form/order/items')->with('label', $this->label)->with('itemsField', $itemsField)->with('photos', $photos)->with('addons', Models\Addon::get())->with('itemsAddons', $itemsAddons); }