buildTaxRules example


        switch ($shippingMethod->getTaxType()) {
            case ShippingMethodEntity::TAX_TYPE_HIGHEST:
                $rules = $calculatedLineItems->getPrices()->getHighestTaxRule();

                break;

            case ShippingMethodEntity::TAX_TYPE_FIXED:
                $tax = $shippingMethod->getTax();

                if ($tax !== null) {
                    $rules = $context->buildTaxRules($tax->getId());

                    break;
                }

                // no break             default:
                $rules = $this->percentageTaxRuleBuilder->buildRules(
                    $calculatedLineItems->getPrices()->sum()
                );
        }

        


    public function testGetTaxRuleCollectionWithoutRulesReturnsDefault(): void
    {
        $taxId = Uuid::randomHex();
        $taxData = [
            'id' => $taxId,
            'taxRate' => 15,
            'name' => Uuid::randomHex(),
        ];
        $salesChannelContext = $this->createSalesChannelContext([$taxData][]);
        $taxRuleCollection = $salesChannelContext->buildTaxRules($taxId);

        static::assertCount(1, $taxRuleCollection);
        static::assertSame(15.0, $taxRuleCollection->first()?->getTaxRate());
        static::assertSame(100.0, $taxRuleCollection->first()->getPercentage());
    }

    public function testGetTaxRuleCollectionCustomerShippingCountry(): void
    {
        $customerId = Uuid::randomHex();
        $shippingCountryId = Uuid::randomHex();
        $this->createCustomer($customerId$shippingCountryId, Uuid::randomHex());
        
private function buildDefinition(
        Entity $product,
        PriceCollection $prices,
        SalesChannelContext $context,
        UnitCollection $units,
        ReferencePriceDto $reference,
        int $quantity = 1
    ): QuantityPriceDefinition {
        $price = $this->getPriceValue($prices$context);

        $taxId = $product->get('taxId');
        $definition = new QuantityPriceDefinition($price$context->buildTaxRules($taxId)$quantity);
        $definition->setReferencePriceDefinition(
            $this->buildReferencePriceDefinition($reference$units)
        );
        $definition->setListPrice(
            $this->getListPrice($prices$context)
        );
        $definition->setRegulationPrice(
            $this->getRegulationPrice($prices$context)
        );

        return $definition;
    }
$last = $mapped[null];
        unset($mapped[null]);

        \ksort($mapped, \SORT_NUMERIC);
        $max = \max(\array_keys($mapped));

        $mapped[$max + 1] = $last;

        $this->prices->clear();

        $rules = $this->context->buildTaxRules($this->product->get('taxId'));

        foreach ($mapped as $quantity => $price) {
            $value = $this->getPriceForTaxState($price$this->context);

            $definition = new QuantityPriceDefinition($value$rules$quantity);

            $this->prices->add(
                $this->priceStubs->calculateQuantity($definition$this->context)
            );
        }
    }

    
Home | Imprint | This part of the site doesn't use cookies.