diff --git a/packages/Webkul/Admin/src/Resources/views/sales/orders/view.blade.php b/packages/Webkul/Admin/src/Resources/views/sales/orders/view.blade.php
index 8787b2767..dcf5d8872 100755
--- a/packages/Webkul/Admin/src/Resources/views/sales/orders/view.blade.php
+++ b/packages/Webkul/Admin/src/Resources/views/sales/orders/view.blade.php
@@ -347,9 +347,9 @@
@php ($taxRates = Webkul\Tax\Helpers\Tax::getTaxRatesWithAmount($order, true))
@foreach ($taxRates as $taxRate => $baseTaxAmount)
last ? 'class=border' : ''}}>
- | {{ __('admin::app.sales.orders.tax') }} {{ $taxRate }} % |
+ {{ __('admin::app.sales.orders.tax') }} {{ $taxRate }} % |
- |
- {{ core()->formatBasePrice($baseTaxAmount) }} |
+ {{ core()->formatBasePrice($baseTaxAmount) }} |
@endforeach
diff --git a/packages/Webkul/Core/src/Core.php b/packages/Webkul/Core/src/Core.php
index 963af1b00..832e3c178 100755
--- a/packages/Webkul/Core/src/Core.php
+++ b/packages/Webkul/Core/src/Core.php
@@ -933,4 +933,15 @@ class Core
return $instance[$className] = app($className);
}
+
+ /**
+ * Returns a string as selector part for identifying elements in views
+ * @param float $taxRate
+ *
+ * @return string
+ */
+ public static function taxRateAsIdentifier(float $taxRate): string
+ {
+ return str_replace('.', '_', (string)$taxRate);
+ }
}
\ No newline at end of file
diff --git a/packages/Webkul/Shop/src/Resources/views/checkout/total/summary.blade.php b/packages/Webkul/Shop/src/Resources/views/checkout/total/summary.blade.php
index e492cb91f..76a6b238b 100755
--- a/packages/Webkul/Shop/src/Resources/views/checkout/total/summary.blade.php
+++ b/packages/Webkul/Shop/src/Resources/views/checkout/total/summary.blade.php
@@ -20,8 +20,8 @@
@if ($cart->base_tax_total)
@foreach (Webkul\Tax\Helpers\Tax::getTaxRatesWithAmount($cart, true) as $taxRate => $baseTaxAmount )
-
-
+
+
@endforeach
@endif
diff --git a/packages/Webkul/Shop/src/Resources/views/emails/sales/new-admin-order.blade.php b/packages/Webkul/Shop/src/Resources/views/emails/sales/new-admin-order.blade.php
index 7e077768b..ec6933735 100644
--- a/packages/Webkul/Shop/src/Resources/views/emails/sales/new-admin-order.blade.php
+++ b/packages/Webkul/Shop/src/Resources/views/emails/sales/new-admin-order.blade.php
@@ -163,8 +163,8 @@
@foreach (Webkul\Tax\Helpers\Tax::getTaxRatesWithAmount($order, true) as $taxRate => $baseTaxAmount )
- {{ __('shop::app.mail.order.tax') }} {{ $taxRate }} %
-
+ {{ __('shop::app.mail.order.tax') }} {{ $taxRate }} %
+
{{ core()->formatBasePrice($baseTaxAmount) }}
diff --git a/packages/Webkul/Shop/src/Resources/views/emails/sales/new-invoice.blade.php b/packages/Webkul/Shop/src/Resources/views/emails/sales/new-invoice.blade.php
index b8f70beaa..32a35705f 100755
--- a/packages/Webkul/Shop/src/Resources/views/emails/sales/new-invoice.blade.php
+++ b/packages/Webkul/Shop/src/Resources/views/emails/sales/new-invoice.blade.php
@@ -158,8 +158,8 @@
@foreach (Webkul\Tax\Helpers\Tax::getTaxRatesWithAmount($refund, false) as $taxRate => $taxAmount)
- {{ __('shop::app.mail.order.tax') }} {{ $taxRate }} %
-
+ {{ __('shop::app.mail.order.tax') }} {{ $taxRate }} %
+
{{ core()->formatPrice($taxAmount, $order->order_currency_code) }}
diff --git a/packages/Webkul/Shop/src/Resources/views/emails/sales/new-order.blade.php b/packages/Webkul/Shop/src/Resources/views/emails/sales/new-order.blade.php
index 8089ce37a..a1b58f641 100755
--- a/packages/Webkul/Shop/src/Resources/views/emails/sales/new-order.blade.php
+++ b/packages/Webkul/Shop/src/Resources/views/emails/sales/new-order.blade.php
@@ -158,8 +158,8 @@
@foreach (Webkul\Tax\Helpers\Tax::getTaxRatesWithAmount($order, false) as $taxRate => $taxAmount )
- {{ __('shop::app.mail.order.tax') }} {{ $taxRate }} %
-
+ {{ __('shop::app.mail.order.tax') }} {{ $taxRate }} %
+
{{ core()->formatPrice($taxAmount, $order->order_currency_code) }}
diff --git a/packages/Webkul/Shop/src/Resources/views/emails/sales/order-cancel.blade.php b/packages/Webkul/Shop/src/Resources/views/emails/sales/order-cancel.blade.php
index c3b007370..2b0139e1c 100644
--- a/packages/Webkul/Shop/src/Resources/views/emails/sales/order-cancel.blade.php
+++ b/packages/Webkul/Shop/src/Resources/views/emails/sales/order-cancel.blade.php
@@ -159,8 +159,8 @@
@foreach (Webkul\Tax\Helpers\Tax::getTaxRatesWithAmount($order, false) as $taxRate => $taxAmount )
- {{ __('shop::app.mail.order.cancel.tax') }} {{ $taxRate }} %
-
+ {{ __('shop::app.mail.order.cancel.tax') }} {{ $taxRate }} %
+
{{ core()->formatPrice($taxAmount, $order->order_currency_code) }}
diff --git a/packages/Webkul/Tax/src/Helpers/Tax.php b/packages/Webkul/Tax/src/Helpers/Tax.php
index 908aa8be7..cc10b2baf 100644
--- a/packages/Webkul/Tax/src/Helpers/Tax.php
+++ b/packages/Webkul/Tax/src/Helpers/Tax.php
@@ -29,6 +29,13 @@ class Tax
return $taxes;
}
+ /**
+ * Returns the total tax amount
+ * @param object $that
+ * @param bool $asBase
+ *
+ * @return float
+ */
public static function getTaxTotal(object $that, bool $asBase = false): float
{
$taxes = self::getTaxRatesWithAmount($that, $asBase);
diff --git a/tests/_support/UnitTester.php b/tests/_support/UnitTester.php
index e19544a51..b056dc732 100644
--- a/tests/_support/UnitTester.php
+++ b/tests/_support/UnitTester.php
@@ -1,5 +1,6 @@
comment('I execute function "'
+ . $functionName
+ . '" of class "'
+ . (is_object($className) ? get_class($className) : $className)
+ . '" with '
+ . count($methodParams)
+ . ' method-params, '
+ . count($constructParams)
+ . ' constuctor-params and '
+ . count($mocks)
+ . ' mocked class-methods/params'
+ );
+ $class = new \ReflectionClass($className);
+ $method = $class->getMethod($functionName);
+ $method->setAccessible(true);
+ if (is_object($className)) {
+ $reflectedClass = $className;
+ } elseif (empty($constructParams)) {
+ $reflectedClass = Stub::make($className, $mocks);
+ } else {
+ $reflectedClass = Stub::construct($className, $constructParams, $mocks);
+ }
+
+ return $method->invokeArgs($reflectedClass, $methodParams);
+ }
+}
\ No newline at end of file
diff --git a/tests/functional/Shop/CartCest.php b/tests/functional/Shop/CartCest.php
index 87f9aa131..8381defa2 100644
--- a/tests/functional/Shop/CartCest.php
+++ b/tests/functional/Shop/CartCest.php
@@ -4,6 +4,7 @@ namespace Tests\Functional\Cart;
use FunctionalTester;
use Faker\Factory;
+use Illuminate\Support\Facades\Config;
use Webkul\Tax\Models\TaxMap;
use Webkul\Tax\Models\TaxRate;
use Webkul\Tax\Models\TaxCategory;
@@ -21,15 +22,27 @@ class CartCest
{
$this->faker = Factory::create();
- $this->country = 'DE'; //$this->faker->countryCode;
+ $this->country = Config::get('app.default_country');
- $this->tax1 = $I->have(TaxRate::class, ['tax_rate' => 7.00, 'country' => $this->country]);
+ $this->tax1 = $I->have(TaxRate::class, [
+ //'tax_rate' => 7.00,
+ 'country' => $this->country
+ ]);
$taxCategorie1 = $I->have(TaxCategory::class, []);
- $I->have(TaxMap::class, ['tax_rate_id' => $this->tax1->id, 'tax_category_id' => $taxCategorie1->id]);
+ $I->have(TaxMap::class, [
+ 'tax_rate_id' => $this->tax1->id,
+ 'tax_category_id' => $taxCategorie1->id
+ ]);
- $this->tax2 = $I->have(TaxRate::class, ['tax_rate' => 19.00, 'country' => $this->country]);
+ $this->tax2 = $I->have(TaxRate::class, [
+ //'tax_rate' => 19.00,
+ 'country' => $this->country
+ ]);
$taxCategorie2 = $I->have(TaxCategory::class, []);
- $I->have(TaxMap::class, ['tax_rate_id' => $this->tax2->id, 'tax_category_id' => $taxCategorie2->id]);
+ $I->have(TaxMap::class, [
+ 'tax_rate_id' => $this->tax2->id,
+ 'tax_category_id' => $taxCategorie2->id
+ ]);
$config1 = [
'productInventory' => ['qty' => 100],
@@ -54,7 +67,6 @@ class CartCest
public function checkCartWithMultipleTaxRates(FunctionalTester $I)
{
- $I->setConfigData(['default_country' => $this->country]);
$prod1Quantity = $this->faker->numberBetween(9, 30);
if ($prod1Quantity % 2 !== 0) {
@@ -73,9 +85,9 @@ class CartCest
]);
$I->amOnPage('/checkout/cart');
- $I->see('Tax ' . $this->tax1->tax_rate . ' %', '#taxrate-' . $this->tax1->tax_rate);
- $I->see(round($this->product1->price * $this->tax1->tax_rate / 100, 2),
- '#basetaxamount-' . $this->tax1->tax_rate);
+ $I->see('Tax ' . $this->tax1->tax_rate . ' %', '#taxrate-' . core()->taxRateAsIdentifier($this->tax1->tax_rate));
+ $I->see(core()->currency(round($this->product1->price * $this->tax1->tax_rate / 100, 2)),
+ '#basetaxamount-' . core()->taxRateAsIdentifier($this->tax1->tax_rate));
Cart::addProduct($this->product1->id, [
'_token' => session('_token'),
@@ -84,9 +96,9 @@ class CartCest
]);
$I->amOnPage('/checkout/cart');
- $I->see('Tax ' . $this->tax1->tax_rate . ' %', '#taxrate-' . $this->tax1->tax_rate);
- $I->see(round(($prod1Quantity + 1) * $this->product1->price * $this->tax1->tax_rate / 100, 2),
- '#basetaxamount-' . $this->tax1->tax_rate);
+ $I->see('Tax ' . $this->tax1->tax_rate . ' %', '#taxrate-' . core()->taxRateAsIdentifier($this->tax1->tax_rate));
+ $I->see(core()->currency(round(($prod1Quantity + 1) * $this->product1->price * $this->tax1->tax_rate / 100, 2)),
+ '#basetaxamount-' . core()->taxRateAsIdentifier($this->tax1->tax_rate));
Cart::addProduct($this->product2->id, [
'_token' => session('_token'),
@@ -95,20 +107,18 @@ class CartCest
]);
$I->amOnPage('/checkout/cart');
- $I->see('Tax ' . $this->tax1->tax_rate . ' %', '#taxrate-' . $this->tax1->tax_rate);
+ $I->see('Tax ' . $this->tax1->tax_rate . ' %', '#taxrate-' . core()->taxRateAsIdentifier($this->tax1->tax_rate));
$taxAmount1 = round(($prod1Quantity + 1) * $this->product1->price * $this->tax1->tax_rate / 100, 2);
- $I->see(core()->currency($taxAmount1),'#basetaxamount-' . $this->tax1->tax_rate);
+ $I->see(core()->currency($taxAmount1),'#basetaxamount-' . core()->taxRateAsIdentifier($this->tax1->tax_rate));
- $I->see('Tax ' . $this->tax2->tax_rate . ' %', '#taxrate-' . $this->tax2->tax_rate);
+ $I->see('Tax ' . $this->tax2->tax_rate . ' %', '#taxrate-' . core()->taxRateAsIdentifier($this->tax2->tax_rate));
$taxAmount2 = round($prod2Quantity * $this->product2->price * $this->tax2->tax_rate / 100, 2);
- $I->see(core()->currency($taxAmount2),'#basetaxamount-' . $this->tax2->tax_rate);
+ $I->see(core()->currency($taxAmount2),'#basetaxamount-' . core()->taxRateAsIdentifier($this->tax2->tax_rate));
$cart = Cart::getCart();
$I->assertEquals(2, $cart->items_count);
$I->assertEquals((float)($prod1Quantity + 1 + $prod2Quantity), $cart->items_qty);
$I->assertEquals($taxAmount1 + $taxAmount2, $cart->tax_total);
-
-
}
}
\ No newline at end of file
diff --git a/tests/unit/Core/CoreCest.php b/tests/unit/Core/CoreCest.php
new file mode 100644
index 000000000..25189b907
--- /dev/null
+++ b/tests/unit/Core/CoreCest.php
@@ -0,0 +1,34 @@
+ 0,
+ 'expected' => '0',
+ ],
+ [
+ 'input' => 0.01,
+ 'expected' => '0_01',
+ ],
+ [
+ 'input' => .12,
+ 'expected' => '0_12',
+ ],
+ [
+ 'input' => 1234.5678,
+ 'expected' => '1234_5678',
+ ],
+ ];
+
+ foreach ($scenarios as $scenario) {
+ $I->assertEquals($scenario['expected'], $I->executeFunction(\Webkul\Core\Core::class, 'taxRateAsIdentifier', [$scenario['input']]));
+ }
+ }
+}
diff --git a/tests/unit/Tax/Helpers/TaxCest.php b/tests/unit/Tax/Helpers/TaxCest.php
new file mode 100644
index 000000000..9b8caa20f
--- /dev/null
+++ b/tests/unit/Tax/Helpers/TaxCest.php
@@ -0,0 +1,18 @@
+assertTrue(false);
+ }
+
+ public function testGetTaxTotal(UnitTester $I)
+ {
+ $I->assertTrue(false);
+ }
+}