getTax example

return $this->setOneToOne($attribute, CustomerGroup::class, 'attribute', 'customerGroup');
    }

    /** * @return array */
    public function toArray()
    {
        return [
            'id' => $this->getId(),
            'key' => $this->getKey(),
            'tax' => $this->getTax(),
            'mode' => $this->getMode(),
            'minimumorder' => $this->getMinimumOrder(),
            'minimumordersurcharge' => $this->getMinimumOrderSurcharge(),
            'basketdiscount' => $this->getDiscount(),
        ];
    }
}
static::assertCount(2, $taxes);
        static::assertArrayHasKey(20, $taxes);
        static::assertArrayHasKey(10, $taxes);

        static::assertEquals(20, $taxes[20]->getTaxRate());
        static::assertEquals(10, $taxes[10]->getTaxRate());

        static::assertEquals(50, $taxes[20]->getPrice());
        static::assertEquals(50, $taxes[10]->getPrice());

        static::assertEquals(10, $taxes[20]->getTax());
        static::assertEquals(5, $taxes[10]->getTax());
    }
}
$field['value'] = $this->dqlHelper->formatValue($prefix$field$field['value']);

                    $setter = 'set' . ucfirst($field['field']);
                    $model->$setter($field['value']);
                }
                $entityManager->persist($model);
                // price_model             } else {
                $detailModel = $entityManager->find(Detail::class$primaryIdentifiers['detail']);
                // store net prices                 $tax = (float) $detailModel->getArticle()->getTax()->getTax() / 100 + 1;
                $priceModel = $entityManager->getRepository($entity)->findOneBy(
                    ['articleDetailsId' => $detailModel->getId(), 'customerGroupKey' => 'EK', 'from' => 1]
                );
                if ($priceModel === null) {
                    continue;
                }

                foreach ($fields as $field) {
                    // Do not persist non-editable fields                     $fieldInfo = $columnInfo[ucfirst($prefix) . ucfirst($field['field'])];
                    if (!$fieldInfo['editable']) {
                        
static::assertEquals(50, $cart->getPrice()->getPositionPrice());
        static::assertEquals(41.66, $cart->getPrice()->getNetPrice());

        $promotion = $cart->getLineItems()->getElements();
        $promotion = array_values($promotion)[1];

        static::assertInstanceOf(LineItem::class$promotion);
        $price = $promotion->getPrice();
        static::assertInstanceOf(CalculatedPrice::class$price);
        static::assertEquals(-50, $price->getTotalPrice());
        static::assertNotNull($price->getCalculatedTaxes()->first());
        static::assertEquals(-8.33, $price->getCalculatedTaxes()->first()->getTax());
    }

    /** * This test verifies that we can set a * maximum absolute value for a percentage discount. * We have a 100 EUR product and 50% OFF but a maximum * of 30 EUR discount. This means our cart should be minimum 70 EUR in the end. * We have * * @group promotions */
    
$taxes = [];

            if ($this->_order['taxfree']) {
                $this->_amountNetto += $this->_order['invoice_shipping'];
            } else {
                if ($this->_order['is_proportional_calculation']) {
                    $taxes = Shopware()->Container()->get('shopware.cart.proportional_tax_calculator')->calculate($this->_order['invoice_shipping']$this->getPricePositions(), false);
                    $taxNet = 0;

                    foreach ($taxes as $tax) {
                        $taxNet += $tax->getNetPrice();
                        $this->_tax[number_format($tax->getTaxRate(), 2)] += $tax->getTax();
                    }

                    $this->_amountNetto += $taxNet;
                } else {
                    $this->_amountNetto += ($this->_order['invoice_shipping'] / (100 + $taxShipping) * 100);

                    if (!empty($taxShipping) && !empty($this->_order['invoice_shipping'])) {
                        $shippingTax = Shopware()->Container()->get(TaxAggregatorInterface::class)->shippingCostsTaxSum([
                            CheckoutKey::SHIPPING_COSTS_TAX => (float) $this->_order['invoice_shipping_tax_rate'],
                            CheckoutKey::SHIPPING_COSTS_NET => (float) $this->_order['invoice_shipping_net'],
                            CheckoutKey::SHIPPING_COSTS_WITH_TAX => (float) $this->_order['invoice_shipping'],
                        ]);
$result = [];

        if (!empty($cart[CheckoutKey::SHIPPING_COSTS_TAX_PROPORTIONAL])) {
            $callback = static function Darray $carry, Price $shippingTax) {
                $taxRate = number_format($shippingTax->getTaxRate(), 2);

                if (!\array_key_exists($taxRate$carry)) {
                    $carry[$taxRate] = 0.0;
                }

                $carry[$taxRate] += $shippingTax->getTax();

                return $carry;
            };

            $result = array_reduce($cart[CheckoutKey::SHIPPING_COSTS_TAX_PROPORTIONAL]$callback[]);
        } else {
            $taxRate = number_format((float) $cart[CheckoutKey::SHIPPING_COSTS_TAX], 2);

            $result[$taxRate] = $cart[CheckoutKey::SHIPPING_COSTS_WITH_TAX] - $cart[CheckoutKey::SHIPPING_COSTS_NET];

            if (empty($result[$taxRate])) {
                
 {
    }

    public function calculate(QuantityPriceDefinition $definition, CashRoundingConfig $config): CalculatedPrice
    {
        $unitPrice = $this->getUnitPrice($definition$config);

        $unitTaxes = $this->taxCalculator->calculateGrossTaxes($unitPrice$definition->getTaxRules());

        foreach ($unitTaxes as $tax) {
            $total = $this->priceRounding->mathRound(
                $tax->getTax() * $definition->getQuantity(),
                $config
            );

            $tax->setTax($total);

            $tax->setPrice($tax->getPrice() * $definition->getQuantity());
        }

        $price = $this->priceRounding->cashRound(
            $unitPrice * $definition->getQuantity(),
            $config
        );


    private function calculateShippingCosts(ShippingMethodEntity $shippingMethod, PriceCollection $priceCollection, LineItemCollection $calculatedLineItems, SalesChannelContext $context, ?CalculatedPrice $manualShippingCost = null): CalculatedPrice
    {
        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()
                );
'queryBuilder' => $qb,
            ]
        );

        $maxTaxId = $qb->execute()->fetchOne();
        if (!$maxTaxId) {
            return false;
        }

        $tax = $this->contextService->getShopContext()->getTaxRule($maxTaxId);

        return $tax->getTax();
    }

    /** * Add voucher to cart * Used in several places * * @param string $voucherCode Voucher code * @param string $basket * * @throws \Exception * @throws \Enlight_Exception * @throws \Enlight_Event_Exception * @throws \Zend_Db_Adapter_Exception * * @return array|bool True if successful, false if stopped by an event, array with error data if one occurred */

        $this->priceCalculatorService = $priceCalculatorService;
    }

    /** * {@inheritdoc} */
    public function calculateProduct(
        ListProduct $product,
        ShopContextInterface $context
    ) {
        $tax = $context->getTaxRule($product->getTax()->getId());
        if (!$tax instanceof Tax) {
            throw new StructNotFoundException(Tax::class$product->getTax()->getId());
        }

        $rules = $product->getPriceRules();

        $prices = [];
        foreach ($rules as $rule) {
            $prices[] = $this->calculatePriceStruct($rule$tax$context);
        }

        
class TaxProviderPersister
{
    /** * @internal */
    public function __construct(private readonly EntityRepository $taxProviderRepository)
    {
    }

    public function updateTaxProviders(Manifest $manifest, string $appId, string $defaultLocale, Context $context): void
    {
        $tax = $manifest->getTax();

        if (!$tax) {
            return;
        }

        $taxProviders = $tax->getTaxProviders();

        if (!$taxProviders) {
            return;
        }

        

    protected function prepareData(array $data, ProductModel $article, Detail $variant)
    {
        $data = $this->prepareUnitAssociation($data);

        if (!empty($data['prices'])) {
            $data['prices'] = $this->preparePriceAssociation(
                $data,
                $article,
                $variant,
                $article->getTax()
            );
        }

        if (isset($data['purchasePrice']) && \is_string($data['purchasePrice'])) {
            $data['purchasePrice'] = (float) str_replace(',', '.', $data['purchasePrice']);
        }

        $data = $this->prepareAttributeAssociation($data$article$variant);

        if (isset($data['configuratorOptions'])) {
            $data = $this->prepareConfigurator($data$article$variant);
        }


        static::assertInstanceOf(TaxProviderResponse::class$taxResponse);

        $lineItemTaxes = $taxResponse->getLineItemTaxes();
        static::assertNotNull($lineItemTaxes);
        static::assertArrayHasKey($this->ids->get('line-item-1')$lineItemTaxes);
        $taxes = $lineItemTaxes[$this->ids->get('line-item-1')];
        $tax = $taxes->first();
        static::assertInstanceOf(CalculatedTax::class$tax);
        static::assertCount(1, $taxes);
        static::assertSame(19.0, $tax->getTax());
        static::assertSame(19.0, $tax->getTaxRate());
        static::assertSame(100.0, $tax->getPrice());

        $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());
        

    private function getListProductData(ListProduct $product): array
    {
        $createDate = null;
        if ($product->getCreatedAt()) {
            $createDate = $product->getCreatedAt()->format('Y-m-d');
        }
        $updateDate = null;
        if ($product->getUpdatedAt()) {
            $updateDate = $product->getUpdatedAt()->format('Y-m-d');
        }
        $tax = $product->getTax();
        $taxRule = $this->contextService->getShopContext()->getTaxRule($product->getTax()->getId());
        if ($taxRule instanceof Tax) {
            $tax = $taxRule;
        }

        $data = [
            'articleID' => $product->getId(),
            'articleDetailsID' => $product->getVariantId(),
            'ordernumber' => $product->getNumber(),
            'highlight' => $product->highlight(),
            'description' => $product->getShortDescription(),
            
private function checkTaxRule(array $data, ShopContextInterface $shopContext): array
    {
        $taxId = $data['taxId'];
        if (empty($taxId)) {
            unset($data['tax']);

            return $data;
        }
        $tax = $this->getManager()->find(Tax::class$taxId);
        if ($tax instanceof Tax) {
            $data['tax'] = $tax;
            $data['taxRate'] = (float) $tax->getTax();
        }

        $taxRule = $shopContext->getTaxRule($taxId);
        if ($taxRule instanceof TaxStruct) {
            $data['taxRate'] = (float) $taxRule->getTax();
        }

        return $data;
    }

    private function hasProductGraduatedPrices(string $productNumber, Order $order): bool
    {
Home | Imprint | This part of the site doesn't use cookies.