我需要数小数位(税,促销,费用.),但总价格必须在数学上四舍五入,没有小数。
示例:2 x product1 CZK 424.00 1 x Product2 CZK 408.00
CZK 832.00船运CZK 99.00折扣CZK -41.60 10%增值税71.86 21%增值税17.18 -Total CZK 889.40-删除圆角CZK - 0.60不需要显示总计CZK 889.00
发布于 2020-09-11 14:22:45
这解决了我的问题:https://www.drupal.org/project/commerce/issues/3076196
roundingmodule.info
name: Commerce rounding module.
type: module
description: Rounding.
core: 8.x
package: Customroundingmodule.services.yml
services:
roundingmodule.rounding_order_processor:
class: Drupal\roundingmodule\RoundingOrderProcessor
tags:
- { name: commerce_order.order_processor, priority: -10 }roundingmodule.commerce_adjustment_types.yml
rounding:
label: 'Rounding'
singular_label: 'rounding adjustment'
plural_label: 'rounding adjustments'
has_ui: true
weight: 20src/RoundingOrderProcessor.php
getTotalPrice();
$rounded_total = $rounder->round($order_total->divide(100))->multiply(100);
$difference = $rounded_total->subtract($order_total);
$order->addAdjustment(new Adjustment([
'type' => 'rounding',
'label' => 'Rounding',
'amount' => $difference,
]));
}
}https://drupal.stackexchange.com/questions/296651
复制相似问题