getCartPriceTaxes example

$price = $this->amountCalculator->calculate(
            $cart->getLineItems()->getPrices(),
            $cart->getDeliveries()->getShippingCosts(),
            $context
        );

        // either take the price from the tax provider result or take the calculated taxes         $taxes = $price->getCalculatedTaxes()->filter(fn (CalculatedTax $tax) => $tax->getTax() > 0.0);
        $price->setCalculatedTaxes($taxes);

        if ($result->getCartPriceTaxes()) {
            $price = $this->applyCartPriceTaxes($price$result->getCartPriceTaxes()$context);
        }

        $cart->setPrice($price);
    }

    private function applyCartPriceTaxes(CartPrice $price, CalculatedTaxCollection $taxes, SalesChannelContext $context): CartPrice
    {
        $netPrice = $price->getNetPrice();
        $grossPrice = $price->getTotalPrice();
        $taxSum = $taxes->getAmount();

        
static::assertEquals(new CalculatedTax(3.0, 3.0, 3.0)$response->getLineItemTaxes()[$this->ids->get('line-item-2')]->getAt(1));

        static::assertNotNull($response->getDeliveryTaxes());
        static::assertCount(2, $response->getDeliveryTaxes());
        static::assertArrayHasKey($this->ids->get('delivery-1')$response->getDeliveryTaxes());
        static::assertArrayHasKey($this->ids->get('delivery-2')$response->getDeliveryTaxes());

        static::assertEquals(new CalculatedTax(4.0, 4.0, 4.0)$response->getDeliveryTaxes()[$this->ids->get('delivery-1')]->getAt(0));
        static::assertEquals(new CalculatedTax(5.0, 5.0, 5.0)$response->getDeliveryTaxes()[$this->ids->get('delivery-2')]->getAt(0));
        static::assertEquals(new CalculatedTax(6.0, 6.0, 6.0)$response->getDeliveryTaxes()[$this->ids->get('delivery-2')]->getAt(1));

        static::assertNotNull($response->getCartPriceTaxes());
        static::assertCount(2, $response->getCartPriceTaxes());
        static::assertEquals(new CalculatedTax(7.0, 7.0, 7.0)$response->getCartPriceTaxes()->getAt(0));
        static::assertEquals(new CalculatedTax(8.0, 8.0, 8.0)$response->getCartPriceTaxes()->getAt(1));
    }

    public function testSetters(): void
    {
        $response = new TaxProviderResponse();

        $response->setLineItemTaxes([
            $this->ids->get('line-item-1') => new CalculatedTaxCollection([
                

class TaxProviderStructTest extends TestCase
{
    public function testEmpty(): void
    {
        $struct = new TaxProviderResult();

        static::assertNull($struct->getLineItemTaxes());
        static::assertNull($struct->getDeliveryTaxes());
        static::assertNull($struct->getCartPriceTaxes());
        static::assertFalse($struct->declaresTaxes());
    }

    /** * @param array<string, CalculatedTaxCollection>|null $lineItemTaxes * @param array<string, CalculatedTaxCollection>|null $deliveryTaxes * * @dataProvider structDataProvider */
    public function testDirty(
        ?array $lineItemTaxes,
        ?
$deliveryTaxes = $taxResponse->getDeliveryTaxes();
        static::assertNotNull($deliveryTaxes);
        static::assertArrayHasKey($this->ids->get('delivery-1')$deliveryTaxes);
        $taxes = $deliveryTaxes[$this->ids->get('delivery-1')];
        $tax = $taxes->first();
        static::assertInstanceOf(CalculatedTax::class$tax);
        static::assertCount(1, $taxes);
        static::assertSame(7.0, $tax->getTax());
        static::assertSame(7.0, $tax->getTaxRate());
        static::assertSame(100.0, $tax->getPrice());

        $cartPriceTaxes = $taxResponse->getCartPriceTaxes();
        static::assertNotNull($cartPriceTaxes);
        $cartPriceTax = $cartPriceTaxes->first();
        static::assertInstanceOf(CalculatedTax::class$cartPriceTax);
        static::assertCount(1, $cartPriceTaxes);
        static::assertSame(26.0, $cartPriceTax->getTax());
        static::assertSame(13.0, $cartPriceTax->getTaxRate());
        static::assertSame(200.0, $cartPriceTax->getPrice());
    }

    public function testGuzzleException(): void
    {
        
Home | Imprint | This part of the site doesn't use cookies.