Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 15 additions & 7 deletions packages/core/src/Models/Price.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,41 +92,49 @@ public function priceExTax(): \Lunar\DataTypes\Price
/**
* Return the price inclusive of tax.
*/
public function priceIncTax(): int|\Lunar\DataTypes\Price
public function priceIncTax(?TaxZone $taxZone = null): int|\Lunar\DataTypes\Price
{
if (prices_inc_tax()) {
return $this->price;
}

$priceIncTax = clone $this->price;
$priceIncTax->value = (int) round($priceIncTax->value * (1 + $this->getPriceableTaxRate()));
$priceIncTax->value = (int) round($priceIncTax->value * (1 + $this->getPriceableTaxRate($taxZone)));

return $priceIncTax;
}

/**
* Return the compare price inclusive of tax.
*/
public function comparePriceIncTax(): int|\Lunar\DataTypes\Price
public function comparePriceIncTax(?TaxZone $taxZone = null): int|\Lunar\DataTypes\Price
{
if (prices_inc_tax()) {
return $this->compare_price;
}

$comparePriceIncTax = clone $this->compare_price;
$comparePriceIncTax->value = (int) round($comparePriceIncTax->value * (1 + $this->getPriceableTaxRate()));
$comparePriceIncTax->value = (int) round($comparePriceIncTax->value * (1 + $this->getPriceableTaxRate($taxZone)));

return $comparePriceIncTax;
}

/**
* Return the total tax rate amount within the predefined tax zone for the related priceable
*/
protected function getPriceableTaxRate(): int|float
protected function getPriceableTaxRate(?TaxZone $taxZone = null): int|float
{
return Blink::once('price_tax_rate_'.$this->priceable->getTaxClass()->id, function () {
$taxZone = TaxZone::where('default', '=', 1)->first();
/* This function is called multiple times somewhere from the package and since we just added an optional
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@alecritson not sure we want to leave this comment in the code

Copy link
Copy Markdown
Contributor Author

@MacTavish-69 MacTavish-69 Mar 31, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ignore this PR in favor of #2411 , because this functionality is present in the newer PR as well.

This PR/Code was our earlier solution to show Tax Incl. Prices but it wouldn't work on cart items. It would only be applicable on Models which had price attached to them.

* parameter to it, the initial calls are with Null Tax Zone and the result is cached which
* ignores the subsequent calls with a valid Tax Zone.
* Hence we forget the cache and let it run with the provided tax zone and cache that value.
*/
if ($taxZone) {
Blink::forget('price_tax_rate_'.$this->priceable->getTaxClass()->id);
}

return Blink::once('price_tax_rate_'.$this->priceable->getTaxClass()->id, function () use ($taxZone) {
$taxZone = $taxZone ?? TaxZone::where('default', '=', 1)->first();
if ($taxZone && ! is_null($taxClass = $this->priceable->getTaxClass())) {
return $taxClass->taxRateAmounts
->whereIn('tax_rate_id', $taxZone->taxRates->pluck('id'))
Expand Down
Loading