¨4.0.1¨

This commit is contained in:
¨NW¨
2023-12-03 14:07:47 +00:00
parent c08b36d1b6
commit f35052522d
1112 changed files with 43019 additions and 24987 deletions

View File

@@ -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);
}
}