Added downloadable order item info

This commit is contained in:
jitendra 2019-06-29 17:51:49 +05:30
parent ad6e422fdb
commit 3ef416b22e
13 changed files with 127 additions and 108 deletions

View File

@ -7,10 +7,10 @@ use Illuminate\Http\Response;
use Illuminate\Routing\Controller;
use Illuminate\Support\Facades\DB;
use Carbon\Carbon;
use Webkul\Sales\Repositories\OrderRepository as Order;
use Webkul\Sales\Repositories\OrderItemRepository as OrderItem;
use Webkul\Customer\Repositories\CustomerRepository as Customer;
use Webkul\Product\Repositories\ProductInventoryRepository as ProductInventory;
use Webkul\Sales\Repositories\OrderRepository;
use Webkul\Sales\Repositories\OrderItemRepository;
use Webkul\Customer\Repositories\CustomerRepository;
use Webkul\Product\Repositories\ProductInventoryRepository;
/**
* Dashboard controller
@ -32,28 +32,28 @@ class DashboardController extends Controller
*
* @var array
*/
protected $order;
protected $orderRepository;
/**
* OrderItemRepository object
*
* @var array
*/
protected $orderItem;
protected $orderItemRepository;
/**
* CustomerRepository object
*
* @var array
*/
protected $customer;
protected $customerRepository;
/**
* ProductInventoryRepository object
*
* @var array
*/
protected $productInventory;
protected $productInventoryRepository;
/**
* string object
@ -86,30 +86,30 @@ class DashboardController extends Controller
/**
* Create a new controller instance.
*
* @param \Webkul\Sales\Repositories\OrderRepository $order
* @param \Webkul\Sales\Repositories\OrderItemRepository $orderItem
* @param \Webkul\Customer\Repositories\CustomerRepository $customer
* @param \Webkul\Product\Repositories\ProductInventoryRepository $productInventory
* @param \Webkul\Sales\Repositories\OrderRepository $orderRepository
* @param \Webkul\Sales\Repositories\OrderItemRepository $orderItemRepository
* @param \Webkul\Customer\Repositories\CustomerRepository $customerRepository
* @param \Webkul\Product\Repositories\ProductInventoryRepository $productInventoryRepository
* @return void
*/
public function __construct(
Order $order,
OrderItem $orderItem,
Customer $customer,
ProductInventory $productInventory
OrderRepository $orderRepository,
OrderItemRepository $orderItemRepository,
CustomerRepository $customerRepository,
ProductInventoryRepository $productInventoryRepository
)
{
$this->_config = request('_config');
$this->middleware('admin');
$this->order = $order;
$this->orderRepository = $orderRepository;
$this->orderItem = $orderItem;
$this->orderItemRepository = $orderItemRepository;
$this->customer = $customer;
$this->customerRepository = $customerRepository;
$this->productInventory = $productInventory;
$this->productInventoryRepository = $productInventoryRepository;
}
public function getPercentageChange($previous, $current)
@ -175,7 +175,7 @@ class DashboardController extends Controller
*/
public function getTopSellingCategories()
{
return $this->orderItem->getModel()
return $this->orderItemRepository->getModel()
->leftJoin('products', 'order_items.product_id', 'products.id')
->leftJoin('product_categories', 'products.id', 'product_categories.product_id')
->leftJoin('categories', 'product_categories.category_id', 'categories.id')
@ -200,7 +200,7 @@ class DashboardController extends Controller
*/
public function getStockThreshold()
{
return $this->productInventory->getModel()
return $this->productInventoryRepository->getModel()
->leftJoin('products', 'product_inventories.product_id', 'products.id')
->select(DB::raw('SUM(qty) as total_qty'))
->addSelect('product_inventories.product_id')
@ -217,7 +217,7 @@ class DashboardController extends Controller
*/
public function getTopSellingProducts()
{
return $this->orderItem->getModel()
return $this->orderItemRepository->getModel()
->select(DB::raw('SUM(qty_ordered) as total_qty_ordered'))
->addSelect('id', 'product_id', 'product_type', 'name')
->where('order_items.created_at', '>=', $this->startDate)
@ -236,7 +236,7 @@ class DashboardController extends Controller
*/
public function getCustomerWithMostSales()
{
return $this->order->getModel()
return $this->orderRepository->getModel()
->select(DB::raw('SUM(base_grand_total) as total_base_grand_total'))
->addSelect(DB::raw('COUNT(id) as total_orders'))
->addSelect('id', 'customer_id', 'customer_email', 'customer_first_name', 'customer_last_name')
@ -285,14 +285,14 @@ class DashboardController extends Controller
private function getOrdersBetweenDate($start, $end)
{
return $this->order->scopeQuery(function ($query) use ($start, $end) {
return $this->orderRepository->scopeQuery(function ($query) use ($start, $end) {
return $query->where('orders.created_at', '>=', $start)->where('orders.created_at', '<=', $end);
});
}
private function getCustomersBetweenDates($start, $end)
{
return $this->customer->scopeQuery(function ($query) use ($start, $end) {
return $this->customerRepository->scopeQuery(function ($query) use ($start, $end) {
return $query->where('customers.created_at', '>=', $start)->where('customers.created_at', '<=', $end);
});
}

View File

@ -233,7 +233,7 @@
<td>
{{ $item->name }}
@if ($html = $item->getOptionDetailHtml())
<p>{{ $html }}</p>
@elseif ($item->type == 'downloadable')

View File

@ -256,7 +256,7 @@
<td>
{{ $item->name }}
@if ($item->type == 'configurable' && $html = $item->getOptionDetailHtml())
@if ($html = $item->getOptionDetailHtml())
<p>{{ $html }}</p>
@elseif ($item->type == 'downloadable')
<p><b>Downloads : </b>{{ $item->getDownloadableDetailHtml() }}</p>

View File

@ -276,7 +276,7 @@
<td>{{ $item->type == 'configurable' ? $item->child->sku : $item->sku }}</td>
<td>
{{ $item->name }}
@if ($html = $item->getOptionDetailHtml())
<p>{{ $html }}</p>
@elseif ($item->type == 'downloadable')

View File

@ -251,7 +251,7 @@
<td>{{ $item->sku }}</td>
<td>
{{ $item->name }}
@if ($html = $item->getOptionDetailHtml())
<p>{{ $html }}</p>
@elseif ($item->type == 'downloadable')

View File

@ -45,21 +45,20 @@ class InvoiceItem extends Model implements InvoiceItemContract
return $this->hasOne(InvoiceItemProxy::modelClass(), 'parent_id');
}
/**
* Get order item type
*/
public function getTypeAttribute()
{
return $this->order_item->type;
}
/**
* Returns configurable option html
*/
public function getOptionDetailHtml()
{
if ($this->type == 'configurable' && isset($this->additional['attributes'])) {
$labels = [];
foreach ($this->additional['attributes'] as $attribute) {
$labels[] = $attribute['attribute_name'] . ' : ' . $attribute['option_label'];
}
return implode(', ', $labels);
}
return $this->order_item->getOptionDetailHtml();
}
/**
@ -67,6 +66,6 @@ class InvoiceItem extends Model implements InvoiceItemContract
*/
public function getDownloadableDetailHtml()
{
return $this->order_item->getOptionDetailHtml();
return $this->order_item->getDownloadableDetailHtml();
}
}

View File

@ -158,7 +158,10 @@ class OrderItem extends Model implements OrderItemContract
*/
public function getOptionDetailHtml()
{
if ($this->type == 'configurable' && isset($this->additional['attributes'])) {
if ($this->type != 'configurable')
return;
if (isset($this->additional['attributes'])) {
$labels = [];
foreach ($this->additional['attributes'] as $attribute) {

View File

@ -45,21 +45,20 @@ class ShipmentItem extends Model implements ShipmentItemContract
return $this->belongsTo(ShipmentItemProxy::modelClass(), 'parent_id');
}
/**
* Get order item type
*/
public function getTypeAttribute()
{
return $this->order_item->type;
}
/**
* Returns configurable option html
*/
public function getOptionDetailHtml()
{
if ($this->type == 'configurable' && isset($this->additional['attributes'])) {
$labels = [];
foreach ($this->additional['attributes'] as $attribute) {
$labels[] = $attribute['attribute_name'] . ' : ' . $attribute['option_label'];
}
return implode(', ', $labels);
}
return $this->order_item->getOptionDetailHtml();
}
/**
@ -67,6 +66,6 @@ class ShipmentItem extends Model implements ShipmentItemContract
*/
public function getDownloadableDetailHtml()
{
return $this->order_item->getOptionDetailHtml();
return $this->order_item->getDownloadableDetailHtml();
}
}

View File

@ -112,20 +112,24 @@
<tr>
<td data-value="{{ __('shop::app.customer.account.order.view.SKU') }}" style="text-align: left;padding: 8px">{{ $item->child ? $item->child->sku : $item->sku }}</td>
<td data-value="{{ __('shop::app.customer.account.order.view.product-name') }}" style="text-align: left;padding: 8px">{{ $item->name }}</td>
<td data-value="{{ __('shop::app.customer.account.order.view.product-name') }}" style="text-align: left;padding: 8px">
{{ $item->name }}
@if ($html = $item->getOptionDetailHtml())
<div style="">
<label style="margin-top: 10px; font-size: 16px;color: #5E5E5E; display: block;">
{{ $html }}
</label>
</div>
@elseif ($item->type == 'downloadable')
<p><b>Downloads : </b>{{ $item->getDownloadableDetailHtml() }}</p>
@endif
</td>
<td data-value="{{ __('shop::app.customer.account.order.view.price') }}" style="text-align: left;padding: 8px">{{ core()->formatPrice($item->price, $order->order_currency_code) }}
</td>
<td data-value="{{ __('shop::app.customer.account.order.view.qty') }}" style="text-align: left;padding: 8px">{{ $item->qty_ordered }}</td>
@if ($html = $item->getOptionDetailHtml())
<div style="">
<label style="margin-top: 10px; font-size: 16px;color: #5E5E5E; display: block;">
{{ $html }}
</label>
</div>
@endif
</tr>
@endforeach
</tbody>
@ -172,7 +176,7 @@
</div>
</div>
<div style="margin-top: 65px;font-size: 16px;color: #5E5E5E;line-height: 24px;display: inline-block">
<div style="width: 100%;margin-top: 65px;font-size: 16px;color: #5E5E5E;line-height: 24px;display: inline-block">
<p style="font-size: 16px;color: #5E5E5E;line-height: 24px;">
{!!
__('shop::app.mail.order.help', [

View File

@ -122,20 +122,25 @@
@foreach ($shipment->items as $item)
<tr>
<td data-value="{{ __('shop::app.customer.account.order.view.SKU') }}" style="text-align: left;padding: 8px">{{ $item->child ? $item->child->sku : $item->sku }}</td>
<td data-value="{{ __('shop::app.customer.account.order.view.product-name') }}" style="text-align: left;padding: 8px">{{ $item->name }}</td>
<td data-value="{{ __('shop::app.customer.account.order.view.product-name') }}" style="text-align: left;padding: 8px">
{{ $item->name }}
@if ($html = $item->getOptionDetailHtml())
<div style="">
<label style="margin-top: 10px; font-size: 16px;color: #5E5E5E; display: block;">
{{ $html }}
</label>
</div>
@elseif ($item->type == 'downloadable')
<p><b>Downloads : </b>{{ $item->getDownloadableDetailHtml() }}</p>
@endif
</td>
<td data-value="{{ __('shop::app.customer.account.order.view.price') }}" style="text-align: left;padding: 8px">{{ core()->formatPrice($item->price, $order->order_currency_code) }}</td>
<td data-value="{{ __('shop::app.customer.account.order.view.qty') }}" style="text-align: left;padding: 8px">{{ $item->qty }}</td>
</tr>
@if ($html = $item->getOptionDetailHtml())
<div style="">
<label style="margin-top: 10px; font-size: 16px;color: #5E5E5E; display: block;">
{{ $html }}
</label>
</div>
@elseif ($item->type == 'downloadable')
<p><b>Downloads : </b>{{ $item->getDownloadableDetailHtml() }}</p>
@endif
@endforeach
</tbody>
</table>

View File

@ -113,22 +113,24 @@
<tbody>
@foreach ($invoice->items as $item)
<tr>
<td data-value="{{ __('shop::app.customer.account.order.view.product-name') }}" style="text-align: left;padding: 8px">{{ $item->name }}</td>
<td data-value="{{ __('shop::app.customer.account.order.view.product-name') }}" style="text-align: left;padding: 8px">
{{ $item->name }}
@if ($html = $item->getOptionDetailHtml())
<div style="">
<label style="margin-top: 10px; font-size: 16px;color: #5E5E5E; display: block;">
{{ $html }}
</label>
</div>
@elseif ($item->type == 'downloadable')
<p><b>Downloads : </b>{{ $item->getDownloadableDetailHtml() }}</p>
@endif
</td>
<td data-value="{{ __('shop::app.customer.account.order.view.price') }}" style="text-align: left;padding: 8px">{{ core()->formatPrice($item->price, $order->order_currency_code) }}
</td>
<td data-value="{{ __('shop::app.customer.account.order.view.qty') }}" style="text-align: left;padding: 8px">{{ $item->qty }}</td>
@if ($html = $item->getOptionDetailHtml())
<div style="">
<label style="margin-top: 10px; font-size: 16px;color: #5E5E5E; display: block;">
{{ $html }}
</label>
</div>
@elseif ($item->type == 'downloadable')
<p><b>Downloads : </b>{{ $item->getDownloadableDetailHtml() }}</p>
@endif
</tr>
@endforeach

View File

@ -114,22 +114,24 @@
<tr>
<td data-value="{{ __('shop::app.customer.account.order.view.SKU') }}" style="text-align: left;padding: 8px">{{ $item->child ? $item->child->sku : $item->sku }}</td>
<td data-value="{{ __('shop::app.customer.account.order.view.product-name') }}" style="text-align: left;padding: 8px">{{ $item->name }}</td>
<td data-value="{{ __('shop::app.customer.account.order.view.product-name') }}" style="text-align: left;padding: 8px">
{{ $item->name }}
@if ($html = $item->getOptionDetailHtml())
<div style="">
<label style="margin-top: 10px; font-size: 16px;color: #5E5E5E; display: block;">
{{ $html }}
</label>
</div>
@elseif ($item->type == 'downloadable')
<p><b>Downloads : </b>{{ $item->getDownloadableDetailHtml() }}</p>
@endif
</td>
<td data-value="{{ __('shop::app.customer.account.order.view.price') }}" style="text-align: left;padding: 8px">{{ core()->formatPrice($item->price, $order->order_currency_code) }}
</td>
<td data-value="{{ __('shop::app.customer.account.order.view.qty') }}" style="text-align: left;padding: 8px">{{ $item->qty_ordered }}</td>
@if ($html = $item->getOptionDetailHtml())
<div style="">
<label style="margin-top: 10px; font-size: 16px;color: #5E5E5E; display: block;">
{{ $html }}
</label>
</div>
@elseif ($item->type == 'downloadable')
<p><b>Downloads : </b>{{ $item->getDownloadableDetailHtml() }}</p>
@endif
</tr>
@endforeach
</tbody>

View File

@ -123,19 +123,24 @@
@foreach ($shipment->items as $item)
<tr>
<td data-value="{{ __('shop::app.customer.account.order.view.SKU') }}" style="text-align: left;padding: 8px">{{ $item->child ? $item->child->sku : $item->sku }}</td>
<td data-value="{{ __('shop::app.customer.account.order.view.product-name') }}" style="text-align: left;padding: 8px">{{ $item->name }}</td>
<td data-value="{{ __('shop::app.customer.account.order.view.price') }}" style="text-align: left;padding: 8px">{{ core()->formatPrice($item->price, $order->order_currency_code) }}</td>
<td data-value="{{ __('shop::app.customer.account.order.view.qty') }}" style="text-align: left;padding: 8px">{{ $item->qty }}</td>
@if ($html = $item->getOptionDetailHtml())
<div style="">
<label style="margin-top: 10px; font-size: 16px;color: #5E5E5E; display: block;">
{{ $html }}
</label>
</div>
@elseif ($item->type == 'downloadable')
<p><b>Downloads : </b>{{ $item->getDownloadableDetailHtml() }}</p>
@endif
<td data-value="{{ __('shop::app.customer.account.order.view.product-name') }}" style="text-align: left;padding: 8px">
{{ $item->name }}
@if ($html = $item->getOptionDetailHtml())
<div style="">
<label style="margin-top: 10px; font-size: 16px;color: #5E5E5E; display: block;">
{{ $html }}
</label>
</div>
@elseif ($item->type == 'downloadable')
<p><b>Downloads : </b>{{ $item->getDownloadableDetailHtml() }}</p>
@endif
</td>
<td data-value="{{ __('shop::app.customer.account.order.view.price') }}" style="text-align: left;padding: 8px">{{ core()->formatPrice($item->price, $order->order_currency_code) }}</td>
<td data-value="{{ __('shop::app.customer.account.order.view.qty') }}" style="text-align: left;padding: 8px">{{ $item->qty }}</td>
</tr>
@endforeach