【问题标题】:How to redefine CalculatedPrice in Shopware6?如何在 Shopware 6 中定义计算价格?
【发布时间】: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


    【解决方案1】:

    我认为您需要关注该文档https://docs.shopware.com/en/shopware-platform-dev-en/how-to/cart-change-price

    我还需要实现从外部系统应用自定义价格,我正是根据该文档完成的,因此您需要在购物车处理期间准确设置价格,您可以使用您的 DepositCalculatedPrice 值来完成。

    【讨论】:

    • 但是我不需要改价格!好吧,我也需要这个,但主要是在我的产品行项目中添加存款。
    • 在这种情况下,您可以添加该数据的最佳位置可能是订单项有效负载或扩展,然后您需要将购物车数据映射到订阅 \Shopware\Core\Checkout\Cart\Order\CartConvertedEvent::class 事件的订阅者中的订单数据跨度>
    猜你喜欢
    • 2022-07-01
    • 1970-01-01
    • 2015-03-15
    • 1970-01-01
    • 2022-08-14
    • 1970-01-01
    • 1970-01-01
    • 2022-08-11
    • 1970-01-01
    相关资源
    最近更新 更多