TaxProviderResult example

new AmountCalculator(
                new CashRounding(),
                new PercentageTaxRuleBuilder(),
                new TaxAdjustmentCalculator()
            ),
            new CashRounding()
        );
    }

    public function testItThrowsOnEmptyLineItemPrice(): void
    {
        $struct = new TaxProviderResult(
            [
                $this->ids->get('line-item-1') => new CalculatedTaxCollection([
                    new CalculatedTax(
                        7,
                        7,
                        100
                    ),
                ]),
            ],
            [
                $this->ids->get('delivery-position-1') => new CalculatedTaxCollection([
                    
if ($cart->getLineItems()->count() > 0 || $cart->getDeliveries()->count() > 0) {
            $cartTax = new CalculatedTaxCollection([
                new CalculatedTax(
                    $total->getTotalPrice() * $this->taxRate,
                    $this->taxRate * 100,
                    $total->getTotalPrice()
                ),
            ]);
        }

        return new TaxProviderResult($lineItems$deliveries$cartTax ?? null);
    }
}
/** * @package checkout * * @internal * * @covers \Shopware\Core\Checkout\Cart\TaxProvider\Struct\TaxProviderResult */
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 */
$lineItemTax = $lineItemTaxes['7'];
        $deliveryTax = $deliveryTaxes['7'];

        static::assertEquals(7, $lineItemTax->getTaxRate());
        static::assertEquals(7, $deliveryTax->getTaxRate());
    }

    public function testNoTaxResultsGivenThrowsException(): void
    {
        // empty data set should result in exception to prevent invalid taxes         $taxProviderStruct = new TaxProviderResult();

        $cart = new Cart('foo');
        $salesChannelContext = static::createMock(SalesChannelContext::class);
        $salesChannelContext
            ->method('getTotalRounding')
            ->willReturn(new CashRoundingConfig(2, 0.01, true));

        $testProvider = static::createMock(TestEmptyTaxProvider::class);
        $testProvider
            ->expects(static::once())
            ->method('provide')
            
Home | Imprint | This part of the site doesn't use cookies.