小编luc*_*rio的帖子

Shopware 6 价格收集器/处理器上的折扣计算错误

我完全按照文档中的描述实现了价格收集器/处理器(https://developer.shopware.com/docs/guides/plugins/plugins/checkout/cart/change-price-of-item)。

\n

出于测试目的,购物车中的每个订单项产品的价格为 100\xe2\x82\xac。

\n

当应用我在管理员中创建的折扣 (10%) 时,折扣将应用于产品的原始价格,而不是实际的新购物车价格。\n我在这里错过了什么?我的 OverwritePriceCollector.php 如下所示:

\n
<?php declare(strict_types=1);\n\nnamespace Test\\TestPlugin\\Core\\Checkout\\Cart;\n\nuse Shopware\\Core\\Checkout\\Cart\\Cart;\nuse Shopware\\Core\\Checkout\\Cart\\CartBehavior;\nuse Shopware\\Core\\Checkout\\Cart\\CartDataCollectorInterface;\nuse Shopware\\Core\\Checkout\\Cart\\CartProcessorInterface;\nuse Shopware\\Core\\Checkout\\Cart\\LineItem\\CartDataCollection;\nuse Shopware\\Core\\Checkout\\Cart\\LineItem\\LineItem;\nuse Shopware\\Core\\Checkout\\Cart\\Price\\AbsolutePriceCalculator;\nuse Shopware\\Core\\Checkout\\Cart\\Price\\PercentagePriceCalculator;\nuse Shopware\\Core\\Checkout\\Cart\\Price\\QuantityPriceCalculator;\nuse Shopware\\Core\\Checkout\\Cart\\Price\\Struct\\AbsolutePriceDefinition;\nuse Shopware\\Core\\Checkout\\Cart\\Price\\Struct\\PercentagePriceDefinition;\nuse Shopware\\Core\\Checkout\\Cart\\Price\\Struct\\QuantityPriceDefinition;\nuse Shopware\\Core\\System\\SalesChannel\\SalesChannelContext;\n\nclass OverwritePriceCollector implements CartDataCollectorInterface, CartProcessorInterface\n{\n    /**\n     * @var QuantityPriceCalculator\n     */\n    private $calculator;\n\n    public function __construct(QuantityPriceCalculator $calculator) {\n        $this->calculator = $calculator;\n    }\n\n    public function collect(CartDataCollection $data, Cart $original, SalesChannelContext $context, CartBehavior $behavior): void\n    {\n        // get all product ids of current cart\n        $productIds = $original->getLineItems()->filterType(LineItem::PRODUCT_LINE_ITEM_TYPE)->getReferenceIds();\n\n        // remove all product ids which are already …
Run Code Online (Sandbox Code Playgroud)

php shopware

2
推荐指数
1
解决办法
868
查看次数

标签 统计

php ×1

shopware ×1