Page MenuHomePhorge

PackageSku.php
No OneTemporary

Authored By
Unknown
Size
1 KB
Referenced Files
None
Subscribers
None

PackageSku.php

<?php
namespace App;
use Illuminate\Database\Eloquent\Relations\Pivot;
/**
* Link SKUs to Packages.
*/
class PackageSku extends Pivot
{
protected $fillable = [
'package_id',
'sku_id',
'cost',
'qty'
];
protected $casts = [
'cost' => 'integer',
'qty' => 'integer'
];
/**
* Under this package, how much does this SKU cost?
*
* @return int The costs of this SKU under this package in cents.
*/
public function cost()
{
$costs = 0;
$units = $this->qty - $this->sku->units_free;
if ($units < 0) {
\Log::debug(
"Package {$this->package_id} is misconfigured for more free units than qty."
);
$units = 0;
}
$ppu = $this->sku->cost * ((100 - $this->package->discount_rate) / 100);
$costs += $units * $ppu;
return $costs;
}
public function package()
{
return $this->belongsTo('App\Package');
}
public function sku()
{
return $this->belongsTo('App\Sku');
}
}

File Metadata

Mime Type
text/x-php
Expires
Fri, Apr 24, 1:48 PM (3 d, 20 h ago)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
64/91/4f6f15c5ad00b21682fe9db2669c
Default Alt Text
PackageSku.php (1 KB)

Event Timeline