setTax example

foreach ($creditItems as $creditItem) {
            $creditItem->setUnitPrice($creditItem->getUnitPrice() !== 0.0 ? -$creditItem->getUnitPrice() : 0.0);
            $creditItem->setTotalPrice($creditItem->getTotalPrice() !== 0.0 ? -$creditItem->getTotalPrice() : 0.0);
        }

        $creditItemsCalculatedPrice = $creditItems->getPrices()->sum();
        $totalPrice = $creditItemsCalculatedPrice->getTotalPrice();
        $taxAmount = $creditItemsCalculatedPrice->getCalculatedTaxes()->getAmount();
        $taxes = $creditItemsCalculatedPrice->getCalculatedTaxes();

        foreach ($taxes as $tax) {
            $tax->setTax($tax->getTax() !== 0.0 ? -$tax->getTax() : 0.0);
        }

        if ($order->getPrice()->hasNetPrices()) {
            $price = new CartPrice(
                -$totalPrice,
                -($totalPrice + $taxAmount),
                -$order->getPositionPrice(),
                $taxes,
                $creditItemsCalculatedPrice->getTaxRules(),
                $order->getTaxStatus()
            );
        }
$status = $this->getContainer()->get(ModelManager::class)->find(DetailStatus::class$detail['statusId']);
            if (!$status) {
                throw new NotFoundException(sprintf('DetailStatus by id %s not found', $detail['statusId']));
            }
            $detailModel->setStatus($status);
            unset($detail['statusId']);

            $tax = $this->getContainer()->get(ModelManager::class)->find(Tax::class$detail['taxId']);
            if (!$tax) {
                throw new NotFoundException(sprintf('Tax by id %s not found', $detail['taxId']));
            }
            $detailModel->setTax($tax);
            unset($detail['taxId']);

            // Set shipped flag             if (\array_key_exists('shipped', $detail)) {
                $detailModel->setShipped($detail['shipped']);
            }

            $violations = $this->getManager()->validate($detailModel);
            if ($violations->count() > 0) {
                throw new ValidationException($violations);
            }

            
return $order;
    }

    private function handlePrices(OrderEntity $order): OrderEntity
    {
        foreach ($order->getLineItems() ?? [] as $lineItem) {
            $lineItem->setUnitPrice($lineItem->getUnitPrice() / -1);
            $lineItem->setTotalPrice($lineItem->getTotalPrice() / -1);
        }

        foreach ($order->getPrice()->getCalculatedTaxes()->sortByTax()->getElements() as $tax) {
            $tax->setTax($tax->getTax() / -1);
        }

        $order->setShippingTotal($order->getShippingTotal() / -1);
        $order->setAmountNet($order->getAmountNet() / -1);
        $order->setAmountTotal($order->getAmountTotal() / -1);

        return $order;
    }

    private function getNumber(Context $context, OrderEntity $order, DocumentGenerateOperation $operation): string
    {
        
class StructHelper
{
    public function assignProductData(ListProduct $listProduct, ListProduct $product)
    {
        trigger_error(sprintf('%s:%s is deprecated since Shopware 5.6 and will be removed with 5.7. Will be removed without replacement.', __CLASS__, __METHOD__), E_USER_DEPRECATED);

        $product->setShippingFree($listProduct->isShippingFree());
        $product->setMainVariantId($listProduct->getMainVariantId());
        $product->setAllowsNotification($listProduct->allowsNotification());
        $product->setHighlight($listProduct->highlight());
        $product->setUnit($listProduct->getUnit());
        $product->setTax($listProduct->getTax());
        $product->setPrices($listProduct->getPrices());
        $product->setManufacturer($listProduct->getManufacturer());
        $product->setCover($listProduct->getCover());
        $product->setCheapestPrice($listProduct->getCheapestPrice());
        $product->setName($listProduct->getName());
        $product->setAdditional($listProduct->getAdditional());
        $product->setCloseouts($listProduct->isCloseouts());
        $product->setEan($listProduct->getEan());
        $product->setHeight($listProduct->getHeight());
        $product->setKeywords($listProduct->getKeywords());
        $product->setLength($listProduct->getLength());
        
$calculatedTaxes = $this->taxCalculator->calculateNetTaxes(
            $unitPrice,
            $definition->getTaxRules()
        );

        foreach ($calculatedTaxes as $tax) {
            $total = $this->priceRounding->mathRound(
                $tax->getTax() * $definition->getQuantity(),
                $config
            );
            $tax->setTax($total);
            $tax->setPrice($tax->getPrice() * $definition->getQuantity());
        }

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

        $reference = $this->calculateReferencePrice($unitPrice$definition->getReferencePriceDefinition()$config);

        return new CalculatedPrice(
            
public function testCalculateByFixedTaxRate(): void
    {
        $shippingMethod = new ShippingMethodEntity();
        $shippingMethod->setId(Uuid::randomHex());
        $shippingMethod->setDeliveryTime($this->deliveryTimeEntity);
        $shippingMethod->setName(Uuid::randomHex());
        $shippingMethod->setTaxType(ShippingMethodEntity::TAX_TYPE_FIXED);

        $taxRate = 10;

        $shippingMethod->setTax((new TaxEntity())->assign([
            'id' => Uuid::randomHex(),
            'name' => 'Test',
            'taxRate' => $taxRate,
        ]));

        $price = new ShippingMethodPriceEntity();
        $price->setUniqueIdentifier(Uuid::randomHex());
        $price->setCurrencyPrice(new PriceCollection(
            [
                new Price(
                    Defaults::CURRENCY,
                    
$data = $this->prepareSeoCategoryAssociatedData($data$article);

        $data = $this->prepareRelatedAssociatedData($data$article);
        $data = $this->prepareSimilarAssociatedData($data$article);
        $data = $this->prepareAvoidCustomerGroups($data$article);
        $data = $this->preparePropertyValuesData($data$article);
        $data = $this->prepareDownloadsAssociatedData($data$article);
        $data = $this->prepareConfiguratorSet($data$article);

        // Need to set the tax data directly for following price calculations which use the tax object of the article         if (isset($data['tax'])) {
            $article->setTax($data['tax']);
        }

        if (isset($data['configuratorSet'])) {
            $article->setConfiguratorSet($data['configuratorSet']);
        }

        $data = $this->prepareImageAssociatedData($data$article);
        $data = $this->prepareAttributeAssociatedData($data$article);

        // The mainDetail gets its initial value for lastStock from $article, so this has to be set beforehand         if (isset($data['lastStock'])) {
            

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

        $reference = $this->calculateReferencePrice($unitPrice$definition->getReferencePriceDefinition()$config);

        


            $exists->increment($calculatedTax);
        }

        return $new;
    }

    public function round(CashRounding $rounding, CashRoundingConfig $config): void
    {
        foreach ($this->elements as $tax) {
            $tax->setTax(
                $rounding->mathRound($tax->getTax()$config)
            );
        }
    }

    public function getApiAlias(): string
    {
        return 'cart_tax_calculated_collection';
    }

    protected function getExpectedClass(): ?string
    {

    public function hydrate(array $data)
    {
        $tax = new Tax();

        $tax->setId((int) $data['__tax_id']);
        $tax->setName($data['__tax_description']);
        $tax->setTax((float) $data['__tax_tax']);

        return $tax;
    }

    /** * Creates a new tax struct and assigns the passed * data array. * * @return Tax */
    public function hydrateRule(array $data)
    {
'txtpackunit' => '__unit_packunit',
        ]);
    }

    private function assignData(ListProduct $product, array $data): ListProduct
    {
        $translation = $this->getProductTranslation($data);
        $data = array_merge($data$translation);

        $this->assignProductData($product$data);

        $product->setTax(
            $this->taxHydrator->hydrate($data)
        );

        $this->assignPriceGroupData($product$data);

        if ($data['__product_supplierID']) {
            $product->setManufacturer(
                $this->manufacturerHydrator->hydrate($data)
            );
        }

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