66use Drupal \commerce_order \Adjustment ;
77use Drupal \commerce_order \Entity \OrderInterface ;
88use Drupal \commerce_order \Entity \OrderItemInterface ;
9- use Drupal \commerce_price \Calculator ;
109use Drupal \commerce_price \RounderInterface ;
1110use Drupal \commerce_store \Entity \StoreInterface ;
1211use Drupal \commerce_tax \TaxZone ;
@@ -147,12 +146,8 @@ public function apply(OrderInterface $order) {
147146 foreach ($ rates as $ zone_id => $ rate ) {
148147 $ zone = $ zones [$ zone_id ];
149148 $ unit_price = $ order_item ->getUnitPrice ();
150- $ percentage = $ rate ->getPercentage ()->getNumber ();
151- $ tax_amount = $ unit_price ->multiply ($ percentage );
152- if ($ prices_include_tax ) {
153- $ divisor = Calculator::add ('1 ' , $ percentage );
154- $ tax_amount = $ tax_amount ->divide ($ divisor );
155- }
149+ $ percentage = $ rate ->getPercentage ();
150+ $ tax_amount = $ percentage ->calculateTaxAmount ($ unit_price , $ prices_include_tax );
156151 if ($ this ->shouldRound ()) {
157152 $ tax_amount = $ this ->rounder ->round ($ tax_amount );
158153 }
@@ -169,7 +164,7 @@ public function apply(OrderInterface $order) {
169164 'type ' => 'tax ' ,
170165 'label ' => $ zone ->getDisplayLabel (),
171166 'amount ' => $ negate ? $ tax_amount ->multiply ('-1 ' ) : $ tax_amount ,
172- 'percentage ' => $ percentage ,
167+ 'percentage ' => $ percentage-> getNumber () ,
173168 'source_id ' => $ this ->entityId . '| ' . $ zone ->getId () . '| ' . $ rate ->getId (),
174169 'included ' => !$ negate && $ this ->isDisplayInclusive (),
175170 ]));
0 commit comments