¨4.0.1¨
This commit is contained in:
@@ -32,6 +32,7 @@ class OptionValue extends Model
|
||||
*/
|
||||
protected $translatedAttributes = ['label'];
|
||||
|
||||
|
||||
public function getPriceAttribute($price)
|
||||
{
|
||||
if ($this->priceIsPercent()) {
|
||||
@@ -41,29 +42,12 @@ class OptionValue extends Model
|
||||
return Money::inDefaultCurrency($price);
|
||||
}
|
||||
|
||||
|
||||
public function priceIsPercent()
|
||||
{
|
||||
return $this->price_type === 'percent';
|
||||
}
|
||||
|
||||
public function priceIsFixed()
|
||||
{
|
||||
return $this->price_type === 'fixed';
|
||||
}
|
||||
|
||||
public function priceForProduct(Product $product)
|
||||
{
|
||||
if ($this->priceIsFixed()) {
|
||||
return $this->price;
|
||||
}
|
||||
|
||||
return $this->getPercentOf($product->selling_price->amount());
|
||||
}
|
||||
|
||||
private function getPercentOf($productPrice)
|
||||
{
|
||||
return Money::inDefaultCurrency(($this->price / 100) * $productPrice);
|
||||
}
|
||||
|
||||
public function formattedPriceForProduct(Product $product, $forSelectOption = false)
|
||||
{
|
||||
@@ -81,4 +65,28 @@ class OptionValue extends Model
|
||||
|
||||
return "<span class='extra-price'>+ {$formattedPrice}</span>";
|
||||
}
|
||||
|
||||
|
||||
public function priceForProduct(Product $product)
|
||||
{
|
||||
if ($this->priceIsFixed()) {
|
||||
return $this->price;
|
||||
}
|
||||
|
||||
return $this->getPercentOf(($product->variant ?? $product)
|
||||
->selling_price
|
||||
->amount());
|
||||
}
|
||||
|
||||
|
||||
public function priceIsFixed()
|
||||
{
|
||||
return $this->price_type === 'fixed';
|
||||
}
|
||||
|
||||
|
||||
private function getPercentOf($productPrice)
|
||||
{
|
||||
return Money::inDefaultCurrency(($this->price / 100) * $productPrice);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user