我正在尝试在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的Price json字段,而不是DepositCalculatedPrice。那么有没有办法解决这个问题呢?也许我可以在某个地方用到OrderLineItemDefinition.php的后代?或者让它不检查字段定义?
发布于 2021-02-25 20:19:11
我认为你需要遵循那个文档https://docs.shopware.com/en/shopware-platform-dev-en/how-to/cart-change-price
我还需要从外部系统实现自定义价格应用,并且我确实是根据该文档进行的,因此您需要在购物车处理过程中准确设置价格,您可以使用DepositCalculatedPrice值进行设置。
https://stackoverflow.com/questions/66367676
复制相似问题