public function getPurchase($id) { $purchase_model = \App\Models\PurchaseModel::find($id); if (!$purchase_model) { // TODO: 404 - not found } return view('purchase.index'); }
public function postSave(Request $request) { $post_fields_arr = $request->all(); $validator = \Validator::make($post_fields_arr, ['name' => 'required|max:255', 'description' => 'max:255', 'expiration_time' => 'required']); if ($validator->fails()) { return 'Невалидные данные'; } $post_fields_arr['user_id'] = $this->user->id; if (isset($post_fields_arr['id'])) { $purchase_model = \App\Models\PurchaseModel::find($post_fields_arr['id']); if (!$purchase_model) { return 'Ошибка: нет закупки с таким ID - ' . $post_fields_arr['id']; } $purchase_model->name = $post_fields_arr['name']; $purchase_model->description = $post_fields_arr['description']; $purchase_model->save(); } else { \App\Models\PurchaseModel::create($post_fields_arr); } return redirect('/seller/purchases'); }
/** * Возвращает коллекцию данных для построения "Таблицы цен" * @param $product_id * @param $purchase_id * @return array */ public static function getPricingGridMixForProduct($product_id, $purchase_id) { /** * @var $product \App\BusinessLogic\Models\Product * @var $purchase \App\Models\PurchaseModel */ $product = \App\BusinessLogic\Models\Product::find($product_id); $purchase = \App\Models\PurchaseModel::find($purchase_id); $pricing_grid_columns = $purchase->getPricingGridColumns()->get(); $columns_ids_arr = []; foreach ($pricing_grid_columns as $column) { $columns_ids_arr[] = $column->id; } $product_prices = $product->prices($columns_ids_arr); $product_prices_unsorted = []; foreach ($product_prices as $product_price) { $product_prices_unsorted[$product_price->column_id] = $product_price->price; } $rows = []; foreach ($pricing_grid_columns as $column) { $rows[] = ['title' => $column->column_title, 'expiry_date' => date('d.m.Y H:i'), 'price' => $product_prices_unsorted[$column->id]]; } return $rows; }
/** * Удаление закупки */ public function testRemovePurchase() { $this->assertGreaterThan(0, self::$purchase_id); \App\Models\PurchaseModel::destroy(self::$purchase_id); $purchase_model = \App\Models\PurchaseModel::find(self::$purchase_id); $this->assertNull($purchase_model); }
<div class="container"> <div class="row"> <div class="col-md-12"> <div class="panel panel-default"> <div class="panel-heading">Список заказов</div> {!! \App\Helpers\WidgetHelper::region('center_1') !!} <div class="panel-body"> @if(empty($purchases_ids_arr)) <h1>Заказов нет, сделайте свой первый заказ</h1> @else <div class="panel-group" id="orders-accordion" role="tablist" aria-multiselectable="true"> @foreach($purchases_ids_arr as $purchase_id) <?php $purchase_model = \App\Models\PurchaseModel::find($purchase_id); \App\Helpers\Assistant::assertModel($purchase_model); ?> <div class="panel panel-default" id="purchasePanel-{{ $purchase_model->id }}"> <div class="panel-heading" role="tab" id="headingOne-{{ $purchase_model->id }}"> <h4 class="panel-title"> <a role="button" data-toggle="collapse" data-parent="#orders-accordion" href="#collapseOne-{{ $purchase_model->id }}" aria-expanded="true" aria-controls="collapseOne-{{ $purchase_model->id }}" class="collapsed"> <strong>{{ $purchase_model->name }}</strong>, товаров: {{ count($orders_models_arr_by_purchases_ids_arr[$purchase_id]) }} </a> </h4> </div> <div id="collapseOne-{{ $purchase_model->id }}" class="panel-collapse collapse" role="tabpanel" aria-labelledby="headingOne-{{ $purchase_model->id }}" aria-expanded="true" style="height: 0px;"> <div class="panel-body"> <table class="table"> <thead> <tr>