Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
| Total | |
0.00% |
0 / 1 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 5 |
| Variant | |
0.00% |
0 / 1 |
|
0.00% |
0 / 2 |
12 | |
0.00% |
0 / 5 |
| product | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 1 |
|||
| getPriceAttribute | |
0.00% |
0 / 1 |
6 | |
0.00% |
0 / 4 |
|||
| <?php | |
| namespace Mtc\Shop; | |
| use Illuminate\Database\Eloquent\Model; | |
| use Mtc\Core\Admin\Nodeable; | |
| class Variant extends Model | |
| { | |
| use Nodeable; | |
| protected $fillable = [ | |
| 'product_id', | |
| 'sku', | |
| 'stock_enabled', | |
| 'stock_quantity', | |
| 'shipping_weight', | |
| 'shipping_dimensions_length', | |
| 'shipping_dimensions_width', | |
| 'shipping_dimensions_height', | |
| 'price', | |
| 'sale_price', | |
| 'sale_price_valid_from', | |
| 'sale_price_valid_until', | |
| ]; | |
| protected $casts = [ | |
| 'price' => 'double', | |
| 'sale_price' => 'double', | |
| ]; | |
| protected $touches = ['product']; | |
| public function product() | |
| { | |
| return $this->belongsTo(Product::class); | |
| } | |
| public function getPriceAttribute() | |
| { | |
| $price_method = $this->product->price_method; | |
| if (!class_exists($price_method)) { | |
| throw new \Exception("Price method not found: {$price_method}"); | |
| } | |
| return new $price_method($this->product, $this); | |
| } | |
| } |