randomFloat example

/** * @return list<array<string, mixed>> */
    private function createDiscounts(): array
    {
        $discounts = [];
        $count = $this->faker->randomDigit() / 3;

        for ($i = 0; $i <= $count; ++$i) {
            $scope = $this->faker->randomElement([PromotionDiscountEntity::SCOPE_CART, PromotionDiscountEntity::SCOPE_DELIVERY]);
            $type = $this->faker->randomElement([PromotionDiscountEntity::TYPE_ABSOLUTE, PromotionDiscountEntity::TYPE_PERCENTAGE]);
            $value = $this->faker->randomFloat(2, 0.01, 100);
            if ($type === PromotionDiscountEntity::TYPE_PERCENTAGE || $scope === PromotionDiscountEntity::SCOPE_DELIVERY) {
                $value /= 10;
            }

            $discounts[] = [
                'scope' => $scope,
                'type' => $type,
                'value' => $value,
                'considerAdvancedRules' => false,
            ];
        }

        
$repo->update($updates$context->getContext());
        }
    }

    /** * @return mixed */
    private function randomCustomFieldValue(string $type, Generator $faker)
    {
        return match ($type) {
            CustomFieldTypes::BOOL => (bool) random_int(0, 1),
            CustomFieldTypes::FLOAT => $faker->randomFloat(),
            CustomFieldTypes::INT => random_int(-1000000, 1000000),
            CustomFieldTypes::DATETIME => $faker->dateTime(),
            default => $faker->text(),
        };
    }
}

    private function buildVariants(array $combinations, array $prices, TaxCollection $taxes): array
    {
        $configurator = [];

        $variants = [];
        foreach ($combinations as $options) {
            $price = $this->faker->randomFloat(2, 1, 1000);
            $tax = $taxes->get(array_rand($taxes->getIds()));
            if (!$tax instanceof TaxEntity) {
                continue;
            }
            $taxRate = 1 + ($tax->getTaxRate() / 100);

            $id = Uuid::randomHex();
            $variants[] = [
                'id' => $id,
                'productNumber' => $id,
                'price' => [['currencyId' => Defaults::CURRENCY, 'gross' => $price, 'net' => $price / $taxRate, 'linked' => true]],
                
Home | Imprint | This part of the site doesn't use cookies.