首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在Shopware6中重新定义CalculatedPrice?

如何在Shopware6中重新定义CalculatedPrice?
EN

Stack Overflow用户
提问于 2021-02-25 19:32:56
回答 1查看 55关注 0票数 1

我正在尝试在Shopware6中编写插件,它必须添加一些自定义的值(如存款)到产品线项目。所以我写了我的类

代码语言:javascript
复制
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的后代?或者让它不检查字段定义?

EN

回答 1

Stack Overflow用户

发布于 2021-02-25 20:19:11

我认为你需要遵循那个文档https://docs.shopware.com/en/shopware-platform-dev-en/how-to/cart-change-price

我还需要从外部系统实现自定义价格应用,并且我确实是根据该文档进行的,因此您需要在购物车处理过程中准确设置价格,您可以使用DepositCalculatedPrice值进行设置。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/66367676

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档