How to display all ordered products in order history page without condition?
-
Hi,
Can anyone suggest me how to display all ordered products in order history page without where condition for order id. Actually I have tried but it showing only first ordered details, so how can I do this without condition. Please find below is the my code and image when I click on order history page It shows like below image (without order_id but it shows first order details only, see url in image)
OrderController.php
public function index() { $order = $this->order->findOneWhere([ 'customer_id' => auth()->guard('customer')->user()->id ]); return view('shop::customers.account.orders.view', ['order' => $order]); } /** * Show the view for the specified resource. * * @param int $id * @return \Illuminate\Http\Response */ // public function view($id) // { // $order = $this->order->findOneWhere([ // 'customer_id' => auth()->guard('customer')->user()->id, // 'id' => $id // ]); // if (! $order) // abort(404); // return view($this->_config['view'], compact('order')); // }
routes.php
Route::get('orders', 'Webkul\Shop\Http\Controllers\OrderController@index')->defaults('_config', [ 'view' => 'shop::customers.account.orders.index' ])->name('customer.orders.index'); // Customer orders view summary and status Route::get('orders/view', 'Webkul\Shop\Http\Controllers\OrderController@index')->defaults('_config', [ 'view' => 'shop::customers.account.orders.view' ])->name('customer.orders.view');
view.blade.php
@extends('shop::layouts.master') @section('page_title') {{ __('shop::app.customer.account.order.view.page-tile', ['order_id' => $order->id]) }} @endsection @section('content-wrapper') <div class="account-content"> @include('shop::customers.account.partials.sidemenu') <div class="account-layout"> <div class="account-head"> <span class="back-icon"><a href="{{ route('customer.account.index') }}"><i class="icon icon-menu-back"></i></a></span> <span class="account-heading"> {{ __('shop::app.customer.account.order.view.page-tile', ['order_id' => $order->id]) }} </span> <span></span> </div> {!! view_render_event('bagisto.shop.customers.account.orders.view.before', ['order' => $order]) !!} <div class="sale-container"> <tabs> <tab name="{{ __('shop::app.customer.account.order.view.info') }}" :selected="true"> <div class="sale-section"> <div class="section-content"> <div class="row"> <span class="title"> {{ __('shop::app.customer.account.order.view.placed-on') }} </span> <span class="value"> {{ core()->formatDate($order->created_at, 'd M Y') }} </span> </div> </div> </div> <div class="sale-section"> <div class="secton-title"> <span>{{ __('shop::app.customer.account.order.view.products-ordered') }}</span> </div> <div class="section-content"> <div class="table"> <table> <thead> <tr> <th>{{ __('shop::app.customer.account.order.view.SKU') }}</th> <th>Image</th> <th>{{ __('shop::app.customer.account.order.view.product-name') }}</th> <th>{{ __('shop::app.customer.account.order.view.price') }}</th> <th>{{ __('shop::app.customer.account.order.view.item-status') }}</th> <th>{{ __('shop::app.customer.account.order.view.subtotal') }}</th> <th>{{ __('shop::app.customer.account.order.view.tax-percent') }}</th> <th>{{ __('shop::app.customer.account.order.view.tax-amount') }}</th> <th>{{ __('shop::app.customer.account.order.view.grand-total') }}</th> </tr> </thead> <tbody> @foreach ($order->items as $item) <tr> @inject ('productImageHelper', 'Webkul\Product\Helpers\ProductImage') <?php $product = $item->product; $productBaseImage = $productImageHelper->getProductBaseImage($product); ?> <td data-value="{{ __('shop::app.customer.account.order.view.SKU') }}"> {{ $item->type == 'configurable' ? $item->child->sku : $item->sku }} </td> <td data-value="Image"> <img src="{{ $productBaseImage['medium_image_url'] }}" width="50px" height="50px"/></td> <td data-value="{{ __('shop::app.customer.account.order.view.product-name') }}">{{ $item->name }}</td> <td data-value="{{ __('shop::app.customer.account.order.view.price') }}">{{ core()->formatPrice($item->price, $order->order_currency_code) }}</td> <td data-value="{{ __('shop::app.customer.account.order.view.item-status') }}"> <span class="qty-row"> {{ __('shop::app.customer.account.order.view.item-ordered', ['qty_ordered' => $item->qty_ordered]) }} </span> <span class="qty-row"> {{ $item->qty_invoiced ? __('shop::app.customer.account.order.view.item-invoice', ['qty_invoiced' => $item->qty_invoiced]) : '' }} </span> <span class="qty-row"> {{ $item->qty_shipped ? __('shop::app.customer.account.order.view.item-shipped', ['qty_shipped' => $item->qty_shipped]) : '' }} </span> <span class="qty-row"> {{ $item->qty_canceled ? __('shop::app.customer.account.order.view.item-canceled', ['qty_canceled' => $item->qty_canceled]) : '' }} </span> </td> <td data-value="{{ __('shop::app.customer.account.order.view.subtotal') }}">{{ core()->formatPrice($item->total, $order->order_currency_code) }}</td> <td data-value="{{ __('shop::app.customer.account.order.view.tax-percent') }}">{{ number_format($item->tax_percent, 2) }}%</td> <td data-value="{{ __('shop::app.customer.account.order.view.tax-amount') }}">{{ core()->formatPrice($item->tax_amount, $order->order_currency_code) }}</td> <td data-value="{{ __('shop::app.customer.account.order.view.grand-total') }}">{{ core()->formatPrice($item->total + $item->tax_amount, $order->order_currency_code) }}</td> </tr> @endforeach </tbody> </table> </div> <div class="totals"> <table class="sale-summary"> <tbody> <tr> <td>{{ __('shop::app.customer.account.order.view.subtotal') }}</td> <td>-</td> <td>{{ core()->formatPrice($order->sub_total, $order->order_currency_code) }}</td> </tr> <tr> <td>{{ __('shop::app.customer.account.order.view.shipping-handling') }}</td> <td>-</td> <td>{{ core()->formatPrice($order->shipping_amount, $order->order_currency_code) }}</td> </tr> @if ($order->base_discount_amount > 0) <tr> <td>{{ __('shop::app.customer.account.order.view.discount') }}</td> <td>-</td> <td>{{ core()->formatPrice($order->discount_amount, $order->order_currency_code) }}</td> </tr> @endif <tr class="border"> <td>{{ __('shop::app.customer.account.order.view.tax') }}</td> <td>-</td> <td>{{ core()->formatPrice($order->tax_amount, $order->order_currency_code) }}</td> </tr> <tr class="bold"> <td>{{ __('shop::app.customer.account.order.view.grand-total') }}</td> <td>-</td> <td>{{ core()->formatPrice($order->grand_total, $order->order_currency_code) }}</td> </tr> <tr class="bold"> <td>{{ __('shop::app.customer.account.order.view.total-paid') }}</td> <td>-</td> <td>{{ core()->formatPrice($order->grand_total_invoiced, $order->order_currency_code) }}</td> </tr> <tr class="bold"> <td>{{ __('shop::app.customer.account.order.view.total-refunded') }}</td> <td>-</td> <td>{{ core()->formatPrice($order->grand_total_refunded, $order->order_currency_code) }}</td> </tr> <tr class="bold"> <td>{{ __('shop::app.customer.account.order.view.total-due') }}</td> <td>-</td> <td>{{ core()->formatPrice($order->total_due, $order->order_currency_code) }}</td> </tr> <tbody> </table> </div> </div> </div> </tab> @if ($order->invoices->count()) <tab name="{{ __('shop::app.customer.account.order.view.invoices') }}"> @foreach ($order->invoices as $invoice) <div class="sale-section"> <div class="secton-title"> <span>{{ __('shop::app.customer.account.order.view.individual-invoice', ['invoice_id' => $invoice->id]) }}</span> <a href="{{ route('customer.orders.print', $invoice->id) }}" class="pull-right"> {{ __('shop::app.customer.account.order.view.print') }} </a> </div> <div class="section-content"> <div class="table"> <table> <thead> <tr> <th>{{ __('shop::app.customer.account.order.view.SKU') }}</th> <th>{{ __('shop::app.customer.account.order.view.product-name') }}</th> <th>{{ __('shop::app.customer.account.order.view.price') }}</th> <th>{{ __('shop::app.customer.account.order.view.qty') }}</th> <th>{{ __('shop::app.customer.account.order.view.subtotal') }}</th> <th>{{ __('shop::app.customer.account.order.view.tax-amount') }}</th> <th>{{ __('shop::app.customer.account.order.view.grand-total') }}</th> </tr> </thead> <tbody> @foreach ($invoice->items as $item) <tr> <td data-value="{{ __('shop::app.customer.account.order.view.SKU') }}">{{ $item->child ? $item->child->sku : $item->sku }}</td> <td data-value="{{ __('shop::app.customer.account.order.view.product-name') }}">{{ $item->name }}</td> <td data-value="{{ __('shop::app.customer.account.order.view.price') }}">{{ core()->formatPrice($item->price, $order->order_currency_code) }}</td> <td data-value="{{ __('shop::app.customer.account.order.view.qty') }}">{{ $item->qty }}</td> <td data-value="{{ __('shop::app.customer.account.order.view.subtotal') }}">{{ core()->formatPrice($item->total, $order->order_currency_code) }}</td> <td data-value="{{ __('shop::app.customer.account.order.view.tax-amount') }}">{{ core()->formatPrice($item->tax_amount, $order->order_currency_code) }}</td> <td data-value="{{ __('shop::app.customer.account.order.view.grand-total') }}">{{ core()->formatPrice($item->total + $item->tax_amount, $order->order_currency_code) }}</td> </tr> @endforeach </tbody> </table> </div> <div class="totals"> <table class="sale-summary"> <tr> <td>{{ __('shop::app.customer.account.order.view.subtotal') }}</td> <td>-</td> <td>{{ core()->formatPrice($invoice->sub_total, $order->order_currency_code) }}</td> </tr> <tr> <td>{{ __('shop::app.customer.account.order.view.shipping-handling') }}</td> <td>-</td> <td>{{ core()->formatPrice($invoice->shipping_amount, $order->order_currency_code) }}</td> </tr> <tr> <td>{{ __('shop::app.customer.account.order.view.tax') }}</td> <td>-</td> <td>{{ core()->formatPrice($invoice->tax_amount, $order->order_currency_code) }}</td> </tr> <tr class="bold"> <td>{{ __('shop::app.customer.account.order.view.grand-total') }}</td> <td>-</td> <td>{{ core()->formatPrice($invoice->grand_total, $order->order_currency_code) }}</td> </tr> </table> </div> </div> </div> @endforeach </tab> @endif @if ($order->shipments->count()) <tab name="{{ __('shop::app.customer.account.order.view.shipments') }}"> @foreach ($order->shipments as $shipment) <div class="sale-section"> <div class="secton-title"> <span>{{ __('shop::app.customer.account.order.view.individual-shipment', ['shipment_id' => $shipment->id]) }}</span> </div> <div class="section-content"> <div class="table"> <table> <thead> <tr> <th>{{ __('shop::app.customer.account.order.view.SKU') }}</th> <th>{{ __('shop::app.customer.account.order.view.product-name') }}</th> <th>{{ __('shop::app.customer.account.order.view.qty') }}</th> </tr> </thead> <tbody> @foreach ($shipment->items as $item) <tr> <td data-value="{{ __('shop::app.customer.account.order.view.SKU') }}">{{ $item->sku }}</td> <td data-value="{{ __('shop::app.customer.account.order.view.product-name') }}">{{ $item->name }}</td> <td data-value="{{ __('shop::app.customer.account.order.view.qty') }}">{{ $item->qty }}</td> </tr> @endforeach </tbody> </table> </div> </div> </div> @endforeach </tab> @endif </tabs> <div class="sale-section"> <div class="section-content" style="border-bottom: 0"> <div class="order-box-container"> <div class="box"> <div class="box-title"> {{ __('shop::app.customer.account.order.view.shipping-address') }} </div> <div class="box-content"> @include ('admin::sales.address', ['address' => $order->billing_address]) </div> </div> <div class="box"> <div class="box-title"> {{ __('shop::app.customer.account.order.view.billing-address') }} </div> <div class="box-content"> @include ('admin::sales.address', ['address' => $order->shipping_address]) </div> </div> <div class="box"> <div class="box-title"> {{ __('shop::app.customer.account.order.view.shipping-method') }} </div> <div class="box-content"> {{ $order->shipping_title }} </div> </div> <div class="box"> <div class="box-title"> {{ __('shop::app.customer.account.order.view.payment-method') }} </div> <div class="box-content"> {{ core()->getConfigData('sales.paymentmethods.' . $order->payment->method . '.title') }} </div> </div> </div> </div> </div> </div> {!! view_render_event('bagisto.shop.customers.account.orders.view.after', ['order' => $order]) !!} </div> </div> @endsection
-
Hi,
I want order history only with Products Ordered not order data, see below images, I want only second image (but without condition, i mean view all ordered products data of specific user when we click on order history tab from sidemenu) but not first image. Thank you in advance.
-
Hi @Keerthi
Change your query like below.
$order = $this->order->findWhere([ 'customer_id' => auth()->guard('customer')->user()->id ]);
You are using findOneWhere in query that's why it is returning single data.
Thanks
-
Hi @rahul,
If I use below query (What you send to me)
$order = $this->order->findWhere([ 'customer_id' => auth()->guard('customer')->user()->id ]);
Then I am getting error like below
Property [id] does not exist on this collection instance. (View: C:\xampp\htdocs\vayathi\packages\Webkul\Shop\src\Resources\views\customers\account\orders\view.blade.php)
Please suggest me on this issue, thank you.
-
Hi @Keerthi
When you need to get all orders of customer then use below one.
$orders = $this->order->findWhere([ 'customer_id' => auth()->guard('customer')->user()->id ]);
When you need to get particular order of customer then. ( $id will get get from url)
$order = $this->order->findOneWhere([ 'customer_id' => auth()->guard('customer')->user()->id, 'id' => $id ]);
thanks
-
Hi @rahul,
I don't want place ordered history, I want products ordered history in orders page like below image to reference. In image showing only single ordered history with condition, but I need all ordered products history of specific user. that means show all ordered products without click on eye icon, thank you.
-
Hi @Keerthi
Use this one -
$orders = $this->order->findWhere([ 'customer_id' => auth()->guard('customer')->user()->id ]); foreach ($orders as $order) { foreach ($order->items as $item) { $orderItem[] = $item; } }
In orders, you will get all orders then using order items , you can get all ordered item.
Thanks
-
Hi,
order_items table
orders table