public function __construct( private readonly EntityRepository
$taxRepository,
private readonly NetPriceCalculator
$netCalculator,
private readonly GrossPriceCalculator
$grossCalculator ) { } #[Route(path: 'api/_action/calculate-price', name: 'api.action.calculate-price', methods: ['POST'])]
public function calculate(Request
$request, Context
$context): JsonResponse
{ if (!
$request->request->
has('price'
)) { throw CartException::
priceParameterIsMissing();
} if (!
$request->request->
has('taxId'
)) { throw CartException::
taxIdParameterIsMissing();
} $taxId =
(string) $request->request->
get('taxId'
);
$price =
(float) $request->request->
get('price'
);
$quantity =
$request->request->
getInt('quantity', 1
);
$output =
(string) $request->request->
get('output', 'gross'
);
$preCalculated =
$request->request->
getBoolean('calculated', true
);