buildRules example

if (!$currency) {
            throw CartException::invalidPriceDefinition();
        }

        $value = $context->getTaxState() === CartPrice::TAX_STATE_GROSS ? $currency->getGross() : $currency->getNet();

        if ($currency->getCurrencyId() !== $context->getCurrencyId()) {
            $value *= $context->getCurrency()->getFactor();
        }

        $taxRules = $this->percentageTaxRuleBuilder->buildRules($prices->sum());

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

        return $this->priceCalculator->calculate($definition$context);
    }
}


require __DIR__.'/vendor/autoload.php';

use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\Finder\Finder;
use Symfony\Component\VarExporter\VarExporter;

Builder::cleanTarget();
$emojisCodePoints = Builder::getEmojisCodePoints();
Builder::saveRules(Builder::buildRules($emojisCodePoints));
Builder::saveRules(Builder::buildStripRules($emojisCodePoints));
Builder::saveRules(Builder::buildGitHubRules($emojisCodePoints));
Builder::saveRules(Builder::buildSlackRules($emojisCodePoints));

final class Builder
{
    private const TARGET_DIR = __DIR__.'/../data/transliterator/emoji/';

    public static function getEmojisCodePoints(): array
    {
        $lines = file(__DIR__.'/vendor/emoji-test.txt');

        

    public function calculate(float $percentage, PriceCollection $prices, SalesChannelContext $context): CalculatedPrice
    {
        $price = $prices->sum();

        $discount = $this->round(
            $price->getTotalPrice() / 100 * $percentage,
            $context
        );

        $rules = $this->percentageTaxRuleBuilder->buildRules($price);

        $definition = new QuantityPriceDefinition($discount$rules, 1);

        return $this->priceCalculator->calculate($definition$context);
    }

    private function round(float $price, SalesChannelContext $context): float
    {
        if ($context->getTaxState() !== CartPrice::TAX_STATE_GROSS && !$context->getItemRounding()->roundForNet()) {
            return $this->rounding->mathRound($price$context->getItemRounding());
        }

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

        if ($manualShippingCost !== null) {
            $price = $manualShippingCost->getTotalPrice();
        } else {
            $price = $this->getCurrencyPrice($priceCollection$context);
        }

        $definition = new QuantityPriceDefinition($price$rules, 1);

        
$taxes->round(
                $this->rounding,
                $context->getItemRounding()
            );

            return $taxes;
        }

        $price = $prices->sum();

        $rules = $this->taxRuleBuilder->buildRules($price);

        if ($context->getTaxState() === CartPrice::TAX_STATE_GROSS) {
            $taxes = $this->taxCalculator->calculateGrossTaxes($price->getTotalPrice()$rules);
        } else {
            $taxes = $this->taxCalculator->calculateNetTaxes($price->getTotalPrice()$rules);
        }

        $taxes->round($this->rounding, $context->getItemRounding());

        return $taxes;
    }
}
/** * @internal */
    public function __construct(
        private readonly QuantityPriceCalculator $priceCalculator,
        private readonly PercentageTaxRuleBuilder $percentageTaxRuleBuilder
    ) {
    }

    public function calculate(float $price, PriceCollection $prices, SalesChannelContext $context, int $quantity = 1): CalculatedPrice
    {
        $taxRules = $this->percentageTaxRuleBuilder->buildRules($prices->sum());

        $definition = new QuantityPriceDefinition($price$taxRules$quantity);

        return $this->priceCalculator->calculate($definition$context);
    }
}
Home | Imprint | This part of the site doesn't use cookies.