sarga/packages/Webkul/Sales/src/Models/OrderItem.php

97 lines
2.3 KiB
PHP
Raw Normal View History

<?php
namespace Webkul\Sales\Models;
use Illuminate\Database\Eloquent\Model;
use Webkul\Sales\Contracts\OrderItem as OrderItemContract;
2018-10-23 11:45:44 +00:00
use Webkul\Product\Models\Product;
class OrderItem extends Model implements OrderItemContract
{
2018-10-05 06:18:58 +00:00
protected $guarded = ['id', 'child', 'created_at', 'updated_at'];
2018-10-26 04:20:43 +00:00
protected $casts = [
'additional' => 'array',
];
/**
* Get remaining qty for shipping.
*/
public function getQtyToShipAttribute()
{
2018-10-15 10:39:09 +00:00
return $this->qty_ordered - $this->qty_shipped - $this->qty_refunded - $this->qty_canceled;
}
/**
* Get remaining qty for invoice.
*/
public function getQtyToInvoiceAttribute()
{
2018-10-15 10:39:09 +00:00
return $this->qty_ordered - $this->qty_invoiced - $this->qty_canceled;
}
/**
* Get remaining qty for cancel.
*/
public function getQtyToCancelAttribute()
{
2018-10-15 10:39:09 +00:00
return $this->qty_ordered - $this->qty_canceled - $this->qty_invoiced;
}
/**
* Get the order record associated with the order item.
*/
public function order()
{
return $this->belongsTo(OrderProxy::modelClass());
}
/**
* Get the order record associated with the order item.
*/
public function product()
{
return $this->morphTo();
}
/**
* Get the child item record associated with the order item.
*/
public function child()
{
return $this->hasOne(OrderItemProxy::modelClass(), 'parent_id');
}
2018-10-05 06:18:58 +00:00
/**
* Get the invoice items record associated with the order item.
*/
public function invoice_items()
{
return $this->hasMany(InvoiceItemProxy::modelClass());
}
/**
* Get the shipment items record associated with the order item.
*/
public function shipment_items()
{
return $this->hasMany(ShipmentItemProxy::modelClass());
2018-10-05 06:18:58 +00:00
}
2018-10-26 04:20:43 +00:00
/**
* 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);
}
}
}