Skip to content
Merged
Show file tree
Hide file tree
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
5 changes: 5 additions & 0 deletions backend/app/DomainObjects/ProductPriceDomainObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,4 +113,9 @@ public function getOffSaleReason(): ?string
{
return $this->offSaleReason;
}

public function isFree(): bool
{
return $this->getPrice() === 0.00;
}
}
10 changes: 5 additions & 5 deletions backend/app/Services/Domain/Order/OrderItemProcessingService.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@
use Illuminate\Support\Collection;
use Symfony\Component\Routing\Exception\ResourceNotFoundException;

readonly class OrderItemProcessingService
class OrderItemProcessingService
{
public function __construct(
private OrderRepositoryInterface $orderRepository,
private ProductRepositoryInterface $productRepository,
private TaxAndFeeCalculationService $taxCalculationService,
private ProductPriceService $productPriceService,
private readonly OrderRepositoryInterface $orderRepository,
private readonly ProductRepositoryInterface $productRepository,
private readonly TaxAndFeeCalculationService $taxCalculationService,
private readonly ProductPriceService $productPriceService,
)
{
}
Expand Down
15 changes: 9 additions & 6 deletions backend/app/Services/Domain/Product/ProductFilterService.php
Original file line number Diff line number Diff line change
Expand Up @@ -162,12 +162,15 @@ private function filterProduct(

private function processProductPrice(ProductDomainObject $product, ProductPriceDomainObject $price): void
{
$taxAndFees = $this->taxCalculationService
->calculateTaxAndFeesForProductPrice($product, $price);

$price
->setTaxTotal(Currency::round($taxAndFees->taxTotal))
->setFeeTotal(Currency::round($taxAndFees->feeTotal));
// If the product is free of charge, we don't charge service fees or taxes
if (!$price->isFree()) {
$taxAndFees = $this->taxCalculationService
->calculateTaxAndFeesForProductPrice($product, $price);

$price
->setTaxTotal(Currency::round($taxAndFees->taxTotal))
->setFeeTotal(Currency::round($taxAndFees->feeTotal));
}

$price->setIsAvailable($this->getPriceAvailability($price, $product));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
namespace HiEvents\Services\Domain\Tax;

use HiEvents\DomainObjects\Enums\TaxCalculationType;
use HiEvents\DomainObjects\TaxAndFeesDomainObject;
use HiEvents\DomainObjects\ProductDomainObject;
use HiEvents\DomainObjects\ProductPriceDomainObject;
use HiEvents\DomainObjects\TaxAndFeesDomainObject;
use HiEvents\Services\Domain\Tax\DTO\TaxCalculationResponse;
use InvalidArgumentException;

Expand Down Expand Up @@ -49,6 +49,13 @@ public function calculateTaxAndFeesForProduct(

private function calculateFee(TaxAndFeesDomainObject $taxOrFee, float $price, int $quantity): float
{
// We do not charge a tax or fee on items which are free of charge
if ($price === 0.00) {
$this->taxRollupService->addToRollUp($taxOrFee, 0);

return 0.00;
}

$amount = match ($taxOrFee->getCalculationType()) {
TaxCalculationType::FIXED->name => $taxOrFee->getRate(),
TaxCalculationType::PERCENTAGE->name => ($price * $taxOrFee->getRate()) / 100,
Expand Down
Loading