Created
November 14, 2022 17:48
-
-
Save webber12/53cd6c60b73a492106354fb4c16fdc3b to your computer and use it in GitHub Desktop.
Список заказов вместе с продуктами
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
protected function getOrderList() | |
{ | |
$arr = []; | |
$currentUser = $this->data['user']['id'] ?? 0; | |
if(!empty($currentUser)) { | |
$arr = app('evouser')->do('OrderList', [ 'user' => $currentUser ]); | |
} | |
if(!empty($arr['data'])) { | |
//print_r($arr['data']); | |
$ids = array_column($arr['data'], 'id'); | |
//print_r($ids); | |
$res = DB::table('commerce_order_products') | |
->whereIn('order_id', $ids) | |
->orderBy('position', 'ASC') | |
->get()->toArray(); | |
if(!empty($res)) { | |
$products = json_decode(json_encode($res), 1); | |
$product_ids = array_column($products, 'product_id'); | |
//получаем сразу все картинки - tv id=48 | |
$images = SiteTmplvarContentvalue::whereIn('contentid', $product_ids)->where('tmplvarid', 48)->pluck('value', 'contentid')->toArray(); | |
foreach($products as $p) { | |
if(!empty($p['product_id'])) { | |
if (!isset($arr['data'][$p['order_id']]['products'])) { | |
$arr['data'][$p['order_id']]['products'] = []; | |
} | |
$p['options'] = !empty($p['options']) ? json_decode($p['options'], 1) : []; | |
$p['image'] = $images[$p['product_id']] ?? ''; | |
$arr['data'][$p['order_id']]['products'][] = $p; | |
} else { | |
$arr['data'][$p['order_id']]['delivery'] = $p; | |
} | |
} | |
} | |
} | |
return $arr; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment