Resolved conflicts

This commit is contained in:
Jitendra Singh 2020-02-21 19:36:17 +05:30
commit 5c696f8d00
62 changed files with 1589 additions and 666 deletions

View File

@ -19,7 +19,7 @@ DB_PREFIX=
BROADCAST_DRIVER=log
CACHE_DRIVER=file
SESSION_DRIVER=file
SESSION_LIFETIME=20
SESSION_LIFETIME=120
QUEUE_DRIVER=sync
REDIS_HOST=127.0.0.1

View File

@ -2,7 +2,7 @@
#### This changelog consists the bug & security fixes and new features being included in the releases listed below.
## **v1.0.0-BETA2(13th of February 2020)** - *Release*
## **v1.0.0 (21st of February 2020)** - *Release*
* #2377 [fixed] - Getting exception on creating a new category under any other category.
@ -48,10 +48,44 @@
* #2439 [fixed] - can't process for further checkout steps until all the address line filled.
* #2435 [fixed] - error composer install --no-dev.
* #2440 [fixed] - Advertisement Three Images is not working.
* #2449 [fixed] - error clicking empty cart.
* #2458 [fixed] - Payment method is not updating on checkout page.
* #2459 [fixed] - shipping address field warning for guest customer not translated.
* #2463 [fixed] - Tax rate is not update on same product.
* #2468 [fixed] - Guest user is able to checkout if guest checkout is disabled.
* #2469 [fixed] - Displaying wrong amount for bundle product in cart.
* #2479 [fixed] - showing total review in recent view product list.
* #2480 [fixed] - Exception is thrown by mini cart when catalog rule is applied on configurable product.
* #2488 [fixed] - ErrorException When Editing product in different language.
* #2490 [fixed] - missing zip code & country field in checkout page.
* #2491 [fixed] - Exception on Create/Edit bundle product.
* #2494 [fixed] - Product total inventory for all locale is showing wrong.
* #2500 [fixed] - Database reset fails.
* #2519 [fixed] - filter price attribute throwing an exception.
* #2526 [fixed] - Velocity backend route is not accessible in arabic locale.
* #2533 [fixed] - Shipment email notification is not sending to customer.
* #2538 [fixed] - unable to place order for virtual & downloadable product.
## **v1.0.0-BETA1(5th of February 2020)** - *Release*
* [feature] Updated to laravel version 6.

View File

@ -15,6 +15,8 @@ printf "### start preparation ###\n"
printf ">> truncate and migrate database\n"
php artisan migrate:fresh --env=testing --quiet
printf ">> cleaning previous tests ###\n"
${WORKPATH}/../vendor/bin/codecept clean
printf "### finish preparation ###\n"
printf "### start tests ###\n"

View File

@ -33,17 +33,17 @@
"maatwebsite/excel": "3.1.18",
"nwidart/laravel-modules": "^3.2",
"prettus/l5-repository": "^2.6",
"tymon/jwt-auth": "^1.0.0"
"tymon/jwt-auth": "^1.0.0",
"barryvdh/laravel-debugbar": "^3.1",
"fzaninotto/faker": "^1.4"
},
"require-dev": {
"barryvdh/laravel-debugbar": "^3.1",
"codeception/codeception": "^4.0",
"codeception/module-asserts": "^1.1",
"codeception/module-filesystem": "^1.0",
"codeception/module-laravel5": "^1.0",
"filp/whoops": "^2.0",
"fzaninotto/faker": "^1.4",
"laravel/dusk": "^5.7.0",
"mockery/mockery": "^1.0",
"nunomaduro/collision": "^2.0",

831
composer.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -102,6 +102,8 @@ return [
| Ensure it is uppercase and reflects the 'code' column of the
| countries table.
|
| for example: DE EN FR
| (use capital letters!)
*/
'default_country' => null,

View File

@ -98,6 +98,10 @@ class CartController extends Controller
*/
public function store($id)
{
if (request()->get('is_buy_now')) {
Event::dispatch('shop.item.buy-now', $id);
}
Event::dispatch('checkout.cart.item.add.before', $id);
$result = Cart::addProduct($id, request()->except('_token'));
@ -229,4 +233,4 @@ class CartController extends Controller
'data' => $cart ? new CartResource($cart) : null
]);
}
}
}

View File

@ -16,6 +16,12 @@ class Cart extends JsonResource
*/
public function toArray($request)
{
$taxes = \Webkul\Tax\Helpers\Tax::getTaxRatesWithAmount($this, false);
$baseTaxes = \Webkul\Tax\Helpers\Tax::getTaxRatesWithAmount($this, true);
$formatedTaxes = $this->formatTaxAmounts($taxes, false);
$formatedBaseTaxes = $this->formatTaxAmounts($baseTaxes, true);
return [
'id' => $this->id,
'customer_email' => $this->customer_email,
@ -60,6 +66,31 @@ class Cart extends JsonResource
'shipping_address' => new CartAddress($this->shipping_address),
'created_at' => $this->created_at,
'updated_at' => $this->updated_at,
'taxes' => json_encode($taxes, JSON_FORCE_OBJECT),
'formated_taxes' => json_encode($formatedTaxes, JSON_FORCE_OBJECT),
'base_taxes' => json_encode($baseTaxes, JSON_FORCE_OBJECT),
'formated_base_taxes' => json_encode($formatedBaseTaxes, JSON_FORCE_OBJECT),
];
}
/**
* @param array $taxes
* @param bool $isBase
*
* @return array
*/
private function formatTaxAmounts(array $taxes, bool $isBase = false): array
{
$result = [];
foreach ($taxes as $taxRate => $taxAmount) {
if ($isBase === true) {
$result[$taxRate] = core()->formatBasePrice($taxAmount);
} else {
$result[$taxRate] = core()->formatPrice($taxAmount, $this->cart_currency_code);
}
}
return $result;
}
}

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,39 @@
/*!
* Sizzle CSS Selector Engine v2.3.4
* https://sizzlejs.com/
*
* Copyright JS Foundation and other contributors
* Released under the MIT license
* https://js.foundation/
*
* Date: 2019-04-08
*/
/*!
* Vue.js v2.6.11
* (c) 2014-2019 Evan You
* Released under the MIT License.
*/
/*!
* jQuery JavaScript Library v3.4.1
* https://jquery.com/
*
* Includes Sizzle.js
* https://sizzlejs.com/
*
* Copyright JS Foundation and other contributors
* Released under the MIT license
* https://jquery.org/license
*
* Date: 2019-05-01T21:04Z
*/
/**
* @license
* Lodash <https://lodash.com/>
* Copyright OpenJS Foundation and other contributors <https://openjsf.org/>
* Released under MIT license <https://lodash.com/license>
* Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
* Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
*/

View File

@ -1,4 +1,4 @@
{
"/js/admin.js": "/js/admin.js?id=8c0724bfd64081ee94bf",
"/css/admin.css": "/css/admin.css?id=51bad88a58200b49c06a"
"/js/admin.js": "/js/admin.js?id=c7c2ef0a298910b82304",
"/css/admin.css": "/css/admin.css?id=f2c6fe51889bca1fb79d"
}

View File

@ -408,9 +408,13 @@ Route::group(['middleware' => ['web']], function () {
//delete backend user
Route::post('/users/delete/{id}', 'Webkul\User\Http\Controllers\UserController@destroy')->name('admin.users.delete');
Route::post('/confirm/destroy', 'Webkul\User\Http\Controllers\UserController@destroySelf')->defaults('_config', [
Route::get('/users/confirm/{id}', 'Webkul\User\Http\Controllers\UserController@confirm')->defaults('_config', [
'view' => 'admin::customers.confirm-password'
])->name('super.users.confirm');
Route::post('/users/confirm/{id}', 'Webkul\User\Http\Controllers\UserController@destroySelf')->defaults('_config', [
'redirect' => 'admin.users.index'
])->name('admin.users.confirm.destroy');
])->name('admin.users.destroy');
// User Role Routes
Route::get('/roles', 'Webkul\User\Http\Controllers\RoleController@index')->defaults('_config', [

View File

@ -140,7 +140,12 @@
.filter-row-one .dropdown-filters {
right: unset;
position: static !important;
left: 25px;
.per-page-label {
position: static !important;
}
}
}

View File

@ -8,15 +8,15 @@
<div class="content">
<div class="page-header">
<div class="page-title">
<h1>{{ __('admin::app.users.users.confirm-delete-title') }}</h1>
</div>
<div class="page-action">
<h1>
<i class="icon angle-left-icon back-link" onclick="history.length > 1 ? history.go(-1) : window.location = '{{ url('/admin/dashboard') }}';"></i>
{{ __('admin::app.users.users.confirm-delete-title') }}
</h1>
</div>
</div>
<div class="page-content">
<form action="{{ route('admin.users.confirm.destroy') }}" method="POST" @submit.prevent="onSubmit">
<form action="{{ route('admin.users.destroy', $user->id) }}" method="POST" @submit.prevent="onSubmit">
@csrf
<div class="control-group" :class="[errors.has('password') ? 'has-error' : '']">
<label for="password" class="required">

View File

@ -266,7 +266,7 @@
@if (isset($item->additional['attributes']))
<div class="item-options">
@foreach ($item->additional['attributes'] as $attribute)
<b>{{ $attribute['attribute_name'] }} : </b>{{ $attribute['option_label'] }}</br>
@endforeach
@ -344,11 +344,14 @@
</tr>
@endif
<tr class="border">
<td>{{ __('admin::app.sales.orders.tax') }}</td>
@php ($taxRates = Webkul\Tax\Helpers\Tax::getTaxRatesWithAmount($order, true))
@foreach ($taxRates as $taxRate => $baseTaxAmount)
<tr {{ $loop->last ? 'class=border' : ''}}>
<td id="taxrate-{{ core()->taxRateAsIdentifier($taxRate) }}">{{ __('admin::app.sales.orders.tax') }} {{ $taxRate }} %</td>
<td>-</td>
<td>{{ core()->formatBasePrice($order->base_tax_amount) }}</td>
<td id="basetaxamount-{{ core()->taxRateAsIdentifier($taxRate) }}">{{ core()->formatBasePrice($baseTaxAmount) }}</td>
</tr>
@endforeach
<tr class="bold">
<td>{{ __('admin::app.sales.orders.grand-total') }}</td>

View File

@ -32,6 +32,6 @@ class CreateCartruleCustomersTable extends Migration
*/
public function down()
{
Schema::dropIfExists('cartrule_customers');
Schema::dropIfExists('cart_rule_customers');
}
}

View File

@ -22,7 +22,7 @@ class CreateCartruleCouponsTable extends Migration
$table->integer('type')->unsigned()->default(0);
$table->boolean('is_primary')->default(0);
$table->date('expired_at')->nullable();
$table->integer('cart_rule_id')->unsigned();
$table->foreign('cart_rule_id')->references('id')->on('cart_rules')->onDelete('cascade');
$table->timestamps();
@ -36,6 +36,6 @@ class CreateCartruleCouponsTable extends Migration
*/
public function down()
{
Schema::dropIfExists('cartrule_coupons');
Schema::dropIfExists('cart_rule_coupons');
}
}

View File

@ -10,7 +10,7 @@ use Webkul\CartRule\Repositories\CartRuleCouponRepository;
/**
* Cart Rule controller
*
* @author Jitendra Singh <jitendra@webkul.com>
* @author Jitendra Singh <jitendra@webkul.com>
* @copyright 2018 Webkul Software Pvt Ltd (http://www.webkul.com)
*/
class CartRuleController extends Controller
@ -39,8 +39,9 @@ class CartRuleController extends Controller
/**
* Create a new controller instance.
*
* @param \Webkul\CartRule\Repositories\CartRuleRepository $cartRuleRepository
* @param \Webkul\CartRule\Repositories\CartRuleCouponRepository $cartRuleCouponRepository
* @param \Webkul\CartRule\Repositories\CartRuleRepository $cartRuleRepository
* @param \Webkul\CartRule\Repositories\CartRuleCouponRepository $cartRuleCouponRepository
*
* @return void
*/
public function __construct(
@ -112,6 +113,7 @@ class CartRuleController extends Controller
* Show the form for editing the specified resource.
*
* @param int $id
*
* @return \Illuminate\Http\Response
*/
public function edit($id)
@ -124,8 +126,9 @@ class CartRuleController extends Controller
/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param int $id
* @param \Illuminate\Http\Request $request
* @param int $id
*
* @return \Illuminate\Http\Response
*/
public function update(Request $request, $id)
@ -159,7 +162,8 @@ class CartRuleController extends Controller
/**
* Remove the specified resource from storage.
*
* @param int $id
* @param int $id
*
* @return \Illuminate\Http\Response
*/
public function destroy($id)
@ -176,7 +180,7 @@ class CartRuleController extends Controller
session()->flash('success', trans('admin::app.response.delete-success', ['name' => 'Cart Rule']));
return response()->json(['message' => true], 200);
} catch(\Exception $e) {
} catch (\Exception $e) {
session()->flash('error', trans('admin::app.response.delete-failed', ['name' => 'Cart Rule']));
}
@ -193,7 +197,7 @@ class CartRuleController extends Controller
$this->validate(request(), [
'coupon_qty' => 'required|integer|min:1',
'code_length' => 'required|integer|min:10',
'code_format' => 'required'
'code_format' => 'required',
]);
if (! request('id')) {

View File

@ -125,9 +125,9 @@ class CartRuleRepository extends Repository
*/
public function create(array $data)
{
$data['starts_from'] = $data['starts_from'] ?: null;
$data['starts_from'] = isset($data['starts_from']) && $data['starts_from'] ? $data['starts_from'] : null;
$data['ends_till'] = $data['ends_till'] ?: null;
$data['ends_till'] = isset($data['ends_till']) && $data['ends_till'] ? $data['ends_till'] : null;
$data['status'] = ! isset($data['status']) ? 0 : 1;

View File

@ -5,7 +5,9 @@ namespace Webkul\Checkout;
use Webkul\Checkout\Repositories\CartRepository;
use Webkul\Checkout\Repositories\CartItemRepository;
use Webkul\Checkout\Repositories\CartAddressRepository;
use Webkul\Customer\Models\CustomerAddress;
use Webkul\Product\Repositories\ProductRepository;
use Webkul\Tax\Helpers\Tax;
use Webkul\Tax\Repositories\TaxCategoryRepository;
use Webkul\Checkout\Models\CartItem;
use Webkul\Checkout\Models\CartPayment;
@ -21,7 +23,8 @@ use Illuminate\Support\Arr;
* @author Jitendra Singh <jitendra@webkul.com>
* @copyright 2018 Webkul Software Pvt Ltd (http://www.webkul.com)
*/
class Cart {
class Cart
{
/**
* CartRepository instance
@ -75,15 +78,16 @@ class Cart {
/**
* Create a new controller instance.
*
* @param Webkul\Checkout\Repositories\CartRepository $cart
* @param Webkul\Checkout\Repositories\CartItemRepository $cartItem
* @param Webkul\Checkout\Repositories\CartAddressRepository $cartAddress
* @param Webkul\Product\Repositories\ProductRepository $product
* @param Webkul\Product\Repositories\TaxCategoryRepository $taxCategory
* @param Webkul\Product\Repositories\CustomerAddressRepository $customerAddress
* @param Webkul\Product\Repositories\CustomerAddressRepository $customerAddress
* @param Webkul\Discount\Repositories\CartRuleRepository $cartRule
* @param Webkul\Helpers\Discount $discount
* @param Webkul\Checkout\Repositories\CartRepository $cart
* @param Webkul\Checkout\Repositories\CartItemRepository $cartItem
* @param Webkul\Checkout\Repositories\CartAddressRepository $cartAddress
* @param Webkul\Product\Repositories\ProductRepository $product
* @param Webkul\Product\Repositories\TaxCategoryRepository $taxCategory
* @param Webkul\Product\Repositories\CustomerAddressRepository $customerAddress
* @param Webkul\Product\Repositories\CustomerAddressRepository $customerAddress
* @param Webkul\Discount\Repositories\CartRuleRepository $cartRule
* @param Webkul\Helpers\Discount $discount
*
* @return void
*/
public function __construct(
@ -94,8 +98,7 @@ class Cart {
TaxCategoryRepository $taxCategoryRepository,
WishlistRepository $wishlistRepository,
CustomerAddressRepository $customerAddressRepository
)
{
) {
$this->cartRepository = $cartRepository;
$this->cartItemRepository = $cartItemRepository;
@ -128,6 +131,7 @@ class Cart {
*
* @param integer $productId
* @param array $data
*
* @return Mixed Cart on success, array with warning otherwise
*/
public function addProduct($productId, $data)
@ -147,7 +151,7 @@ class Cart {
if (is_string($cartProducts)) {
$this->collectTotals();
if (! count($cart->all_items) > 0) {
if (!count($cart->all_items) > 0) {
session()->forget('cart');
}
@ -162,11 +166,12 @@ class Cart {
$cartProduct['parent_id'] = $parentCartItem->id;
}
if (! $cartItem) {
if (!$cartItem) {
$cartItem = $this->cartItemRepository->create(array_merge($cartProduct, ['cart_id' => $cart->id]));
} else {
if (isset($cartProduct['parent_id']) && $cartItem->parent_id != $parentCartItem->id) {
$cartItem = $this->cartItemRepository->create(array_merge($cartProduct, ['cart_id' => $cart->id]));
$cartItem = $this->cartItemRepository->create(array_merge($cartProduct,
['cart_id' => $cart->id]));
} else {
if ($cartItem->product->getTypeInstance()->showQuantityBox() === false) {
return ['warning' => __('shop::app.checkout.cart.integrity.qty_impossible')];
@ -193,6 +198,7 @@ class Cart {
* Create new cart instance.
*
* @param array $data
*
* @return Cart|null
*/
public function create($data)
@ -219,7 +225,7 @@ class Cart {
$cart = $this->cartRepository->create($cartData);
if (! $cart) {
if (!$cart) {
session()->flash('error', trans('shop::app.checkout.cart.create-error'));
return;
@ -280,6 +286,7 @@ class Cart {
* Get cart item by product
*
* @param array $data
*
* @return CartItem|void
*/
public function getItemByProduct($data)
@ -303,6 +310,7 @@ class Cart {
* Remove the item from the cart
*
* @param integer $itemId
*
* @return boolean
*/
public function removeItem($itemId)
@ -338,7 +346,10 @@ class Cart {
public function mergeCart()
{
if (session()->has('cart')) {
$cart = $this->cartRepository->findOneWhere(['customer_id' => $this->getCurrentCustomer()->user()->id, 'is_active' => 1]);
$cart = $this->cartRepository->findOneWhere([
'customer_id' => $this->getCurrentCustomer()->user()->id,
'is_active' => 1,
]);
$guestCart = session()->get('cart');
@ -367,7 +378,7 @@ class Cart {
$cartItem->quantity = $newQuantity = $cartItem->quantity + $guestCartItem->quantity;
if (! $this->isItemHaveQuantity($cartItem)) {
if (!$this->isItemHaveQuantity($cartItem)) {
$this->cartItemRepository->delete($guestCartItem->id);
continue;
@ -388,14 +399,14 @@ class Cart {
$found = true;
}
if (! $found) {
if (!$found) {
$this->cartItemRepository->update([
'cart_id' => $cart->id
'cart_id' => $cart->id,
], $guestCartItem->id);
foreach ($guestCartItem->children as $child) {
$this->cartItemRepository->update([
'cart_id' => $cart->id
'cart_id' => $cart->id,
], $child->id);
}
}
@ -415,11 +426,12 @@ class Cart {
* Save cart
*
* @param Cart $cart
*
* @return void
*/
public function putCart($cart)
{
if (! $this->getCurrentCustomer()->check()) {
if (!$this->getCurrentCustomer()->check()) {
session()->put('cart', $cart);
}
}
@ -475,6 +487,7 @@ class Cart {
* Save customer address
*
* @param array $data
*
* @return boolean
*/
public function saveCustomerAddress($data)
@ -487,7 +500,7 @@ class Cart {
$billingAddress['cart_id'] = $cart->id;
if (isset($data['billing']['address_id']) && $data['billing']['address_id']) {
$address = $this->customerAddressRepository->findOneWhere(['id'=> $data['billing']['address_id']])->toArray();
$address = $this->customerAddressRepository->findOneWhere(['id' => $data['billing']['address_id']])->toArray();
$billingAddress['first_name'] = $this->getCurrentCustomer()->user()->first_name;
$billingAddress['last_name'] = $this->getCurrentCustomer()->user()->last_name;
@ -501,7 +514,7 @@ class Cart {
}
if (isset($data['billing']['save_as_address']) && $data['billing']['save_as_address']) {
$billingAddress['customer_id'] = $this->getCurrentCustomer()->user()->id;
$billingAddress['customer_id'] = $this->getCurrentCustomer()->user()->id;
$this->customerAddressRepository->create($billingAddress);
}
@ -525,7 +538,7 @@ class Cart {
}
if (isset($data['shipping']['save_as_address']) && $data['shipping']['save_as_address']) {
$shippingAddress['customer_id'] = $this->getCurrentCustomer()->user()->id;
$shippingAddress['customer_id'] = $this->getCurrentCustomer()->user()->id;
$this->customerAddressRepository->create($shippingAddress);
}
@ -543,9 +556,11 @@ class Cart {
}
} else {
if (isset($billingAddress['use_for_shipping']) && $billingAddress['use_for_shipping']) {
$this->cartAddressRepository->create(array_merge($billingAddress, ['address_type' => 'shipping']));
$this->cartAddressRepository->create(array_merge($billingAddress,
['address_type' => 'shipping']));
} else {
$this->cartAddressRepository->create(array_merge($shippingAddress, ['address_type' => 'shipping']));
$this->cartAddressRepository->create(array_merge($shippingAddress,
['address_type' => 'shipping']));
}
}
}
@ -573,6 +588,8 @@ class Cart {
$cart->save();
$this->collectTotals();
return true;
}
@ -580,6 +597,7 @@ class Cart {
* Save shipping method for cart
*
* @param string $shippingMethodCode
*
* @return boolean
*/
public function saveShippingMethod($shippingMethodCode)
@ -598,6 +616,7 @@ class Cart {
* Save payment method for cart
*
* @param string $payment
*
* @return CartPayment
*/
public function savePaymentMethod($payment)
@ -606,8 +625,9 @@ class Cart {
return false;
}
if ($cartPayment = $cart->payment)
if ($cartPayment = $cart->payment) {
$cartPayment->delete();
}
$cartPayment = new CartPayment;
@ -648,19 +668,19 @@ class Cart {
$cart->discount_amount += $item->discount_amount;
$cart->base_discount_amount += $item->base_discount_amount;
$cart->grand_total = (float) $cart->grand_total + $item->total + $item->tax_amount - $item->discount_amount;
$cart->base_grand_total = (float) $cart->base_grand_total + $item->base_total + $item->base_tax_amount - $item->base_discount_amount;
$cart->sub_total = (float) $cart->sub_total + $item->total;
$cart->base_sub_total = (float) $cart->base_sub_total + $item->base_total;
$cart->tax_total = (float) $cart->tax_total + $item->tax_amount;
$cart->base_tax_total = (float) $cart->base_tax_total + $item->base_tax_amount;
$cart->sub_total = (float)$cart->sub_total + $item->total;
$cart->base_sub_total = (float)$cart->base_sub_total + $item->base_total;
}
$cart->tax_total = Tax::getTaxTotal($cart, false);
$cart->base_tax_total = Tax::getTaxTotal($cart, true);
$cart->grand_total = $cart->sub_total + $cart->tax_total + $cart->discount_amount;
$cart->base_grand_total = $cart->base_sub_total + $cart->base_tax_total - $cart->base_discount_amount;
if ($shipping = $cart->selected_shipping_rate) {
$cart->grand_total = (float) $cart->grand_total + $shipping->price - $shipping->discount_amount;
$cart->base_grand_total = (float) $cart->base_grand_total + $shipping->base_price - $shipping->base_discount_amount;
$cart->grand_total = (float)$cart->grand_total + $shipping->price - $shipping->discount_amount;
$cart->base_grand_total = (float)$cart->base_grand_total + $shipping->base_price - $shipping->base_discount_amount;
$cart->discount_amount += $shipping->discount_amount;
$cart->base_discount_amount += $shipping->base_discount_amount;
@ -700,7 +720,7 @@ class Cart {
foreach ($cart->items as $item) {
$item->product->getTypeInstance()->validateCartItem($item);
$price = ! is_null($item->custom_price) ? $item->custom_price : $item->base_price;
$price = !is_null($item->custom_price) ? $item->custom_price : $item->base_price;
$this->cartItemRepository->update([
'price' => core()->convertPrice($price),
@ -719,13 +739,9 @@ class Cart {
*
* @return void
*/
public function calculateItemsTax()
public function calculateItemsTax(): void
{
if (! $cart = $this->getCart()) {
return false;
}
if (! $cart->shipping_address && ! $cart->billing_address) {
return;
}
@ -742,59 +758,72 @@ class Cart {
$address = $cart->billing_address;
}
if ($address === null && auth()->guard('customer')->check()) {
$address = auth()->guard('customer')->user()->addresses()
->where('default_address',1)->first();
}
if ($address === null) {
$address = new class() {
public $country;
public $postcode;
function __construct()
{
$this->country = strtoupper(config('app.default_country'));
}
};
}
$taxRates = $taxCategory->tax_rates()->where([
'country' => $address->country,
])->orderBy('tax_rate', 'desc')->get();
'country' => $address->country,
])->orderBy('tax_rate', 'desc')->get();
$item = $this->setItemTaxToZero($item);
if ($taxRates->count()) {
foreach ($taxRates as $rate) {
$haveTaxRate = false;
if ($rate->state != '' && $rate->state != $address->state) {
$this->setItemTaxToZero($item);
continue;
}
if (! $rate->is_zip) {
if ($rate->zip_code == '*' || $rate->zip_code == $address->postcode)
if (!$rate->is_zip) {
if ($rate->zip_code == '*' || $rate->zip_code == $address->postcode) {
$haveTaxRate = true;
}
} else {
if ($address->postcode >= $rate->zip_from && $address->postcode <= $rate->zip_to)
if ($address->postcode >= $rate->zip_from && $address->postcode <= $rate->zip_to) {
$haveTaxRate = true;
}
}
if ($haveTaxRate) {
$item->tax_percent = $rate->tax_rate;
$item->tax_amount = ($item->total * $rate->tax_rate) / 100;
$item->base_tax_amount = ($item->base_total * $rate->tax_rate) / 100;
$item->save();
break;
} else {
$this->setItemTaxToZero($item);
break;
}
}
} else {
$this->setItemTaxToZero($item);
}
$item->save();
}
}
/**
* Set Item tax to zero.
*
* @return void
* @param CartItem $item
* @return CartItem
*/
protected function setItemTaxToZero($item) {
protected function setItemTaxToZero(CartItem $item): CartItem {
$item->tax_percent = 0;
$item->tax_amount = 0;
$item->base_tax_amount = 0;
$item->save();
return $item;
}
/**
@ -835,6 +864,7 @@ class Cart {
* Checks if all cart items have sufficient quantity.
*
* @param CartItem $item
*
* @return boolean
*/
public function isItemHaveQuantity($item)
@ -919,6 +949,7 @@ class Cart {
* Prepares data for order item
*
* @param array $data
*
* @return array
*/
public function prepareDataForOrderItem($data)
@ -959,6 +990,7 @@ class Cart {
* Move a wishlist item to cart
*
* @param WishlistItem $wishlistItem
*
* @return boolean
*/
public function moveToCart($wishlistItem)
@ -988,6 +1020,7 @@ class Cart {
* Function to move a already added product to wishlist will run only on customer authentication.
*
* @param integer $itemId
*
* @return boolean|void
*/
public function moveToWishlist($itemId)
@ -1019,7 +1052,7 @@ class Cart {
}
}
if (! $found) {
if (!$found) {
$this->wishlistRepository->create([
'channel_id' => $cart->channel_id,
'customer_id' => $this->getCurrentCustomer()->user()->id,
@ -1043,6 +1076,7 @@ class Cart {
* Set coupon code to the cart
*
* @param string $code
*
* @return Cart
*/
public function setCouponCode($code)
@ -1071,4 +1105,4 @@ class Cart {
return $this;
}
}
}

View File

@ -993,4 +993,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);
}
}

View File

@ -73,6 +73,7 @@ class Laravel5Helper extends Laravel5
* @param array $productStates
*
* @return \Webkul\Product\Models\Product
* @part ORM
*/
public function haveProduct(int $productType, array $configs = [], array $productStates = []): Product
{

View File

@ -45,7 +45,7 @@ $factory->defineAs(ProductAttributeValue::class, 'tax_category_id', function (Fa
return factory(Product::class)->create()->id;
},
'channel' => 'default',
'integer_value' => null, // ToDo
'integer_value' => null,
'attribute_id' => 4,
];
});

View File

@ -74,7 +74,7 @@ class ProductFlatRepository extends Repository
public function getFilterableAttributes($category, $products) {
$filterAttributes = [];
if (count($category->filterableAttributes) > 0 && count($products)) {
if (count($category->filterableAttributes) > 0 ) {
$filterAttributes = $category->filterableAttributes;
} else {
$categoryProductAttributes = $this->getCategoryProductAttribute($category->id);

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -39,9 +39,3 @@
*
* Date: 2019-05-01T21:04Z
*/
/**
* vue-class-component v7.0.1
* (c) 2015-present Evan You
* @license MIT
*/

View File

@ -1,4 +1,4 @@
{
"/js/shop.js": "/js/shop.js?id=d6e76f2c8f75d4217522",
"/css/shop.css": "/css/shop.css?id=3e715efc0eb756fd1e79"
"/js/shop.js": "/js/shop.js?id=6d8ea335fbfa47e80e72",
"/css/shop.css": "/css/shop.css?id=ccf417b825955d8bd301"
}

View File

@ -103,6 +103,10 @@ class OnepageController extends Controller
{
$data = request()->all();
if (! auth()->guard('customer')->check() && ! Cart::getCart()->hasGuestCheckoutItems()) {
return response()->json(['redirect_url' => route('customer.session.index')], 403);
}
$data['billing']['address1'] = implode(PHP_EOL, array_filter($data['billing']['address1']));
$data['shipping']['address1'] = implode(PHP_EOL, array_filter($data['shipping']['address1']));

View File

@ -3809,6 +3809,12 @@ section.review {
.rtl {
direction: rtl;
.dropdown-filters {
.per-page-label {
position: static !important;
}
}
//header css start here
.header {
.header-top {

View File

@ -286,7 +286,7 @@
</li>
<li class="mb-15">
@{{ addresses.country }}.
@{{ addresses.country }} @{{ addresses.postcode }}
</li>
<li>

View File

@ -18,10 +18,12 @@
@endif
@if ($cart->base_tax_total)
@foreach (Webkul\Tax\Helpers\Tax::getTaxRatesWithAmount($cart, true) as $taxRate => $baseTaxAmount )
<div class="item-detail">
<label>{{ __('shop::app.checkout.total.tax') }}</label>
<label class="right">{{ core()->currency($cart->base_tax_total) }}</label>
<label id="taxrate-{{ core()->taxRateAsIdentifier($taxRate) }}">{{ __('shop::app.checkout.total.tax') }} {{ $taxRate }} %</label>
<label class="right" id="basetaxamount-{{ core()->taxRateAsIdentifier($taxRate) }}">{{ core()->currency($baseTaxAmount) }}</label>
</div>
@endforeach
@endif
<div class="item-detail" id="discount-detail" @if ($cart->base_discount_amount && $cart->base_discount_amount > 0) style="display: block;" @else style="display: none;" @endif>

View File

@ -123,7 +123,7 @@
@if (isset($item->additional['attributes']))
<div class="item-options">
@foreach ($item->additional['attributes'] as $attribute)
<b>{{ $attribute['attribute_name'] }} : </b>{{ $attribute['option_label'] }}</br>
@endforeach
@ -161,12 +161,14 @@
</span>
</div>
@foreach (Webkul\Tax\Helpers\Tax::getTaxRatesWithAmount($order, true) as $taxRate => $baseTaxAmount )
<div>
<span>{{ __('shop::app.mail.order.tax') }}</span>
<span style="float: right;">
{{ core()->formatBasePrice($order->base_tax_amount) }}
<span id="taxrate-{{ core()->taxRateAsIdentifier($taxRate) }}">{{ __('shop::app.mail.order.tax') }} {{ $taxRate }} %</span>
<span id="basetaxamount-{{ core()->taxRateAsIdentifier($taxRate) }}" style="float: right;">
{{ core()->formatBasePrice($baseTaxAmount) }}
</span>
</div>
@endforeach
@if ($order->discount_amount > 0)
<div>

View File

@ -125,14 +125,14 @@
<tbody>
@foreach ($shipment->items as $item)
<tr>
<td data-value="{{ __('shop::app.customer.account.order.view.SKU') }}" style="text-align: left;padding: 8px">{{ $item->getTypeInstance()->getOrderedItem($item)->sku }}</td>
<td data-value="{{ __('shop::app.customer.account.order.view.SKU') }}" style="text-align: left;padding: 8px">{{ $item->sku }}</td>
<td data-value="{{ __('shop::app.customer.account.order.view.product-name') }}" style="text-align: left;padding: 8px">
{{ $item->name }}
@if (isset($item->additional['attributes']))
<div class="item-options">
@foreach ($item->additional['attributes'] as $attribute)
<b>{{ $attribute['attribute_name'] }} : </b>{{ $attribute['option_label'] }}</br>
@endforeach

View File

@ -30,7 +30,8 @@
{{ __('shop::app.mail.invoice.summary') }}
</div>
<div style="display: flex;flex-direction: row;margin-top: 20px;justify-content: space-between;margin-bottom: 40px;">
<div
style="display: flex;flex-direction: row;margin-top: 20px;justify-content: space-between;margin-bottom: 40px;">
@if ($order->shipping_address)
<div style="line-height: 25px;">
<div style="font-weight: bold;font-size: 16px;color: #242424;">
@ -103,37 +104,41 @@
<table style="overflow-x: auto; border-collapse: collapse;
border-spacing: 0;width: 100%">
<thead>
<tr style="background-color: #f2f2f2">
<th style="text-align: left;padding: 8px">{{ __('shop::app.customer.account.order.view.product-name') }}</th>
<th style="text-align: left;padding: 8px">{{ __('shop::app.customer.account.order.view.price') }}</th>
<th style="text-align: left;padding: 8px">{{ __('shop::app.customer.account.order.view.qty') }}</th>
</tr>
<tr style="background-color: #f2f2f2">
<th style="text-align: left;padding: 8px">{{ __('shop::app.customer.account.order.view.product-name') }}</th>
<th style="text-align: left;padding: 8px">{{ __('shop::app.customer.account.order.view.price') }}</th>
<th style="text-align: left;padding: 8px">{{ __('shop::app.customer.account.order.view.qty') }}</th>
</tr>
</thead>
<tbody>
@foreach ($invoice->items as $item)
<tr>
<td data-value="{{ __('shop::app.customer.account.order.view.product-name') }}" style="text-align: left;padding: 8px">
{{ $item->name }}
@if (isset($item->additional['attributes']))
<div class="item-options">
@foreach ($item->additional['attributes'] as $attribute)
<b>{{ $attribute['attribute_name'] }} : </b>{{ $attribute['option_label'] }}</br>
@endforeach
@foreach ($invoice->items as $item)
<tr>
<td data-value="{{ __('shop::app.customer.account.order.view.product-name') }}"
style="text-align: left;padding: 8px">
{{ $item->name }}
</div>
@endif
</td>
@if (isset($item->additional['attributes']))
<div class="item-options">
<td data-value="{{ __('shop::app.customer.account.order.view.price') }}" style="text-align: left;padding: 8px">{{ core()->formatPrice($item->price, $order->order_currency_code) }}
</td>
@foreach ($item->additional['attributes'] as $attribute)
<b>{{ $attribute['attribute_name'] }}
: </b>{{ $attribute['option_label'] }}</br>
@endforeach
<td data-value="{{ __('shop::app.customer.account.order.view.qty') }}" style="text-align: left;padding: 8px">{{ $item->qty }}</td>
</tr>
</div>
@endif
</td>
@endforeach
<td data-value="{{ __('shop::app.customer.account.order.view.price') }}"
style="text-align: left;padding: 8px">{{ core()->formatPrice($item->price, $order->order_currency_code) }}
</td>
<td data-value="{{ __('shop::app.customer.account.order.view.qty') }}"
style="text-align: left;padding: 8px">{{ $item->qty }}</td>
</tr>
@endforeach
</tbody>
</table>
</div>
@ -146,7 +151,7 @@
{{ core()->formatPrice($invoice->sub_total, $invoice->order_currency_code) }}
</span>
</div>
@if ($order->shipping_address)
<div>
<span>{{ __('shop::app.mail.order.shipping-handling') }}</span>
@ -158,8 +163,8 @@
<div>
<span>{{ __('shop::app.mail.order.tax') }}</span>
<span style="float: right;">
{{ core()->formatPrice($invoice->tax_amount, $invoice->order_currency_code) }}
<span id="taxamount" style="float: right;">
{{ core()->formatPrice($invoice->tax_amount, $order->order_currency_code) }}
</span>
</div>
@ -180,7 +185,8 @@
</div>
</div>
<div style="margin-top: 65px;font-size: 16px;color: #5E5E5E;line-height: 24px;display: inline-block;width: 100%">
<div
style="margin-top: 65px;font-size: 16px;color: #5E5E5E;line-height: 24px;display: inline-block;width: 100%">
<p style="font-size: 16px;color: #5E5E5E;line-height: 24px;">
{!!
__('shop::app.mail.order.help', [

View File

@ -116,10 +116,10 @@
<td data-value="{{ __('shop::app.customer.account.order.view.product-name') }}" style="text-align: left;padding: 8px">
{{ $item->name }}
@if (isset($item->additional['attributes']))
<div class="item-options">
@foreach ($item->additional['attributes'] as $attribute)
<b>{{ $attribute['attribute_name'] }} : </b>{{ $attribute['option_label'] }}</br>
@endforeach
@ -156,12 +156,14 @@
</div>
@endif
@foreach (Webkul\Tax\Helpers\Tax::getTaxRatesWithAmount($order, false) as $taxRate => $taxAmount )
<div>
<span>{{ __('shop::app.mail.order.tax') }}</span>
<span style="float: right;">
{{ core()->formatPrice($order->tax_amount, $order->order_currency_code) }}
<span id="taxrate-{{ core()->taxRateAsIdentifier($taxRate) }}">{{ __('shop::app.mail.order.tax') }} {{ $taxRate }} %</span>
<span id="taxamount-{{ core()->taxRateAsIdentifier($taxRate) }}" style="float: right;">
{{ core()->formatPrice($taxAmount, $order->order_currency_code) }}
</span>
</div>
@endforeach
@if ($order->discount_amount > 0)
<div>

View File

@ -115,10 +115,10 @@
<tr>
<td data-value="{{ __('shop::app.customer.account.order.view.product-name') }}" style="text-align: left;padding: 8px">
{{ $item->name }}
@if (isset($item->additional['attributes']))
<div class="item-options">
@foreach ($item->additional['attributes'] as $attribute)
<b>{{ $attribute['attribute_name'] }} : </b>{{ $attribute['option_label'] }}</br>
@endforeach
@ -160,12 +160,14 @@
@endif
@if ($refund->tax_amount > 0)
@foreach (Webkul\Tax\Helpers\Tax::getTaxRatesWithAmount($refund, false) as $taxRate => $taxAmount)
<div>
<span>{{ __('shop::app.mail.order.tax') }}</span>
<span style="float: right;">
{{ core()->formatPrice($refund->tax_amount, $refund->order_currency_code) }}
</span>
</div>
@endforeach
@endif
@if ($refund->discount_amount > 0)

View File

@ -122,14 +122,14 @@
<tbody>
@foreach ($shipment->items as $item)
<tr>
<td data-value="{{ __('shop::app.customer.account.order.view.SKU') }}" style="text-align: left;padding: 8px">{{ $item->getTypeInstance()->getOrderedItem($item)->sku }}</td>
<td data-value="{{ __('shop::app.customer.account.order.view.SKU') }}" style="text-align: left;padding: 8px">{{ $item->sku }}</td>
<td data-value="{{ __('shop::app.customer.account.order.view.product-name') }}" style="text-align: left;padding: 8px">
{{ $item->name }}
@if (isset($item->additional['attributes']))
<div class="item-options">
@foreach ($item->additional['attributes'] as $attribute)
<b>{{ $attribute['attribute_name'] }} : </b>{{ $attribute['option_label'] }}</br>
@endforeach

View File

@ -119,7 +119,7 @@
@if (isset($item->additional['attributes']))
<div class="item-options">
@foreach ($item->additional['attributes'] as $attribute)
<b>{{ $attribute['attribute_name'] }} : </b>{{ $attribute['option_label'] }}</br>
@endforeach
@ -157,12 +157,14 @@
</span>
</div>
<div>
<span>{{ __('shop::app.mail.order.cancel.tax') }}</span>
<span style="float: right;">
{{ core()->formatPrice($order->tax_amount, $order->order_currency_code) }}
@foreach (Webkul\Tax\Helpers\Tax::getTaxRatesWithAmount($order, false) as $taxRate => $taxAmount )
<div>
<span id="taxrate-{{ core()->taxRateAsIdentifier($taxRate) }}">{{ __('shop::app.mail.order.cancel.tax') }} {{ $taxRate }} %</span>
<span id="taxamount-{{ core()->taxRateAsIdentifier($taxRate) }}" style="float: right;">
{{ core()->formatPrice($taxAmount, $order->order_currency_code) }}
</span>
</div>
</div>
@endforeach
@if ($order->discount_amount > 0)
<div>

View File

@ -11,7 +11,9 @@
$products = $productRepository->getAll($category->id);
$filterAttributes = $productFlatRepository->getFilterableAttributes($category, $products);
} else {
}
if (! count($filterAttributes) > 0) {
$filterAttributes = $attributeRepository->getFilterAttributes();
}

View File

@ -0,0 +1,17 @@
<?php
/** @var \Illuminate\Database\Eloquent\Factory $factory */
use Faker\Generator as Faker;
use Webkul\Tax\Models\TaxCategory;
$factory->define(TaxCategory::class, function (Faker $faker) {
return [
'channel_id' => function () {
return core()->getCurrentChannel()->id;
},
'code' => $faker->uuid,
'name' => $faker->words(2, true),
'description' => $faker->sentence(10),
];
});

View File

@ -0,0 +1,19 @@
<?php
/** @var \Illuminate\Database\Eloquent\Factory $factory */
use Faker\Generator as Faker;
use Webkul\Tax\Models\TaxMap;
use Webkul\Tax\Models\TaxRate;
use Webkul\Tax\Models\TaxCategory;
$factory->define(TaxMap::class, function (Faker $faker) {
return [
'tax_category_id' => function () {
return factory(TaxCategory::class)->create()->id;
},
'tax_rate_id' => function () {
return factory(TaxRate::class)->create()->id;
},
];
});

View File

@ -0,0 +1,19 @@
<?php
/** @var \Illuminate\Database\Eloquent\Factory $factory */
use Faker\Generator as Faker;
use Webkul\Tax\Models\TaxRate;
$factory->define(TaxRate::class, function (Faker $faker) {
return [
'identifier' => $faker->uuid,
'is_zip' => 0,
'zip_code' => '*',
'zip_from' => null,
'zip_to' => null,
'state' => '',
'country' => $faker->countryCode,
'tax_rate' => $faker->randomFloat(2, 3, 25),
];
});

View File

@ -0,0 +1,48 @@
<?php
namespace Webkul\Tax\Helpers;
class Tax
{
public const TAX_PRECISION = 4;
/**
* Returns an array with tax rates and tax amount
* @param object $that
* @param bool $asBase
*
* @return array
*/
public static function getTaxRatesWithAmount(object $that, bool $asBase = false): array
{
$taxes = [];
foreach ($that->items as $item) {
$taxRate = (string)round((float)$item->tax_percent, self::TAX_PRECISION);
if (!array_key_exists($taxRate, $taxes)) {
$taxes[$taxRate] = 0;
}
$taxes[$taxRate] += $asBase ? $item->base_tax_amount : $item->tax_amount;
}
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);
$result = 0;
foreach ($taxes as $taxRate => $taxAmount) {
$result += round($taxAmount, 2);
}
return $result;
}
}

View File

@ -22,5 +22,6 @@ class TaxServiceProvider extends ServiceProvider
*/
public function register()
{
$this->loadFactoriesFrom(__DIR__ . '/../Database/Factories');
}
}

View File

@ -685,7 +685,12 @@
_method : element.getAttribute('data-method')
}).then(function(response) {
this.result = response;
location.reload();
if (response.data.redirect) {
window.location.href = response.data.redirect;
} else {
location.reload();
}
}).catch(function (error) {
location.reload();
});

View File

@ -172,7 +172,9 @@ class UserController extends Controller
Event::dispatch('user.admin.delete.before', $id);
if (auth()->guard('admin')->user()->id == $id) {
return view('admin::customers.confirm-password');
return response()->json([
'redirect' => route('super.users.confirm', ['id' => $id]),
]);
}
try {
@ -191,6 +193,19 @@ class UserController extends Controller
return response()->json(['message' => false], 400);
}
/**
* Show the form for confirming the user password.
*
* @param integer $id
* @return \Illuminate\View\View
*/
public function confirm($id)
{
$user = $this->adminRepository->findOrFail($id);
return view($this->_config['view'], compact('user'));
}
/**
* destroy current after confirming
*

View File

@ -239,8 +239,8 @@ use Webkul\Velocity\Repositories\Product\ProductRepository as VelocityProductRep
'avgRating' => $avgRatings,
'firstReviewText' => trans('velocity::app.products.be-first-review'),
'addToCartHtml' => view('shop::products.add-to-cart', [
'product' => $product,
'addWishlistClass' => !(isset($list) && $list) ? '' : '',
'product' => $product,
'addWishlistClass' => !(isset($list) && $list) ? '' : '',
'addToCartBtnClass' => !(isset($list) && $list) ? $addToCartBtnClass ?? '' : ''
])->render(),
];

View File

@ -108,6 +108,9 @@ return [
'footer-middle-content' => 'Footer Middle Content',
'advertisement-four' => 'Advertisement Four Images',
'advertisement-three' => 'Advertisement Three Images',
'images' => 'Images',
'general' => 'General',
'add-image-btn-title' => 'Add Image'
],
'category' => [
'save-btn-title' => 'Save Menu',

View File

@ -30,7 +30,7 @@
</div>
</div>
<accordian :title="'{{ __('admin::app.catalog.attributes.general') }}'" :active="true">
<accordian :title="'{{ __('velocity::app.admin.meta-data.general') }}'" :active="true">
<div slot="body">
<div class="control-group">
<label>{{ __('velocity::app.admin.meta-data.activate-slider') }}</label>
@ -106,19 +106,19 @@
</div>
</accordian>
<accordian :title="'{{ __('admin::app.catalog.products.images') }}'" :active="false">
<accordian :title="'{{ __('velocity::app.admin.meta-data.images') }}'" :active="false">
<div slot="body">
<div class="control-group">
<label>{{ __('velocity::app.admin.meta-data.advertisement-four') }}</label>
@if(! isset($metaData->advertisement[4]))
<image-wrapper
:button-label="'{{ __('admin::app.catalog.products.add-image-btn-title') }}'"
:button-label="'{{ __('velocity::app.admin.meta-data.add-image-btn-title') }}'"
input-name="images[4]">
</image-wrapper>
@else
<image-wrapper
:button-label="'{{ __('admin::app.catalog.products.add-image-btn-title') }}'"
:button-label="'{{ __('velocity::app.admin.meta-data.add-image-btn-title') }}'"
input-name="images[4]" :images='@json($metaData->advertisement[4])'>
</image-wrapper>
@endif
@ -128,12 +128,12 @@
<label>{{ __('velocity::app.admin.meta-data.advertisement-three') }}</label>
@if(! isset($metaData->advertisement[3]))
<image-wrapper
:button-label="'{{ __('admin::app.catalog.products.add-image-btn-title') }}'"
:button-label="'{{ __('velocity::app.admin.meta-data.add-image-btn-title') }}'"
input-name="images[3]">
</image-wrapper>
@else
<image-wrapper
:button-label="'{{ __('admin::app.catalog.products.add-image-btn-title') }}'"
:button-label="'{{ __('velocity::app.admin.meta-data.add-image-btn-title') }}'"
input-name="images[3]" :images='@json($metaData->advertisement[3])'>
</image-wrapper>
@endif
@ -144,33 +144,16 @@
@if(! isset($metaData->advertisement[2]))
<image-wrapper
:button-label="'{{ __('admin::app.catalog.products.add-image-btn-title') }}'"
:button-label="'{{ __('velocity::app.admin.meta-data.add-image-btn-title') }}'"
input-name="images[2]">
</image-wrapper>
@else
<image-wrapper
:button-label="'{{ __('admin::app.catalog.products.add-image-btn-title') }}'"
:button-label="'{{ __('velocity::app.admin.meta-data.add-image-btn-title') }}'"
input-name="images[2]" :images='@json($metaData->advertisement[2])'>
</image-wrapper>
@endif
</div>
{{-- <div class="control-group">
<label>{{ __('velocity::app.admin.meta-data.advertisement-one') }}</label>
<image-wrapper
:button-label="'{{ __('admin::app.catalog.products.add-image-btn-title') }}'"
input-name="images[1]">
</image-wrapper>
</div> --}}
{{-- <div class="control-group product-view-image">
<label>{{ __('velocity::app.admin.meta-data.product-view-image') }}</label>
<image-wrapper
input-name="product_view_images">
</image-wrapper>
</div> --}}
</div>
</accordian>

View File

@ -218,9 +218,11 @@
break;
case 'shipping-form':
document.body.style.cursor = 'wait';
this.saveShipping();
break;
if (this.showShippingSection) {
document.body.style.cursor = 'wait';
this.saveShipping();
break;
}
case 'payment-form':
document.body.style.cursor = 'wait';

View File

@ -14,10 +14,12 @@
@endif
@if ($cart->base_tax_total)
<div class="row">
<span class="col-8">{{ __('shop::app.checkout.total.tax') }}</span>
<span class="col-4 text-right">{{ core()->currency($cart->base_tax_total) }}</span>
</div>
@foreach (Webkul\Tax\Helpers\Tax::getTaxRatesWithAmount($cart, true) as $taxRate => $baseTaxAmount )
<div class="row">
<span class="col-8" id="taxrate-{{ core()->taxRateAsIdentifier($taxRate) }}">{{ __('shop::app.checkout.total.tax') }} {{ $taxRate }} %</span>
<span class="col-4 text-right" id="basetaxamount-{{ core()->taxRateAsIdentifier($taxRate) }}">{{ core()->currency($baseTaxAmount) }}</span>
</div>
@endforeach
@endif
@if (

View File

@ -9,7 +9,9 @@
$products = $productRepository->getAll($category->id);
$filterAttributes = $productFlatRepository->getFilterableAttributes($category, $products);
} else {
}
if (! count($filterAttributes) > 0) {
$filterAttributes = $attributeRepository->getFilterAttributes();
}

View File

@ -202,9 +202,15 @@
computed: {
product_qty: function() {
return this.option.products[this.selected_product]
? this.option.products[this.selected_product].qty
: 0;
var self = this;
self.qty = 0;
self.option.products.forEach(function(product, key){
if (self.selected_product == product.id)
self.qty = self.option.products[key].qty;
});
return self.qty;
}
},

View File

@ -16,7 +16,7 @@ use Codeception\Stub;
* @method void pause()
*
* @SuppressWarnings(PHPMD)
*/
*/
class UnitTester extends \Codeception\Actor
{
use _generated\UnitTesterActions;

View File

@ -0,0 +1,49 @@
<?php
use Webkul\Product\Models\ProductAttributeValue;
use Webkul\Product\Models\ProductFlat;
use Webkul\CartRule\Models\CartRule;
use Haendlerbund\SalesforceApi\Models\HbCartRule;
class CartRuleCest
{
public function testCartRuleCreation(FunctionalTester $I)
{
$I->loginAsAdmin();
$I->amOnAdminRoute('admin.cart-rules.index');
// we are dealing with vue.js so we can not do classical form filling
$I->sendAjaxPostRequest(route('admin.cart-rules.store'), [
'_token' => csrf_token(),
'name' => 'Demo Cart Rule',
// the following fields are important to send with the POST request:
'starts_from' => '',
'ends_till' => '',
'use_auto_generation' => 0,
'coupon_type' => 0, // no coupon
'action_type' => 'by_percent',
'coupon_code' => 'coupon',
'discount_amount' => '10',
'channels' => [
'default',
],
'customer_groups' => [
'guest',
],
]);
$cartRule = $I->grabRecord(CartRule::class, [
'name' => 'Demo Cart Rule',
]);
$I->seeResponseCodeIsSuccessful();
}
}

View File

@ -0,0 +1,436 @@
<?php
namespace Tests\Functional\Cart;
use FunctionalTester;
use Illuminate\Support\Facades\Config;
use Webkul\Core\Helpers\Laravel5Helper;
use Webkul\Tax\Models\TaxMap;
use Webkul\Tax\Models\TaxRate;
use Webkul\Tax\Models\TaxCategory;
use Webkul\Customer\Models\Customer;
use Webkul\Customer\Models\CustomerAddress;
use Cart;
class CartTaxesCest
{
public $country;
function _before(FunctionalTester $I)
{
$this->country = strtoupper(Config::get('app.default_country')) ?? 'DE';
}
public function checkCartWithMultipleTaxRates(FunctionalTester $I): void
{
$tax1 = $I->have(TaxRate::class, [
'country' => $this->country,
]);
$taxCategorie1 = $I->have(TaxCategory::class);
$I->have(TaxMap::class, [
'tax_rate_id' => $tax1->id,
'tax_category_id' => $taxCategorie1->id,
]);
$tax2 = $I->have(TaxRate::class, [
'country' => $this->country,
]);
$taxCategorie2 = $I->have(TaxCategory::class);
$I->have(TaxMap::class, [
'tax_rate_id' => $tax2->id,
'tax_category_id' => $taxCategorie2->id,
]);
$config1 = [
'productInventory' => ['qty' => 100],
'attributeValues' => [
'status' => true,
'new' => 1,
'tax_category_id' => $taxCategorie1->id,
],
];
$product1 = $I->haveProduct(Laravel5Helper::SIMPLE_PRODUCT, $config1);
$config2 = [
'productInventory' => ['qty' => 100],
'attributeValues' => [
'status' => true,
'new' => 1,
'tax_category_id' => $taxCategorie2->id,
],
];
$product2 = $I->haveProduct(Laravel5Helper::SIMPLE_PRODUCT, $config2);
$prod1Quantity = $I->fake()->numberBetween(9, 30);
// quantity of product1 should be not even
if ($prod1Quantity % 2 !== 0) {
$prod1Quantity -= 1;
}
$prod2Quantity = $I->fake()->numberBetween(9, 30);
// quantity of product2 should be even
if ($prod2Quantity % 2 == 0) {
$prod2Quantity -= 1;
}
Cart::addProduct($product1->id, [
'_token' => session('_token'),
'product_id' => $product1->id,
'quantity' => 1,
]);
$I->amOnPage('/checkout/cart');
$I->see('Tax ' . $tax1->tax_rate . ' %', '#taxrate-' . core()->taxRateAsIdentifier($tax1->tax_rate));
$I->see(
core()->currency(round($product1->price * $tax1->tax_rate / 100, 2)),
'#basetaxamount-' . core()->taxRateAsIdentifier($tax1->tax_rate)
);
Cart::addProduct($product1->id, [
'_token' => session('_token'),
'product_id' => $product1->id,
'quantity' => $prod1Quantity,
]);
$I->amOnPage('/checkout/cart');
$I->see('Tax ' . $tax1->tax_rate . ' %', '#taxrate-' . core()->taxRateAsIdentifier($tax1->tax_rate));
$I->see(
core()->currency(round(($prod1Quantity + 1) * $product1->price * $tax1->tax_rate / 100, 2)),
'#basetaxamount-' . core()->taxRateAsIdentifier($tax1->tax_rate)
);
Cart::addProduct($product2->id, [
'_token' => session('_token'),
'product_id' => $product2->id,
'quantity' => $prod2Quantity,
]);
$I->amOnPage('/checkout/cart');
$I->see('Tax ' . $tax1->tax_rate . ' %', '#taxrate-' . core()->taxRateAsIdentifier($tax1->tax_rate));
$taxAmount1 = round(($prod1Quantity + 1) * $product1->price * $tax1->tax_rate / 100, 2);
$I->see(core()->currency($taxAmount1), '#basetaxamount-' . core()->taxRateAsIdentifier($tax1->tax_rate));
$I->see('Tax ' . $tax2->tax_rate . ' %', '#taxrate-' . core()->taxRateAsIdentifier($tax2->tax_rate));
$taxAmount2 = round($prod2Quantity * $product2->price * $tax2->tax_rate / 100, 2);
$I->see(core()->currency($taxAmount2), '#basetaxamount-' . core()->taxRateAsIdentifier($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);
Cart::removeItem($cart->items[1]->id);
$I->amOnPage('/checkout/cart');
$I->amOnPage('/checkout/cart');
$I->see('Tax ' . $tax1->tax_rate . ' %', '#taxrate-' . core()->taxRateAsIdentifier($tax1->tax_rate));
$taxAmount1 = round(($prod1Quantity + 1) * $product1->price * $tax1->tax_rate / 100, 2);
$I->see(core()->currency($taxAmount1), '#basetaxamount-' . core()->taxRateAsIdentifier($tax1->tax_rate));
$I->dontSee('Tax ' . $tax2->tax_rate . ' %', '#taxrate-' . core()->taxRateAsIdentifier($tax2->tax_rate));
$taxAmount2 = round($prod2Quantity * $product2->price * $tax2->tax_rate / 100, 2);
$I->dontSee(core()->currency($taxAmount2), '#basetaxamount-' . core()->taxRateAsIdentifier($tax2->tax_rate));
$cart = Cart::getCart();
$I->assertEquals(1, $cart->items_count);
$I->assertEquals((float)($prod1Quantity + 1), $cart->items_qty);
$I->assertEquals($taxAmount1, $cart->tax_total);
}
public function checkCartWithMultipleZipRangeBasedTaxes(FunctionalTester $I): void
{
$tax11 = $I->have(TaxRate::class, [
'country' => $this->country,
'is_zip' => 1,
'zip_code' => null,
'zip_from' => '00000',
'zip_to' => '49999',
'tax_rate' => $I->fake()->randomFloat(2, 3, 8),
]);
$tax12 = $I->have(TaxRate::class, [
'country' => $this->country,
'is_zip' => 1,
'zip_code' => null,
'zip_from' => '50000',
'zip_to' => '89999',
'tax_rate' => $I->fake()->randomFloat(2, 3, 8),
]);
$taxCategorie1 = $I->have(TaxCategory::class);
$I->have(TaxMap::class, [
'tax_rate_id' => $tax11->id,
'tax_category_id' => $taxCategorie1->id,
]);
$I->have(TaxMap::class, [
'tax_rate_id' => $tax12->id,
'tax_category_id' => $taxCategorie1->id,
]);
$tax21 = $I->have(TaxRate::class, [
'country' => $this->country,
'is_zip' => 1,
'zip_code' => null,
'zip_from' => '00000',
'zip_to' => '49999',
'tax_rate' => $I->fake()->randomFloat(2, 14, 25),
]);
$tax22 = $I->have(TaxRate::class, [
'country' => $this->country,
'is_zip' => 1,
'zip_code' => null,
'zip_from' => '50000',
'zip_to' => '89999',
'tax_rate' => $I->fake()->randomFloat(2, 14, 25),
]);
$taxCategorie2 = $I->have(TaxCategory::class);
$I->have(TaxMap::class, [
'tax_rate_id' => $tax21->id,
'tax_category_id' => $taxCategorie2->id,
]);
$I->have(TaxMap::class, [
'tax_rate_id' => $tax22->id,
'tax_category_id' => $taxCategorie2->id,
]);
$config1 = [
'productInventory' => ['qty' => 100],
'attributeValues' => [
'status' => true,
'new' => 1,
'tax_category_id' => $taxCategorie1->id,
],
];
$product1 = $I->haveProduct(Laravel5Helper::SIMPLE_PRODUCT, $config1);
$config2 = [
'productInventory' => ['qty' => 100],
'attributeValues' => [
'status' => true,
'new' => 1,
'tax_category_id' => $taxCategorie2->id,
],
];
$product2 = $I->haveProduct(Laravel5Helper::SIMPLE_PRODUCT, $config2);
$customer = $I->have(Customer::class);
$addressZip012345 = $I->have(CustomerAddress::class, [
'customer_id' => $customer->id,
'postcode' => '012345',
'vat_id' => 'DE123456789',
'country' => $this->country,
'default_address' => 1,
]);
Cart::addProduct($product1->id, [
'_token' => session('_token'),
'product_id' => $product1->id,
'quantity' => 1,
]);
Cart::saveCustomerAddress(
[
'billing' => [
'address1' => $addressZip012345->address1,
'use_for_shipping' => 1,
'email' => $customer->email,
'company_name' => $addressZip012345->company_name,
'first_name' => $addressZip012345->first_name,
'last_name' => $addressZip012345->last_name,
'city' => $addressZip012345->city,
'state' => $addressZip012345->state,
'postcode' => $addressZip012345->postcode,
'country' => $addressZip012345->country,
],
'shipping' => [
'address1' => '',
],
]);
$I->wantToTest('customer address with postcode in range of 00000 - 49999');
$I->amOnPage('/checkout/cart');
$I->see('Tax ' . $tax11->tax_rate . ' %', '#taxrate-' . core()->taxRateAsIdentifier($tax11->tax_rate));
$I->see(
core()->currency(round($product1->price * $tax11->tax_rate / 100, 2)),
'#basetaxamount-' . core()->taxRateAsIdentifier($tax11->tax_rate)
);
$I->dontSee('Tax ' . $tax12->tax_rate . ' %', '#taxrate-' . core()->taxRateAsIdentifier($tax12->tax_rate));
$I->dontSee(
core()->currency(round($product1->price * $tax12->tax_rate / 100, 2)),
'#basetaxamount-' . core()->taxRateAsIdentifier($tax12->tax_rate)
);
$I->dontSee('Tax ' . $tax21->tax_rate . ' %', '#taxrate-' . core()->taxRateAsIdentifier($tax21->tax_rate));
$I->dontSee(
core()->currency(round($product2->price * $tax21->tax_rate / 100, 2)),
'#basetaxamount-' . core()->taxRateAsIdentifier($tax21->tax_rate)
);
$I->dontSee('Tax ' . $tax22->tax_rate . ' %', '#taxrate-' . core()->taxRateAsIdentifier($tax22->tax_rate));
$I->dontSee(
core()->currency(round($product2->price * $tax22->tax_rate / 100, 2)),
'#basetaxamount-' . core()->taxRateAsIdentifier($tax22->tax_rate)
);
Cart::addProduct($product2->id, [
'_token' => session('_token'),
'product_id' => $product2->id,
'quantity' => 1,
]);
$I->amOnPage('/checkout/cart');
$I->see('Tax ' . $tax11->tax_rate . ' %', '#taxrate-' . core()->taxRateAsIdentifier($tax11->tax_rate));
$I->see(
core()->currency(round($product1->price * $tax11->tax_rate / 100, 2)),
'#basetaxamount-' . core()->taxRateAsIdentifier($tax11->tax_rate)
);
$I->dontSee('Tax ' . $tax12->tax_rate . ' %', '#taxrate-' . core()->taxRateAsIdentifier($tax12->tax_rate));
$I->dontSee(
core()->currency(round($product1->price * $tax12->tax_rate / 100, 2)),
'#basetaxamount-' . core()->taxRateAsIdentifier($tax12->tax_rate)
);
$I->see('Tax ' . $tax21->tax_rate . ' %', '#taxrate-' . core()->taxRateAsIdentifier($tax21->tax_rate));
$I->see(
core()->currency(round($product2->price * $tax21->tax_rate / 100, 2)),
'#basetaxamount-' . core()->taxRateAsIdentifier($tax21->tax_rate)
);
$I->dontSee('Tax ' . $tax22->tax_rate . ' %', '#taxrate-' . core()->taxRateAsIdentifier($tax22->tax_rate));
$I->dontSee(
core()->currency(round($product2->price * $tax22->tax_rate / 100, 2)),
'#basetaxamount-' . core()->taxRateAsIdentifier($tax22->tax_rate)
);
$taxAmount1 = round($product1->price * $tax11->tax_rate / 100, 2);
$I->see(core()->currency($taxAmount1), '#basetaxamount-' . core()->taxRateAsIdentifier($tax11->tax_rate));
$taxAmount2 = round($product2->price * $tax21->tax_rate / 100, 2);
$I->see(core()->currency($taxAmount2), '#basetaxamount-' . core()->taxRateAsIdentifier($tax21->tax_rate));
$I->wantToTest('customer address with postcode in range of 50000 - 89999');
$addressZip67890 = $I->have(CustomerAddress::class, [
'customer_id' => $customer->id,
'postcode' => '67890',
'vat_id' => 'DE123456789',
'country' => $this->country,
'default_address' => 1,
]);
Cart::saveCustomerAddress(
[
'billing' => [
'address1' => $addressZip67890->address1,
'use_for_shipping' => 1,
'email' => $customer->email,
'company_name' => $addressZip67890->company_name,
'first_name' => $addressZip67890->first_name,
'last_name' => $addressZip67890->last_name,
'city' => $addressZip67890->city,
'state' => $addressZip67890->state,
'postcode' => $addressZip67890->postcode,
'country' => $addressZip67890->country,
],
'shipping' => [
'address1' => '',
],
]);
$I->amOnPage('/checkout/cart');
$I->dontSee('Tax ' . $tax11->tax_rate . ' %', '#taxrate-' . core()->taxRateAsIdentifier($tax11->tax_rate));
$I->dontSee(
core()->currency(round($product1->price * $tax11->tax_rate / 100, 2)),
'#basetaxamount-' . core()->taxRateAsIdentifier($tax11->tax_rate)
);
$I->see('Tax ' . $tax12->tax_rate . ' %', '#taxrate-' . core()->taxRateAsIdentifier($tax12->tax_rate));
$I->see(
core()->currency(round($product1->price * $tax12->tax_rate / 100, 2)),
'#basetaxamount-' . core()->taxRateAsIdentifier($tax12->tax_rate)
);
$I->dontSee('Tax ' . $tax21->tax_rate . ' %', '#taxrate-' . core()->taxRateAsIdentifier($tax21->tax_rate));
$I->dontSee(
core()->currency(round($product2->price * $tax21->tax_rate / 100, 2)),
'#basetaxamount-' . core()->taxRateAsIdentifier($tax21->tax_rate)
);
$I->see('Tax ' . $tax22->tax_rate . ' %', '#taxrate-' . core()->taxRateAsIdentifier($tax22->tax_rate));
$I->see(
core()->currency(round($product2->price * $tax22->tax_rate / 100, 2)),
'#basetaxamount-' . core()->taxRateAsIdentifier($tax22->tax_rate)
);
$taxAmount1 = round($product1->price * $tax12->tax_rate / 100, 2);
$I->see(core()->currency($taxAmount1), '#basetaxamount-' . core()->taxRateAsIdentifier($tax12->tax_rate));
$taxAmount2 = round($product2->price * $tax22->tax_rate / 100, 2);
$I->see(core()->currency($taxAmount2), '#basetaxamount-' . core()->taxRateAsIdentifier($tax22->tax_rate));
$I->wantToTest('customer address with postcode in range of 90000 - 99000');
$I->wanttoTest('as we dont have any taxes in this zip range');
$addressZip98765 = $I->have(CustomerAddress::class, [
'customer_id' => $customer->id,
'postcode' => '98765',
'vat_id' => 'DE123456789',
'country' => $this->country,
'default_address' => 1,
]);
Cart::saveCustomerAddress(
[
'billing' => [
'address1' => $addressZip98765->address1,
'use_for_shipping' => 1,
'email' => $customer->email,
'company_name' => $addressZip98765->company_name,
'first_name' => $addressZip98765->first_name,
'last_name' => $addressZip98765->last_name,
'city' => $addressZip98765->city,
'state' => $addressZip98765->state,
'postcode' => $addressZip98765->postcode,
'country' => $addressZip98765->country,
],
'shipping' => [
'address1' => '',
],
]);
$I->amOnPage('/checkout/cart');
$I->dontSee('Tax ' . $tax11->tax_rate . ' %', '#taxrate-' . core()->taxRateAsIdentifier($tax11->tax_rate));
$I->dontSee(
core()->currency(round($product1->price * $tax11->tax_rate / 100, 2)),
'#basetaxamount-' . core()->taxRateAsIdentifier($tax11->tax_rate)
);
$I->dontSee('Tax ' . $tax12->tax_rate . ' %', '#taxrate-' . core()->taxRateAsIdentifier($tax12->tax_rate));
$I->dontSee(
core()->currency(round($product1->price * $tax12->tax_rate / 100, 2)),
'#basetaxamount-' . core()->taxRateAsIdentifier($tax12->tax_rate)
);
$I->dontSee('Tax ' . $tax21->tax_rate . ' %', '#taxrate-' . core()->taxRateAsIdentifier($tax21->tax_rate));
$I->dontSee(
core()->currency(round($product2->price * $tax21->tax_rate / 100, 2)),
'#basetaxamount-' . core()->taxRateAsIdentifier($tax21->tax_rate)
);
$I->dontSee('Tax ' . $tax22->tax_rate . ' %', '#taxrate-' . core()->taxRateAsIdentifier($tax22->tax_rate));
$I->dontSee(
core()->currency(round($product2->price * $tax22->tax_rate / 100, 2)),
'#basetaxamount-' . core()->taxRateAsIdentifier($tax22->tax_rate)
);
}
}

View File

@ -1,6 +1,6 @@
<?php
namespace Tests\Webkul\Unit\Shop;
namespace Tests\Functional\Shop;
use Codeception\Example;
use FunctionalTester;
@ -35,10 +35,10 @@ class GuestCheckoutCest
],
];
$this->productNoGuestCheckout = $I->haveProduct(Laravel5Helper::SIMPLE_PRODUCT, $pConfigDefault, ['simple']);
$this->productNoGuestCheckout = $I->haveProduct(Laravel5Helper::SIMPLE_PRODUCT, $pConfigDefault);
$this->productNoGuestCheckout->refresh();
$this->productGuestCheckout = $I->haveProduct(Laravel5Helper::SIMPLE_PRODUCT, $pConfigGuestCheckout, ['simple']);
$this->productGuestCheckout = $I->haveProduct(Laravel5Helper::SIMPLE_PRODUCT, $pConfigGuestCheckout);
$this->productGuestCheckout->refresh();
}

View File

@ -3,34 +3,46 @@
namespace Tests\Unit\Checkout\Cart\Controllers;
use UnitTester;
use Codeception\Example;
use Webkul\Checkout\Models\Cart;
use Webkul\Shop\Http\Controllers\CartController;
class CartControllerCest
{
public function _before(UnitTester $I)
/**
* @param \UnitTester $I
*
* @param \Example $scenario
*
* @throws \Exception
* @dataProvider getOnWarningAddingToCartScenarios
*/
public function testOnWarningAddingToCart(UnitTester $I, Example $scenario): void
{
$I->assertEquals($scenario['expected'],
$I->executeFunction(
CartController::class,
'onWarningAddingToCart',
[$scenario['result']]
)
);
}
public function testOnWarningAddingToCart(UnitTester $I)
protected function getOnWarningAddingToCartScenarios(): array
{
$scenarios = [
return [
[
'result' => ['key' => 'value', 'warning' => 'Hello World. Something went wrong.'],
'result' => ['key' => 'value', 'warning' => 'Hello World. Something went wrong.'],
'expected' => true,
],
[
'result' => ['key' => 'value'],
'result' => ['key' => 'value'],
'expected' => false,
],
[
'result' => new Cart(),
'result' => new Cart(),
'expected' => false,
],
];
foreach ($scenarios as $scenario) {
$I->assertEquals($scenario['expected'], $I->executeFunction(CartController::class, 'onWarningAddingToCart', [$scenario['result']]));
}
}
}

View File

@ -0,0 +1,52 @@
<?php
namespace Tests\Unit\Core;
use UnitTester;
use Codeception\Example;
class CoreCest
{
/**
* @param \UnitTester $I
*
* @param \Codeception\Example $scenario
*
* @throws \Exception
* @dataProvider getTaxRateScenarios
*
*/
public function testTaxRateAsIdentifier(UnitTester $I, Example $scenario): void
{
$I->assertEquals(
$scenario['expected'],
$I->executeFunction(
\Webkul\Core\Core::class,
'taxRateAsIdentifier',
[$scenario['input']]
)
);
}
protected function getTaxRateScenarios(): array
{
return [
[
'input' => 0,
'expected' => '0',
],
[
'input' => 0.01,
'expected' => '0_01',
],
[
'input' => .12,
'expected' => '0_12',
],
[
'input' => 1234.5678,
'expected' => '1234_5678',
],
];
}
}

View File

@ -0,0 +1,113 @@
<?php
namespace Tests\Unit\Tax\Helpers;
use Faker\Factory;
use Illuminate\Support\Facades\Config;
use UnitTester;
use Webkul\Tax\Models\TaxCategory;
use Webkul\Tax\Models\TaxMap;
use Webkul\Tax\Models\TaxRate;
use Cart;
class TaxCest
{
public $scenario;
public function _before(UnitTester $I)
{
$country = strtoupper(Config::get('app.default_country')) ?? 'DE';
$tax1 = $I->have(TaxRate::class, [
'country' => $country,
]);
$taxCategorie1 = $I->have(TaxCategory::class);
$I->have(TaxMap::class, [
'tax_rate_id' => $tax1->id,
'tax_category_id' => $taxCategorie1->id,
]);
$tax2 = $I->have(TaxRate::class, [
'country' => $country,
]);
$taxCategorie2 = $I->have(TaxCategory::class);
$I->have(TaxMap::class, [
'tax_rate_id' => $tax2->id,
'tax_category_id' => $taxCategorie2->id,
]);
$config1 = [
'productInventory' => ['qty' => 100],
'attributeValues' => [
'status' => true,
'new' => 1,
'tax_category_id' => $taxCategorie1->id,
],
];
$product1 = $I->haveProduct(\Webkul\Core\Helpers\Laravel5Helper::SIMPLE_PRODUCT, $config1);
$config2 = [
'productInventory' => ['qty' => 100],
'attributeValues' => [
'status' => true,
'new' => 1,
'tax_category_id' => $taxCategorie2->id,
],
];
$product2 = $I->haveProduct(\Webkul\Core\Helpers\Laravel5Helper::SIMPLE_PRODUCT, $config2);
Cart::addProduct($product1->id, [
'_token' => session('_token'),
'product_id' => $product1->id,
'quantity' => 11,
]);
Cart::addProduct($product2->id, [
'_token' => session('_token'),
'product_id' => $product2->id,
'quantity' => 7,
]);
$this->scenario = [
'object' => Cart::getCart(),
'expectedTaxRates' => [
(string)round((float)$tax1->tax_rate, \Webkul\Tax\Helpers\Tax::TAX_PRECISION)
=> round(11 * $product1->price * $tax1->tax_rate / 100, 4),
(string)round((float)$tax2->tax_rate, \Webkul\Tax\Helpers\Tax::TAX_PRECISION)
=> round(7 * $product2->price * $tax2->tax_rate / 100, 4),
],
'expectedTaxTotal' =>
round(
round(11 * $product1->price * $tax1->tax_rate / 100, 2)
+ round(7 * $product2->price * $tax2->tax_rate / 100, 2)
, 2),
];
}
public function testGetTaxRatesWithAmount(UnitTester $I)
{
$result = $I->executeFunction(
\Webkul\Tax\Helpers\Tax::class,
'getTaxRatesWithAmount',
[$this->scenario['object'], false]
);
foreach ($result as $taxRate => $taxAmount) {
$I->assertTrue(array_key_exists($taxRate, $result));
$I->assertEquals($this->scenario['expectedTaxRates'][$taxRate], $taxAmount);
}
}
public function testGetTaxTotal(UnitTester $I)
{
$result = $I->executeFunction(
\Webkul\Tax\Helpers\Tax::class,
'getTaxTotal',
[$this->scenario['object'], false]
);
$I->assertEquals($this->scenario['expectedTaxTotal'], $result);
}
}