Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
| Total | |
0.00% |
0 / 1 |
|
25.00% |
1 / 4 |
CRAP | |
15.38% |
2 / 13 |
| PerProduct | |
0.00% |
0 / 1 |
|
25.00% |
1 / 4 |
13.69 | |
15.38% |
2 / 13 |
| __construct | |
100.00% |
1 / 1 |
1 | |
100.00% |
2 / 2 |
|||
| perProduct | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 5 |
|||
| getRange | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 5 |
|||
| perVariant | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 1 |
|||
| <?php | |
| namespace Mtc\Shop\PriceMethods; | |
| use Mtc\Shop\Contracts\PriceMethod; | |
| use Mtc\Shop\PriceMethods\Models\PricePerProduct; | |
| use Mtc\Shop\Product; | |
| use Mtc\Shop\Variant; | |
| class PerProduct implements PriceMethod | |
| { | |
| /** | |
| * Store the product model | |
| * | |
| * @var Mtc\Shop\Product|null | |
| */ | |
| protected $product = null; | |
| /** | |
| * Setup the price method | |
| * | |
| * @param Mtc\Shop\Product $product | |
| * @param Mtc\Shop\Variant|null $variant | |
| */ | |
| public function __construct(Product $product, Variant $variant = null) | |
| { | |
| $this->product = $product; | |
| } | |
| /** | |
| * Get the price (or lowest variant price) for a product. | |
| * | |
| * @param integer $quantity (default: 1) | |
| * @return float | |
| */ | |
| public function perProduct($quantity = 1) | |
| { | |
| // Bulk pricing is built in by default. | |
| return PricePerProduct::where('product_id', $this->product->id) | |
| ->where('quantity', '<=', $quantity) | |
| ->orderBy('quantity', 'asc') | |
| ->first() | |
| ->price; | |
| } | |
| /** | |
| * Get the min/max price for an product. | |
| * | |
| * @param integer $quantity (default: 1) | |
| * @return float[] | |
| */ | |
| public function getRange($quantity = 1) | |
| { | |
| $prices = PricePerProduct::where('product_id', $this->product->id) | |
| ->orderBy('price', 'asc') | |
| ->get(); | |
| return [ | |
| 'min' => $prices->first(), | |
| 'max' => $prices->last(), | |
| ]; | |
| } | |
| /** | |
| * Get the price for a variant. | |
| * @param integer $quantity (default: 1) | |
| * @return float | |
| */ | |
| public function perVariant($quantity = 1) | |
| { | |
| return $this->perProduct($quantity); | |
| } | |
| } |