CurrencyPriceDefinition example

foreach ($value as $price) {
            $price->setGross(\abs($price->getGross()));
            $price->setNet(\abs($price->getNet()));

            if (!$price->getListPrice()) {
                continue;
            }
            $price->getListPrice()->setGross(\abs($price->getListPrice()->getGross()));
            $price->getListPrice()->setNet(\abs($price->getListPrice()->getNet()));
        }

        return new CurrencyPriceDefinition($value);
    }
}
$rules = (\array_key_exists('filter', $decoded) && $decoded['filter'] !== null) ? $this->decodeRule($decoded['filter']) : null;

                return new AbsolutePriceDefinition($decoded['price']$rules);
            case CurrencyPriceDefinition::TYPE:
                $rules = (\array_key_exists('filter', $decoded) && $decoded['filter'] !== null) ? $this->decodeRule($decoded['filter']) : null;

                $collection = new PriceCollection();
                foreach ($decoded['price'] as $price) {
                    $collection->add(new Price($price['currencyId'](float) $price['net'](float) $price['gross'](bool) $price['linked']));
                }

                return new CurrencyPriceDefinition($collection$rules);
            case PercentagePriceDefinition::TYPE:
                $rules = \array_key_exists('filter', $decoded) && $decoded['filter'] !== null ? $this->decodeRule($decoded['filter']) : null;

                return new PercentagePriceDefinition($decoded['percentage']$rules);
        }

        throw new InvalidPriceFieldTypeException($decoded['type']);
    }

    private function validateRules(array $data, string $basePath): ConstraintViolationList
    {
        

#[Package('checkout')] class AbsoluteItem extends LineItem
{
    public function __construct(
        float $price,
        ?string $id = null
    ) {
        parent::__construct($id ?? Uuid::randomHex(), LineItem::DISCOUNT_LINE_ITEM);

        $this->priceDefinition = new CurrencyPriceDefinition(new PriceCollection([
            new Price(Defaults::CURRENCY, $price$price, false),
        ]));
        $this->removable = true;
    }
}


        yield 'Test absolute price definition' => [
            new AbsolutePriceDefinition(20, $rule),
        ];

        yield 'Test percentage price definition' => [
            new PercentagePriceDefinition(-20, $rule),
        ];

        yield 'Test currency price definition' => [
            new CurrencyPriceDefinition(new PriceCollection([
                new Price(Defaults::CURRENCY, 100, 200, false),
                new Price(Uuid::randomHex(), 200, 300, true),
            ])$rule),
        ];

        $customFieldsRule = new LineItemCustomFieldRule(
            LineItemCustomFieldRule::OPERATOR_EQ,
            ['name' => 'foobar', 'type' => CustomFieldTypes::BOOL]
        );
        $customFieldsRule->assign([
            'selectedField' => 'foo',
            
foreach ($value as $price) {
            $price->setGross(\abs($price->getGross()) * -1);
            $price->setNet(\abs($price->getNet()) * -1);

            if (!$price->getListPrice()) {
                continue;
            }
            $price->getListPrice()->setGross(\abs($price->getListPrice()->getGross()) * -1);
            $price->getListPrice()->setNet(\abs($price->getListPrice()->getNet()) * -1);
        }

        return new CurrencyPriceDefinition($value);
    }
}
Home | Imprint | This part of the site doesn't use cookies.