/** * @param $purchase_id * @return array */ public static function getOrdersCollectionsByPurchaseIdAndByUserId($purchase_id, $user_id) { $orders = \DB::table(\App\Basket::TABLE_PRODUCTS_IN_BASKETS)->select('*')->where('user_id', '=', $user_id)->where('purchase_id', '=', $purchase_id)->get(); $user = \App\User::find($user_id); \App\Helpers\Assistant::assertModel($user); $orders_models = $user->orders()->where('purchase_id', '=', $purchase_id)->get(); if (!$orders_models->count()) { return []; } $orders_collections_arr = []; foreach ($orders_models as $order_model) { $order_collection = new \stdClass(); $order_collection->order_id = $order_model->id; $order_collection->amount = $order_model->amount; $order_collection->purchase_id = $order_model->purchase_id; $order_collection->product_id = $order_model->product_id; $order_collection->product_in_purchase_id = $order_model->product_in_purchase_id; $product_in_purchase_model = \App\Models\ProductInPurchaseModel::find($order_model->product_in_purchase_id); \App\Helpers\Assistant::assertModel($product_in_purchase_model); $current_max_price = $product_in_purchase_model->getMaxPrice(); $order_collection->product_price = $current_max_price; $order_collection->total_price = number_format(\App\Helpers\OrdersHelper::getTotalPrice($current_max_price, $order_model->amount), 2); $order_collection->product_name = $product_in_purchase_model->product->name; $order_collection->product_alias = $product_in_purchase_model->alias(); $orders_collections_arr[] = $order_collection; } return $orders_collections_arr; }
<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> <th>Товар</th> <th>Цена*</th> <th>Количество</th> <th>Сумма</th> <th></th> </tr> </thead> <tbody> @foreach($orders_models_arr_by_purchases_ids_arr[$purchase_id] as $order_model) <?php $product_in_purchase_model = \App\Models\ProductInPurchaseModel::find($order_model->product_in_purchase_id); \App\Helpers\Assistant::assertModel($product_in_purchase_model); $current_max_price = $product_in_purchase_model->getMaxPrice(); ?> <tr id="orderValue-{{ $order_model->id }}"> <td><a href="{{ $product_in_purchase_model->alias() }}">{{ $product_in_purchase_model->product->name }}</a></td> <td class="product-price">{{ $current_max_price }}</td> <td><input type="number" style="width: 50px" data-order-id="{{ $order_model->id }}" value="{{ $order_model->amount }}"></td> <td class="total-price">{{ number_format(\App\Helpers\OrdersHelper::getTotalPrice($current_max_price, $order_model->amount), 2) }}</td> <td style="text-align: right"><button class="btn btn-xs btn-danger" onclick="destroyOrder({{ $order_model->id }});">удалить</button></td> </tr> @endforeach </tbody> <tfoot> <tr> <td></td>