You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Shopware产品Feed中导出净价/不含VAT价格

Shopware 6产品Feed导出净价的方法

方法1:通过自定义插件扩展变量

你可以开发一个轻量插件,给Feed导出添加净价变量:

  • 监听FeedExportCollectorEvent事件,在事件处理中获取产品的价格数据
  • 从产品价格对象中提取净价(net字段),注册为自定义变量(比如{{ product.netPrice }})
  • 之后就能在Feed模板里直接调用这个变量导出净价

核心代码示例:

public function onFeedExportCollector(FeedExportCollectorEvent $event): void
{
    $product = $event->getEntity();
    if (!$product instanceof ProductEntity) {
        return;
    }
    
    $defaultPrice = $product->getPrice()->first();
    if ($defaultPrice) {
        $event->addVariable('netPrice', $defaultPrice->getNet());
    }
}

方法2:在Feed模板中直接计算净价

如果不想开发插件,可在Twig模板里通过现有价格字段反向计算:

{% set grossPrice = product.price.first.gross %}
{% set taxRate = product.price.first.taxRate %}
{% set netPrice = grossPrice / (1 + taxRate / 100) %}
{{ netPrice|number_format(2, '.', '') }}

注意:该方法需要产品价格配置中包含税率信息,否则无法计算。

方法3:调用内置价格渲染器获取净价

利用Shopware内置的价格服务,自动适配销售渠道税率计算净价:

{% set priceContext = service('shopware.core.system.sales_channel.context.sales_channel_context_resolver').resolve(product.salesChannelId) %}
{% set netPrice = service('shopware.core.system.price.price_renderer').render(product.price, priceContext, net=true) %}
{{ netPrice }}

内容的提问来源于stack exchange,提问作者Michael_sfx

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.05 21:46:09