Support multiple price rules

This commit is contained in:
Daniel Siepmann 2021-08-31 14:01:07 +02:00
parent 592269baa8
commit 07f189a7f8
4 changed files with 26 additions and 15 deletions

View file

@ -45,9 +45,9 @@ class PriceSpecification extends Minimum
* E.g. 'PerPerson'
* ThueCat specific property.
*
* @var string
* @var array
*/
protected $calculationRule = '';
protected $calculationRules = [];
public function getPrice(): float
{
@ -59,9 +59,12 @@ class PriceSpecification extends Minimum
return $this->currency;
}
public function getCalculationRule(): string
/**
* @return string[]
*/
public function getCalculationRules(): array
{
return $this->calculationRule;
return $this->calculationRules;
}
/**
@ -82,9 +85,13 @@ class PriceSpecification extends Minimum
/**
* @internal for mapping via Symfony component.
* @param string|array $calculationRule
*/
public function setCalculationRule(string $calculationRule): void
public function setCalculationRule($calculationRule): void
{
$this->calculationRule = PropertyValues::removePrefixFromEntry($calculationRule);
if (is_string($calculationRule)) {
$calculationRule = [$calculationRule];
}
$this->calculationRules = PropertyValues::removePrefixFromEntries($calculationRule);
}
}

View file

@ -401,7 +401,7 @@ class GeneralConverter implements Converter
'description' => $priceSpecification->getDescription(),
'price' => $priceSpecification->getPrice(),
'currency' => $priceSpecification->getCurrency(),
'rule' => $priceSpecification->getCalculationRule(),
'rule' => implode(',', $priceSpecification->getCalculationRules()),
];
}

View file

@ -23,6 +23,8 @@ declare(strict_types=1);
namespace WerkraumMedia\ThueCat\Domain\Model\Frontend;
use TYPO3\CMS\Core\Utility\GeneralUtility;
class Price
{
/**
@ -46,22 +48,22 @@ class Price
private $currency;
/**
* @var string
* @var string[]
*/
private $rule;
private $rules;
private function __construct(
string $title,
string $description,
float $price,
string $currency,
string $rule
array $rules
) {
$this->title = $title;
$this->description = $description;
$this->price = $price;
$this->currency = $currency;
$this->rule = $rule;
$this->rules = $rules;
}
/**
@ -74,7 +76,7 @@ class Price
$rawData['description'],
$rawData['price'],
$rawData['currency'],
$rawData['rule']
GeneralUtility::trimExplode(',', $rawData['rule'], true)
);
}
@ -98,8 +100,8 @@ class Price
return $this->currency;
}
public function getRule(): string
public function getRules(): array
{
return $this->rule;
return $this->rules;
}
}

View file

@ -35,7 +35,9 @@
<p>{price.description}</p>
</f:if>
{price.price -> f:format.currency(decimalSeparator: ',', thousandsSeparator: '.', decimals: 2, currencySign: price.currency)}
{f:translate(id: 'content.price.rule.{price.rule}', default: price.rule, extensionName: 'Thuecat')}
<f:for each="{price.rules}" as="rule">
{f:translate(id: 'content.price.rule.{rule}', default: rule, extensionName: 'Thuecat')}
</f:for>
</f:for>
</f:for>
</f:if>