discountTypeNotSupported example

private function buildDiscountDefinition(string $type$value, string $key): PriceDefinitionInterface
    {
        if ($type === PercentagePriceDefinition::TYPE) {
            if ($value instanceof PriceCollection) {
                throw CartException::invalidPercentageDiscount($key);
            }
            $value = FloatComparator::cast((float) $value);

            return new PercentagePriceDefinition(abs($value) * -1);
        }
        if ($type !== AbsolutePriceDefinition::TYPE) {
            throw CartException::discountTypeNotSupported($key$type);
        }
        if (!$value instanceof PriceCollection) {
            throw CartException::absoluteDiscountMissingPriceCollection($key);
        }
        if (!$value->has(Defaults::CURRENCY)) {
            throw CartException::missingDefaultPriceCollectionForDiscount($key);
        }

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

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