【发布时间】:2021-02-25 11:32:55
【问题描述】:
我正在尝试在 Shopware6 中编写插件,它必须向产品行项目添加一些自定义值(如存款)。所以我写了我的课
class DepositCalculatedPrice extends CalculatedPrice
{
/** @var float $deposit */
protected $deposit;
public function __construct(
float $unitPrice,
float $totalPrice,
CalculatedTaxCollection $calculatedTaxes,
CalculatedTaxCollection $calculatedTaxesNoDeposit,
TaxRuleCollection $taxRules,
int $quantity = 1,
?ReferencePrice $referencePrice = null,
?ListPrice $listPrice = null,
float $deposit = 0,
) {
parent::__construct(
$unitPrice,
$totalPrice,
$calculatedTaxes,
$taxRules,
$quantity,
$referencePrice,
$listPrice
);
$this->deposit = $deposit;
}
public function getDeposit(): float
{
return FloatComparator::cast($this->deposit);
}
}
然后我在我的计算器中使用它,然后在我的 PriceProcessor 中使用它。一切顺利,直到我尝试提交我的订单,但 Shopware6 检查 Checkout/Order/Aggregate/OrderLineItem/OrderLineItemDefinition.php 中的字段定义类,并根据 CalculatedPrice 而非 DepositCalculatedPrice 检查 Price json 字段。
那么有没有办法解决呢?也许我可以在某个地方使用OrderLineItemDefinition.php 的一些后代?还是让它不检查字段定义?
【问题讨论】:
标签: custom-fields calculated-field shopware