commit
d25c9bbec0
|
|
@ -19,7 +19,7 @@ DB_PREFIX=
|
||||||
BROADCAST_DRIVER=log
|
BROADCAST_DRIVER=log
|
||||||
CACHE_DRIVER=file
|
CACHE_DRIVER=file
|
||||||
SESSION_DRIVER=file
|
SESSION_DRIVER=file
|
||||||
SESSION_LIFETIME=20
|
SESSION_LIFETIME=120
|
||||||
QUEUE_DRIVER=sync
|
QUEUE_DRIVER=sync
|
||||||
|
|
||||||
REDIS_HOST=127.0.0.1
|
REDIS_HOST=127.0.0.1
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
#### This changelog consists the bug & security fixes and new features being included in the releases listed below.
|
#### 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.
|
* #2377 [fixed] - Getting exception on creating a new category under any other category.
|
||||||
|
|
||||||
|
|
@ -48,6 +48,8 @@
|
||||||
|
|
||||||
* #2439 [fixed] - can't process for further checkout steps until all the address line filled.
|
* #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.
|
* #2440 [fixed] - Advertisement Three Images is not working.
|
||||||
|
|
||||||
* #2449 [fixed] - error clicking empty cart.
|
* #2449 [fixed] - error clicking empty cart.
|
||||||
|
|
@ -56,6 +58,10 @@
|
||||||
|
|
||||||
* #2459 [fixed] - shipping address field warning for guest customer not translated.
|
* #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.
|
* #2469 [fixed] - Displaying wrong amount for bundle product in cart.
|
||||||
|
|
||||||
* #2479 [fixed] - showing total review in recent view product list.
|
* #2479 [fixed] - showing total review in recent view product list.
|
||||||
|
|
@ -70,6 +76,16 @@
|
||||||
|
|
||||||
* #2494 [fixed] - Product total inventory for all locale is showing wrong.
|
* #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*
|
## **v1.0.0-BETA1(5th of February 2020)** - *Release*
|
||||||
|
|
||||||
* [feature] Updated to laravel version 6.
|
* [feature] Updated to laravel version 6.
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,8 @@ printf "### start preparation ###\n"
|
||||||
printf ">> truncate and migrate database\n"
|
printf ">> truncate and migrate database\n"
|
||||||
php artisan migrate:fresh --env=testing --quiet
|
php artisan migrate:fresh --env=testing --quiet
|
||||||
|
|
||||||
|
printf ">> cleaning previous tests ###\n"
|
||||||
|
${WORKPATH}/../vendor/bin/codecept clean
|
||||||
printf "### finish preparation ###\n"
|
printf "### finish preparation ###\n"
|
||||||
|
|
||||||
printf "### start tests ###\n"
|
printf "### start tests ###\n"
|
||||||
|
|
|
||||||
|
|
@ -33,17 +33,17 @@
|
||||||
"maatwebsite/excel": "3.1.18",
|
"maatwebsite/excel": "3.1.18",
|
||||||
"nwidart/laravel-modules": "^3.2",
|
"nwidart/laravel-modules": "^3.2",
|
||||||
"prettus/l5-repository": "^2.6",
|
"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": {
|
"require-dev": {
|
||||||
"barryvdh/laravel-debugbar": "^3.1",
|
|
||||||
"codeception/codeception": "^4.0",
|
"codeception/codeception": "^4.0",
|
||||||
"codeception/module-asserts": "^1.1",
|
"codeception/module-asserts": "^1.1",
|
||||||
"codeception/module-filesystem": "^1.0",
|
"codeception/module-filesystem": "^1.0",
|
||||||
"codeception/module-laravel5": "^1.0",
|
"codeception/module-laravel5": "^1.0",
|
||||||
"filp/whoops": "^2.0",
|
"filp/whoops": "^2.0",
|
||||||
"fzaninotto/faker": "^1.4",
|
|
||||||
"laravel/dusk": "^5.7.0",
|
"laravel/dusk": "^5.7.0",
|
||||||
"mockery/mockery": "^1.0",
|
"mockery/mockery": "^1.0",
|
||||||
"nunomaduro/collision": "^2.0",
|
"nunomaduro/collision": "^2.0",
|
||||||
|
|
|
||||||
File diff suppressed because it is too large
Load Diff
|
|
@ -102,6 +102,8 @@ return [
|
||||||
| Ensure it is uppercase and reflects the 'code' column of the
|
| Ensure it is uppercase and reflects the 'code' column of the
|
||||||
| countries table.
|
| countries table.
|
||||||
|
|
|
|
||||||
|
| for example: DE EN FR
|
||||||
|
| (use capital letters!)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
'default_country' => null,
|
'default_country' => null,
|
||||||
|
|
|
||||||
|
|
@ -98,6 +98,10 @@ class CartController extends Controller
|
||||||
*/
|
*/
|
||||||
public function store($id)
|
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);
|
Event::dispatch('checkout.cart.item.add.before', $id);
|
||||||
|
|
||||||
$result = Cart::addProduct($id, request()->except('_token'));
|
$result = Cart::addProduct($id, request()->except('_token'));
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,12 @@ class Cart extends JsonResource
|
||||||
*/
|
*/
|
||||||
public function toArray($request)
|
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 [
|
return [
|
||||||
'id' => $this->id,
|
'id' => $this->id,
|
||||||
'customer_email' => $this->customer_email,
|
'customer_email' => $this->customer_email,
|
||||||
|
|
@ -60,6 +66,31 @@ class Cart extends JsonResource
|
||||||
'shipping_address' => new CartAddress($this->shipping_address),
|
'shipping_address' => new CartAddress($this->shipping_address),
|
||||||
'created_at' => $this->created_at,
|
'created_at' => $this->created_at,
|
||||||
'updated_at' => $this->updated_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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -344,11 +344,14 @@
|
||||||
</tr>
|
</tr>
|
||||||
@endif
|
@endif
|
||||||
|
|
||||||
<tr class="border">
|
@php ($taxRates = Webkul\Tax\Helpers\Tax::getTaxRatesWithAmount($order, true))
|
||||||
<td>{{ __('admin::app.sales.orders.tax') }}</td>
|
@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>-</td>
|
||||||
<td>{{ core()->formatBasePrice($order->base_tax_amount) }}</td>
|
<td id="basetaxamount-{{ core()->taxRateAsIdentifier($taxRate) }}">{{ core()->formatBasePrice($baseTaxAmount) }}</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
@endforeach
|
||||||
|
|
||||||
<tr class="bold">
|
<tr class="bold">
|
||||||
<td>{{ __('admin::app.sales.orders.grand-total') }}</td>
|
<td>{{ __('admin::app.sales.orders.grand-total') }}</td>
|
||||||
|
|
|
||||||
|
|
@ -32,6 +32,6 @@ class CreateCartruleCustomersTable extends Migration
|
||||||
*/
|
*/
|
||||||
public function down()
|
public function down()
|
||||||
{
|
{
|
||||||
Schema::dropIfExists('cartrule_customers');
|
Schema::dropIfExists('cart_rule_customers');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -36,6 +36,6 @@ class CreateCartruleCouponsTable extends Migration
|
||||||
*/
|
*/
|
||||||
public function down()
|
public function down()
|
||||||
{
|
{
|
||||||
Schema::dropIfExists('cartrule_coupons');
|
Schema::dropIfExists('cart_rule_coupons');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ use Webkul\CartRule\Repositories\CartRuleCouponRepository;
|
||||||
/**
|
/**
|
||||||
* Cart Rule controller
|
* 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)
|
* @copyright 2018 Webkul Software Pvt Ltd (http://www.webkul.com)
|
||||||
*/
|
*/
|
||||||
class CartRuleController extends Controller
|
class CartRuleController extends Controller
|
||||||
|
|
@ -39,8 +39,9 @@ class CartRuleController extends Controller
|
||||||
/**
|
/**
|
||||||
* Create a new controller instance.
|
* Create a new controller instance.
|
||||||
*
|
*
|
||||||
* @param \Webkul\CartRule\Repositories\CartRuleRepository $cartRuleRepository
|
* @param \Webkul\CartRule\Repositories\CartRuleRepository $cartRuleRepository
|
||||||
* @param \Webkul\CartRule\Repositories\CartRuleCouponRepository $cartRuleCouponRepository
|
* @param \Webkul\CartRule\Repositories\CartRuleCouponRepository $cartRuleCouponRepository
|
||||||
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function __construct(
|
public function __construct(
|
||||||
|
|
@ -83,16 +84,16 @@ class CartRuleController extends Controller
|
||||||
public function store()
|
public function store()
|
||||||
{
|
{
|
||||||
$this->validate(request(), [
|
$this->validate(request(), [
|
||||||
'name' => 'required',
|
'name' => 'required',
|
||||||
'channels' => 'required|array|min:1',
|
'channels' => 'required|array|min:1',
|
||||||
'customer_groups' => 'required|array|min:1',
|
'customer_groups' => 'required|array|min:1',
|
||||||
'coupon_type' => 'required',
|
'coupon_type' => 'required',
|
||||||
'use_auto_generation' => 'required_if:coupon_type,==,1',
|
'use_auto_generation' => 'required_if:coupon_type,==,1',
|
||||||
'coupon_code' => 'required_if:use_auto_generation,==,0',
|
'coupon_code' => 'required_if:use_auto_generation,==,0',
|
||||||
'starts_from' => 'nullable|date',
|
'starts_from' => 'nullable|date',
|
||||||
'ends_till' => 'nullable|date|after_or_equal:starts_from',
|
'ends_till' => 'nullable|date|after_or_equal:starts_from',
|
||||||
'action_type' => 'required',
|
'action_type' => 'required',
|
||||||
'discount_amount' => 'required|numeric'
|
'discount_amount' => 'required|numeric',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$data = request()->all();
|
$data = request()->all();
|
||||||
|
|
@ -112,6 +113,7 @@ class CartRuleController extends Controller
|
||||||
* Show the form for editing the specified resource.
|
* Show the form for editing the specified resource.
|
||||||
*
|
*
|
||||||
* @param int $id
|
* @param int $id
|
||||||
|
*
|
||||||
* @return \Illuminate\Http\Response
|
* @return \Illuminate\Http\Response
|
||||||
*/
|
*/
|
||||||
public function edit($id)
|
public function edit($id)
|
||||||
|
|
@ -124,23 +126,24 @@ class CartRuleController extends Controller
|
||||||
/**
|
/**
|
||||||
* Update the specified resource in storage.
|
* Update the specified resource in storage.
|
||||||
*
|
*
|
||||||
* @param \Illuminate\Http\Request $request
|
* @param \Illuminate\Http\Request $request
|
||||||
* @param int $id
|
* @param int $id
|
||||||
|
*
|
||||||
* @return \Illuminate\Http\Response
|
* @return \Illuminate\Http\Response
|
||||||
*/
|
*/
|
||||||
public function update(Request $request, $id)
|
public function update(Request $request, $id)
|
||||||
{
|
{
|
||||||
$this->validate(request(), [
|
$this->validate(request(), [
|
||||||
'name' => 'required',
|
'name' => 'required',
|
||||||
'channels' => 'required|array|min:1',
|
'channels' => 'required|array|min:1',
|
||||||
'customer_groups' => 'required|array|min:1',
|
'customer_groups' => 'required|array|min:1',
|
||||||
'coupon_type' => 'required',
|
'coupon_type' => 'required',
|
||||||
'use_auto_generation' => 'required_if:coupon_type,==,1',
|
'use_auto_generation' => 'required_if:coupon_type,==,1',
|
||||||
'coupon_code' => 'required_if:use_auto_generation,==,0',
|
'coupon_code' => 'required_if:use_auto_generation,==,0',
|
||||||
'starts_from' => 'nullable|date',
|
'starts_from' => 'nullable|date',
|
||||||
'ends_till' => 'nullable|date|after_or_equal:starts_from',
|
'ends_till' => 'nullable|date|after_or_equal:starts_from',
|
||||||
'action_type' => 'required',
|
'action_type' => 'required',
|
||||||
'discount_amount' => 'required|numeric'
|
'discount_amount' => 'required|numeric',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$cartRule = $this->cartRuleRepository->findOrFail($id);
|
$cartRule = $this->cartRuleRepository->findOrFail($id);
|
||||||
|
|
@ -159,7 +162,8 @@ class CartRuleController extends Controller
|
||||||
/**
|
/**
|
||||||
* Remove the specified resource from storage.
|
* Remove the specified resource from storage.
|
||||||
*
|
*
|
||||||
* @param int $id
|
* @param int $id
|
||||||
|
*
|
||||||
* @return \Illuminate\Http\Response
|
* @return \Illuminate\Http\Response
|
||||||
*/
|
*/
|
||||||
public function destroy($id)
|
public function destroy($id)
|
||||||
|
|
@ -176,7 +180,7 @@ class CartRuleController extends Controller
|
||||||
session()->flash('success', trans('admin::app.response.delete-success', ['name' => 'Cart Rule']));
|
session()->flash('success', trans('admin::app.response.delete-success', ['name' => 'Cart Rule']));
|
||||||
|
|
||||||
return response()->json(['message' => true], 200);
|
return response()->json(['message' => true], 200);
|
||||||
} catch(\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
session()->flash('error', trans('admin::app.response.delete-failed', ['name' => 'Cart Rule']));
|
session()->flash('error', trans('admin::app.response.delete-failed', ['name' => 'Cart Rule']));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -191,9 +195,9 @@ class CartRuleController extends Controller
|
||||||
public function generateCoupons()
|
public function generateCoupons()
|
||||||
{
|
{
|
||||||
$this->validate(request(), [
|
$this->validate(request(), [
|
||||||
'coupon_qty' => 'required|integer|min:1',
|
'coupon_qty' => 'required|integer|min:1',
|
||||||
'code_length' => 'required|integer|min:10',
|
'code_length' => 'required|integer|min:10',
|
||||||
'code_format' => 'required'
|
'code_format' => 'required',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
if (! request('id'))
|
if (! request('id'))
|
||||||
|
|
|
||||||
|
|
@ -125,9 +125,9 @@ class CartRuleRepository extends Repository
|
||||||
*/
|
*/
|
||||||
public function create(array $data)
|
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;
|
$data['status'] = ! isset($data['status']) ? 0 : 1;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,9 @@ namespace Webkul\Checkout;
|
||||||
use Webkul\Checkout\Repositories\CartRepository;
|
use Webkul\Checkout\Repositories\CartRepository;
|
||||||
use Webkul\Checkout\Repositories\CartItemRepository;
|
use Webkul\Checkout\Repositories\CartItemRepository;
|
||||||
use Webkul\Checkout\Repositories\CartAddressRepository;
|
use Webkul\Checkout\Repositories\CartAddressRepository;
|
||||||
|
use Webkul\Customer\Models\CustomerAddress;
|
||||||
use Webkul\Product\Repositories\ProductRepository;
|
use Webkul\Product\Repositories\ProductRepository;
|
||||||
|
use Webkul\Tax\Helpers\Tax;
|
||||||
use Webkul\Tax\Repositories\TaxCategoryRepository;
|
use Webkul\Tax\Repositories\TaxCategoryRepository;
|
||||||
use Webkul\Checkout\Models\CartItem;
|
use Webkul\Checkout\Models\CartItem;
|
||||||
use Webkul\Checkout\Models\CartPayment;
|
use Webkul\Checkout\Models\CartPayment;
|
||||||
|
|
@ -21,7 +23,8 @@ use Illuminate\Support\Arr;
|
||||||
* @author Jitendra Singh <jitendra@webkul.com>
|
* @author Jitendra Singh <jitendra@webkul.com>
|
||||||
* @copyright 2018 Webkul Software Pvt Ltd (http://www.webkul.com)
|
* @copyright 2018 Webkul Software Pvt Ltd (http://www.webkul.com)
|
||||||
*/
|
*/
|
||||||
class Cart {
|
class Cart
|
||||||
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* CartRepository instance
|
* CartRepository instance
|
||||||
|
|
@ -75,15 +78,16 @@ class Cart {
|
||||||
/**
|
/**
|
||||||
* Create a new controller instance.
|
* Create a new controller instance.
|
||||||
*
|
*
|
||||||
* @param Webkul\Checkout\Repositories\CartRepository $cart
|
* @param Webkul\Checkout\Repositories\CartRepository $cart
|
||||||
* @param Webkul\Checkout\Repositories\CartItemRepository $cartItem
|
* @param Webkul\Checkout\Repositories\CartItemRepository $cartItem
|
||||||
* @param Webkul\Checkout\Repositories\CartAddressRepository $cartAddress
|
* @param Webkul\Checkout\Repositories\CartAddressRepository $cartAddress
|
||||||
* @param Webkul\Product\Repositories\ProductRepository $product
|
* @param Webkul\Product\Repositories\ProductRepository $product
|
||||||
* @param Webkul\Product\Repositories\TaxCategoryRepository $taxCategory
|
* @param Webkul\Product\Repositories\TaxCategoryRepository $taxCategory
|
||||||
* @param Webkul\Product\Repositories\CustomerAddressRepository $customerAddress
|
* @param Webkul\Product\Repositories\CustomerAddressRepository $customerAddress
|
||||||
* @param Webkul\Product\Repositories\CustomerAddressRepository $customerAddress
|
* @param Webkul\Product\Repositories\CustomerAddressRepository $customerAddress
|
||||||
* @param Webkul\Discount\Repositories\CartRuleRepository $cartRule
|
* @param Webkul\Discount\Repositories\CartRuleRepository $cartRule
|
||||||
* @param Webkul\Helpers\Discount $discount
|
* @param Webkul\Helpers\Discount $discount
|
||||||
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function __construct(
|
public function __construct(
|
||||||
|
|
@ -94,8 +98,7 @@ class Cart {
|
||||||
TaxCategoryRepository $taxCategoryRepository,
|
TaxCategoryRepository $taxCategoryRepository,
|
||||||
WishlistRepository $wishlistRepository,
|
WishlistRepository $wishlistRepository,
|
||||||
CustomerAddressRepository $customerAddressRepository
|
CustomerAddressRepository $customerAddressRepository
|
||||||
)
|
) {
|
||||||
{
|
|
||||||
$this->cartRepository = $cartRepository;
|
$this->cartRepository = $cartRepository;
|
||||||
|
|
||||||
$this->cartItemRepository = $cartItemRepository;
|
$this->cartItemRepository = $cartItemRepository;
|
||||||
|
|
@ -128,6 +131,7 @@ class Cart {
|
||||||
*
|
*
|
||||||
* @param integer $productId
|
* @param integer $productId
|
||||||
* @param array $data
|
* @param array $data
|
||||||
|
*
|
||||||
* @return Mixed Cart on success, array with warning otherwise
|
* @return Mixed Cart on success, array with warning otherwise
|
||||||
*/
|
*/
|
||||||
public function addProduct($productId, $data)
|
public function addProduct($productId, $data)
|
||||||
|
|
@ -147,7 +151,7 @@ class Cart {
|
||||||
if (is_string($cartProducts)) {
|
if (is_string($cartProducts)) {
|
||||||
$this->collectTotals();
|
$this->collectTotals();
|
||||||
|
|
||||||
if (! count($cart->all_items) > 0) {
|
if (!count($cart->all_items) > 0) {
|
||||||
session()->forget('cart');
|
session()->forget('cart');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -162,11 +166,12 @@ class Cart {
|
||||||
$cartProduct['parent_id'] = $parentCartItem->id;
|
$cartProduct['parent_id'] = $parentCartItem->id;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (! $cartItem) {
|
if (!$cartItem) {
|
||||||
$cartItem = $this->cartItemRepository->create(array_merge($cartProduct, ['cart_id' => $cart->id]));
|
$cartItem = $this->cartItemRepository->create(array_merge($cartProduct, ['cart_id' => $cart->id]));
|
||||||
} else {
|
} else {
|
||||||
if (isset($cartProduct['parent_id']) && $cartItem->parent_id != $parentCartItem->id) {
|
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 {
|
} else {
|
||||||
if ($cartItem->product->getTypeInstance()->showQuantityBox() === false) {
|
if ($cartItem->product->getTypeInstance()->showQuantityBox() === false) {
|
||||||
return ['warning' => __('shop::app.checkout.cart.integrity.qty_impossible')];
|
return ['warning' => __('shop::app.checkout.cart.integrity.qty_impossible')];
|
||||||
|
|
@ -176,8 +181,9 @@ class Cart {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (! $parentCartItem)
|
if (!$parentCartItem) {
|
||||||
$parentCartItem = $cartItem;
|
$parentCartItem = $cartItem;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -192,17 +198,18 @@ class Cart {
|
||||||
* Create new cart instance.
|
* Create new cart instance.
|
||||||
*
|
*
|
||||||
* @param array $data
|
* @param array $data
|
||||||
|
*
|
||||||
* @return Cart|null
|
* @return Cart|null
|
||||||
*/
|
*/
|
||||||
public function create($data)
|
public function create($data)
|
||||||
{
|
{
|
||||||
$cartData = [
|
$cartData = [
|
||||||
'channel_id' => core()->getCurrentChannel()->id,
|
'channel_id' => core()->getCurrentChannel()->id,
|
||||||
'global_currency_code' => core()->getBaseCurrencyCode(),
|
'global_currency_code' => core()->getBaseCurrencyCode(),
|
||||||
'base_currency_code' => core()->getBaseCurrencyCode(),
|
'base_currency_code' => core()->getBaseCurrencyCode(),
|
||||||
'channel_currency_code' => core()->getChannelBaseCurrencyCode(),
|
'channel_currency_code' => core()->getChannelBaseCurrencyCode(),
|
||||||
'cart_currency_code' => core()->getCurrentCurrencyCode(),
|
'cart_currency_code' => core()->getCurrentCurrencyCode(),
|
||||||
'items_count' => 1
|
'items_count' => 1,
|
||||||
];
|
];
|
||||||
|
|
||||||
//Authentication details
|
//Authentication details
|
||||||
|
|
@ -218,7 +225,7 @@ class Cart {
|
||||||
|
|
||||||
$cart = $this->cartRepository->create($cartData);
|
$cart = $this->cartRepository->create($cartData);
|
||||||
|
|
||||||
if (! $cart) {
|
if (!$cart) {
|
||||||
session()->flash('error', trans('shop::app.checkout.cart.create-error'));
|
session()->flash('error', trans('shop::app.checkout.cart.create-error'));
|
||||||
|
|
||||||
return;
|
return;
|
||||||
|
|
@ -241,8 +248,9 @@ class Cart {
|
||||||
foreach ($data['qty'] as $itemId => $quantity) {
|
foreach ($data['qty'] as $itemId => $quantity) {
|
||||||
$item = $this->cartItemRepository->findOneByField('id', $itemId);
|
$item = $this->cartItemRepository->findOneByField('id', $itemId);
|
||||||
|
|
||||||
if (! $item)
|
if (!$item) {
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if ($quantity <= 0) {
|
if ($quantity <= 0) {
|
||||||
$this->removeItem($itemId);
|
$this->removeItem($itemId);
|
||||||
|
|
@ -252,18 +260,19 @@ class Cart {
|
||||||
|
|
||||||
$item->quantity = $quantity;
|
$item->quantity = $quantity;
|
||||||
|
|
||||||
if (! $this->isItemHaveQuantity($item))
|
if (!$this->isItemHaveQuantity($item)) {
|
||||||
throw new \Exception(trans('shop::app.checkout.cart.quantity.inventory_warning'));
|
throw new \Exception(trans('shop::app.checkout.cart.quantity.inventory_warning'));
|
||||||
|
}
|
||||||
|
|
||||||
Event::dispatch('checkout.cart.update.before', $item);
|
Event::dispatch('checkout.cart.update.before', $item);
|
||||||
|
|
||||||
$this->cartItemRepository->update([
|
$this->cartItemRepository->update([
|
||||||
'quantity' => $quantity,
|
'quantity' => $quantity,
|
||||||
'total' => core()->convertPrice($item->price * $quantity),
|
'total' => core()->convertPrice($item->price * $quantity),
|
||||||
'base_total' => $item->price * $quantity,
|
'base_total' => $item->price * $quantity,
|
||||||
'total_weight' => $item->weight * $quantity,
|
'total_weight' => $item->weight * $quantity,
|
||||||
'base_total_weight' => $item->weight * $quantity
|
'base_total_weight' => $item->weight * $quantity,
|
||||||
], $itemId);
|
], $itemId);
|
||||||
|
|
||||||
Event::dispatch('checkout.cart.update.after', $item);
|
Event::dispatch('checkout.cart.update.after', $item);
|
||||||
}
|
}
|
||||||
|
|
@ -277,6 +286,7 @@ class Cart {
|
||||||
* Get cart item by product
|
* Get cart item by product
|
||||||
*
|
*
|
||||||
* @param array $data
|
* @param array $data
|
||||||
|
*
|
||||||
* @return CartItem|void
|
* @return CartItem|void
|
||||||
*/
|
*/
|
||||||
public function getItemByProduct($data)
|
public function getItemByProduct($data)
|
||||||
|
|
@ -286,8 +296,10 @@ class Cart {
|
||||||
foreach ($items as $item) {
|
foreach ($items as $item) {
|
||||||
if ($item->product->getTypeInstance()->compareOptions($item->additional, $data['additional'])) {
|
if ($item->product->getTypeInstance()->compareOptions($item->additional, $data['additional'])) {
|
||||||
if (isset($data['additional']['parent_id'])) {
|
if (isset($data['additional']['parent_id'])) {
|
||||||
if ($item->parent->product->getTypeInstance()->compareOptions($item->parent->additional, request()->all()))
|
if ($item->parent->product->getTypeInstance()->compareOptions($item->parent->additional,
|
||||||
|
request()->all())) {
|
||||||
return $item;
|
return $item;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
return $item;
|
return $item;
|
||||||
}
|
}
|
||||||
|
|
@ -299,14 +311,16 @@ class Cart {
|
||||||
* Remove the item from the cart
|
* Remove the item from the cart
|
||||||
*
|
*
|
||||||
* @param integer $itemId
|
* @param integer $itemId
|
||||||
|
*
|
||||||
* @return boolean
|
* @return boolean
|
||||||
*/
|
*/
|
||||||
public function removeItem($itemId)
|
public function removeItem($itemId)
|
||||||
{
|
{
|
||||||
Event::dispatch('checkout.cart.delete.before', $itemId);
|
Event::dispatch('checkout.cart.delete.before', $itemId);
|
||||||
|
|
||||||
if (! $cart = $this->getCart())
|
if (!$cart = $this->getCart()) {
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
$this->cartItemRepository->delete($itemId);
|
$this->cartItemRepository->delete($itemId);
|
||||||
|
|
||||||
|
|
@ -334,18 +348,21 @@ class Cart {
|
||||||
public function mergeCart()
|
public function mergeCart()
|
||||||
{
|
{
|
||||||
if (session()->has('cart')) {
|
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');
|
$guestCart = session()->get('cart');
|
||||||
|
|
||||||
//when the logged in customer is not having any of the cart instance previously and are active.
|
//when the logged in customer is not having any of the cart instance previously and are active.
|
||||||
if (! $cart) {
|
if (!$cart) {
|
||||||
$this->cartRepository->update([
|
$this->cartRepository->update([
|
||||||
'customer_id' => $this->getCurrentCustomer()->user()->id,
|
'customer_id' => $this->getCurrentCustomer()->user()->id,
|
||||||
'is_guest' => 0,
|
'is_guest' => 0,
|
||||||
'customer_first_name' => $this->getCurrentCustomer()->user()->first_name,
|
'customer_first_name' => $this->getCurrentCustomer()->user()->first_name,
|
||||||
'customer_last_name' => $this->getCurrentCustomer()->user()->last_name,
|
'customer_last_name' => $this->getCurrentCustomer()->user()->last_name,
|
||||||
'customer_email' => $this->getCurrentCustomer()->user()->email
|
'customer_email' => $this->getCurrentCustomer()->user()->email,
|
||||||
], $guestCart->id);
|
], $guestCart->id);
|
||||||
|
|
||||||
session()->forget('cart');
|
session()->forget('cart');
|
||||||
|
|
@ -358,23 +375,25 @@ class Cart {
|
||||||
$found = false;
|
$found = false;
|
||||||
|
|
||||||
foreach ($cart->items as $cartItem) {
|
foreach ($cart->items as $cartItem) {
|
||||||
if (! $cartItem->product->getTypeInstance()->compareOptions($cartItem->additional, $guestCartItem->additional))
|
if (!$cartItem->product->getTypeInstance()->compareOptions($cartItem->additional,
|
||||||
|
$guestCartItem->additional)) {
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
$cartItem->quantity = $newQuantity = $cartItem->quantity + $guestCartItem->quantity;
|
$cartItem->quantity = $newQuantity = $cartItem->quantity + $guestCartItem->quantity;
|
||||||
|
|
||||||
if (! $this->isItemHaveQuantity($cartItem)) {
|
if (!$this->isItemHaveQuantity($cartItem)) {
|
||||||
$this->cartItemRepository->delete($guestCartItem->id);
|
$this->cartItemRepository->delete($guestCartItem->id);
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->cartItemRepository->update([
|
$this->cartItemRepository->update([
|
||||||
'quantity' => $newQuantity,
|
'quantity' => $newQuantity,
|
||||||
'total' => core()->convertPrice($cartItem->price * $newQuantity),
|
'total' => core()->convertPrice($cartItem->price * $newQuantity),
|
||||||
'base_total' => $cartItem->price * $newQuantity,
|
'base_total' => $cartItem->price * $newQuantity,
|
||||||
'total_weight' => $cartItem->weight * $newQuantity,
|
'total_weight' => $cartItem->weight * $newQuantity,
|
||||||
'base_total_weight' => $cartItem->weight * $newQuantity
|
'base_total_weight' => $cartItem->weight * $newQuantity,
|
||||||
], $cartItem->id);
|
], $cartItem->id);
|
||||||
|
|
||||||
$guestCart->items->forget($key);
|
$guestCart->items->forget($key);
|
||||||
|
|
@ -384,14 +403,14 @@ class Cart {
|
||||||
$found = true;
|
$found = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (! $found) {
|
if (!$found) {
|
||||||
$this->cartItemRepository->update([
|
$this->cartItemRepository->update([
|
||||||
'cart_id' => $cart->id
|
'cart_id' => $cart->id,
|
||||||
], $guestCartItem->id);
|
], $guestCartItem->id);
|
||||||
|
|
||||||
foreach ($guestCartItem->children as $child) {
|
foreach ($guestCartItem->children as $child) {
|
||||||
$this->cartItemRepository->update([
|
$this->cartItemRepository->update([
|
||||||
'cart_id' => $cart->id
|
'cart_id' => $cart->id,
|
||||||
], $child->id);
|
], $child->id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -411,11 +430,12 @@ class Cart {
|
||||||
* Save cart
|
* Save cart
|
||||||
*
|
*
|
||||||
* @param Cart $cart
|
* @param Cart $cart
|
||||||
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function putCart($cart)
|
public function putCart($cart)
|
||||||
{
|
{
|
||||||
if (! $this->getCurrentCustomer()->check()) {
|
if (!$this->getCurrentCustomer()->check()) {
|
||||||
session()->put('cart', $cart);
|
session()->put('cart', $cart);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -432,7 +452,7 @@ class Cart {
|
||||||
if ($this->getCurrentCustomer()->check()) {
|
if ($this->getCurrentCustomer()->check()) {
|
||||||
$cart = $this->cartRepository->findOneWhere([
|
$cart = $this->cartRepository->findOneWhere([
|
||||||
'customer_id' => $this->getCurrentCustomer()->user()->id,
|
'customer_id' => $this->getCurrentCustomer()->user()->id,
|
||||||
'is_active' => 1
|
'is_active' => 1,
|
||||||
]);
|
]);
|
||||||
} elseif (session()->has('cart')) {
|
} elseif (session()->has('cart')) {
|
||||||
$cart = $this->cartRepository->find(session()->get('cart')->id);
|
$cart = $this->cartRepository->find(session()->get('cart')->id);
|
||||||
|
|
@ -471,18 +491,20 @@ class Cart {
|
||||||
* Save customer address
|
* Save customer address
|
||||||
*
|
*
|
||||||
* @param array $data
|
* @param array $data
|
||||||
|
*
|
||||||
* @return boolean
|
* @return boolean
|
||||||
*/
|
*/
|
||||||
public function saveCustomerAddress($data)
|
public function saveCustomerAddress($data)
|
||||||
{
|
{
|
||||||
if (! $cart = $this->getCart())
|
if (!$cart = $this->getCart()) {
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
$billingAddress = $data['billing'];
|
$billingAddress = $data['billing'];
|
||||||
$billingAddress['cart_id'] = $cart->id;
|
$billingAddress['cart_id'] = $cart->id;
|
||||||
|
|
||||||
if (isset($data['billing']['address_id']) && $data['billing']['address_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['first_name'] = $this->getCurrentCustomer()->user()->first_name;
|
||||||
$billingAddress['last_name'] = $this->getCurrentCustomer()->user()->last_name;
|
$billingAddress['last_name'] = $this->getCurrentCustomer()->user()->last_name;
|
||||||
|
|
@ -496,7 +518,7 @@ class Cart {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($data['billing']['save_as_address']) && $data['billing']['save_as_address']) {
|
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);
|
$this->customerAddressRepository->create($billingAddress);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -505,7 +527,7 @@ class Cart {
|
||||||
$shippingAddress['cart_id'] = $cart->id;
|
$shippingAddress['cart_id'] = $cart->id;
|
||||||
|
|
||||||
if (isset($data['shipping']['address_id']) && $data['shipping']['address_id']) {
|
if (isset($data['shipping']['address_id']) && $data['shipping']['address_id']) {
|
||||||
$address = $this->customerAddressRepository->findOneWhere(['id'=> $data['shipping']['address_id']])->toArray();
|
$address = $this->customerAddressRepository->findOneWhere(['id' => $data['shipping']['address_id']])->toArray();
|
||||||
|
|
||||||
$shippingAddress['first_name'] = $this->getCurrentCustomer()->user()->first_name;
|
$shippingAddress['first_name'] = $this->getCurrentCustomer()->user()->first_name;
|
||||||
$shippingAddress['last_name'] = $this->getCurrentCustomer()->user()->last_name;
|
$shippingAddress['last_name'] = $this->getCurrentCustomer()->user()->last_name;
|
||||||
|
|
@ -519,7 +541,7 @@ class Cart {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($data['shipping']['save_as_address']) && $data['shipping']['save_as_address']) {
|
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);
|
$this->customerAddressRepository->create($shippingAddress);
|
||||||
}
|
}
|
||||||
|
|
@ -537,9 +559,11 @@ class Cart {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (isset($billingAddress['use_for_shipping']) && $billingAddress['use_for_shipping']) {
|
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 {
|
} else {
|
||||||
$this->cartAddressRepository->create(array_merge($shippingAddress, ['address_type' => 'shipping']));
|
$this->cartAddressRepository->create(array_merge($shippingAddress,
|
||||||
|
['address_type' => 'shipping']));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -567,6 +591,8 @@ class Cart {
|
||||||
|
|
||||||
$cart->save();
|
$cart->save();
|
||||||
|
|
||||||
|
$this->collectTotals();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -574,12 +600,14 @@ class Cart {
|
||||||
* Save shipping method for cart
|
* Save shipping method for cart
|
||||||
*
|
*
|
||||||
* @param string $shippingMethodCode
|
* @param string $shippingMethodCode
|
||||||
|
*
|
||||||
* @return boolean
|
* @return boolean
|
||||||
*/
|
*/
|
||||||
public function saveShippingMethod($shippingMethodCode)
|
public function saveShippingMethod($shippingMethodCode)
|
||||||
{
|
{
|
||||||
if (! $cart = $this->getCart())
|
if (!$cart = $this->getCart()) {
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
$cart->shipping_method = $shippingMethodCode;
|
$cart->shipping_method = $shippingMethodCode;
|
||||||
$cart->save();
|
$cart->save();
|
||||||
|
|
@ -591,15 +619,18 @@ class Cart {
|
||||||
* Save payment method for cart
|
* Save payment method for cart
|
||||||
*
|
*
|
||||||
* @param string $payment
|
* @param string $payment
|
||||||
|
*
|
||||||
* @return CartPayment
|
* @return CartPayment
|
||||||
*/
|
*/
|
||||||
public function savePaymentMethod($payment)
|
public function savePaymentMethod($payment)
|
||||||
{
|
{
|
||||||
if (! $cart = $this->getCart())
|
if (!$cart = $this->getCart()) {
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
if ($cartPayment = $cart->payment)
|
if ($cartPayment = $cart->payment) {
|
||||||
$cartPayment->delete();
|
$cartPayment->delete();
|
||||||
|
}
|
||||||
|
|
||||||
$cartPayment = new CartPayment;
|
$cartPayment = new CartPayment;
|
||||||
|
|
||||||
|
|
@ -619,11 +650,13 @@ class Cart {
|
||||||
{
|
{
|
||||||
$validated = $this->validateItems();
|
$validated = $this->validateItems();
|
||||||
|
|
||||||
if (! $validated)
|
if (!$validated) {
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
if (! $cart = $this->getCart())
|
if (!$cart = $this->getCart()) {
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
Event::dispatch('checkout.cart.collect.totals.before', $cart);
|
Event::dispatch('checkout.cart.collect.totals.before', $cart);
|
||||||
|
|
||||||
|
|
@ -638,19 +671,19 @@ class Cart {
|
||||||
$cart->discount_amount += $item->discount_amount;
|
$cart->discount_amount += $item->discount_amount;
|
||||||
$cart->base_discount_amount += $item->base_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->sub_total = (float)$cart->sub_total + $item->total;
|
||||||
$cart->base_grand_total = (float) $cart->base_grand_total + $item->base_total + $item->base_tax_amount - $item->base_discount_amount;
|
$cart->base_sub_total = (float)$cart->base_sub_total + $item->base_total;
|
||||||
|
|
||||||
$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->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) {
|
if ($shipping = $cart->selected_shipping_rate) {
|
||||||
$cart->grand_total = (float) $cart->grand_total + $shipping->price - $shipping->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->base_grand_total = (float)$cart->base_grand_total + $shipping->base_price - $shipping->base_discount_amount;
|
||||||
|
|
||||||
$cart->discount_amount += $shipping->discount_amount;
|
$cart->discount_amount += $shipping->discount_amount;
|
||||||
$cart->base_discount_amount += $shipping->base_discount_amount;
|
$cart->base_discount_amount += $shipping->base_discount_amount;
|
||||||
|
|
@ -679,8 +712,9 @@ class Cart {
|
||||||
*/
|
*/
|
||||||
public function validateItems()
|
public function validateItems()
|
||||||
{
|
{
|
||||||
if (! $cart = $this->getCart())
|
if (!$cart = $this->getCart()) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
//rare case of accident-->used when there are no items.
|
//rare case of accident-->used when there are no items.
|
||||||
if (count($cart->items) == 0) {
|
if (count($cart->items) == 0) {
|
||||||
|
|
@ -691,12 +725,12 @@ class Cart {
|
||||||
foreach ($cart->items as $item) {
|
foreach ($cart->items as $item) {
|
||||||
$item->product->getTypeInstance()->validateCartItem($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([
|
$this->cartItemRepository->update([
|
||||||
'price' => core()->convertPrice($price),
|
'price' => core()->convertPrice($price),
|
||||||
'base_price' => $price,
|
'base_price' => $price,
|
||||||
'total' => core()->convertPrice($price * $item->quantity),
|
'total' => core()->convertPrice($price * $item->quantity),
|
||||||
'base_total' => $price * $item->quantity,
|
'base_total' => $price * $item->quantity,
|
||||||
], $item->id);
|
], $item->id);
|
||||||
}
|
}
|
||||||
|
|
@ -710,19 +744,18 @@ class Cart {
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function calculateItemsTax()
|
public function calculateItemsTax(): void
|
||||||
{
|
{
|
||||||
if (! $cart = $this->getCart())
|
if (!$cart = $this->getCart()) {
|
||||||
return false;
|
|
||||||
|
|
||||||
if (! $cart->shipping_address && ! $cart->billing_address)
|
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
foreach ($cart->items()->get() as $item) {
|
foreach ($cart->items()->get() as $item) {
|
||||||
$taxCategory = $this->taxCategoryRepository->find($item->product->tax_category_id);
|
$taxCategory = $this->taxCategoryRepository->find($item->product->tax_category_id);
|
||||||
|
|
||||||
if (! $taxCategory)
|
if (!$taxCategory) {
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if ($item->product->getTypeInstance()->isStockable()) {
|
if ($item->product->getTypeInstance()->isStockable()) {
|
||||||
$address = $cart->shipping_address;
|
$address = $cart->shipping_address;
|
||||||
|
|
@ -730,58 +763,71 @@ class Cart {
|
||||||
$address = $cart->billing_address;
|
$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([
|
$taxRates = $taxCategory->tax_rates()->where([
|
||||||
'country' => $address->country,
|
'country' => $address->country,
|
||||||
])->orderBy('tax_rate', 'desc')->get();
|
])->orderBy('tax_rate', 'desc')->get();
|
||||||
|
|
||||||
|
$item = $this->setItemTaxToZero($item);
|
||||||
|
|
||||||
if ($taxRates->count()) {
|
if ($taxRates->count()) {
|
||||||
foreach ($taxRates as $rate) {
|
foreach ($taxRates as $rate) {
|
||||||
$haveTaxRate = false;
|
$haveTaxRate = false;
|
||||||
|
|
||||||
if ($rate->state != '' && $rate->state != $address->state) {
|
if ($rate->state != '' && $rate->state != $address->state) {
|
||||||
$this->setItemTaxToZero($item);
|
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
if (!$rate->is_zip) {
|
||||||
if (! $rate->is_zip) {
|
if ($rate->zip_code == '*' || $rate->zip_code == $address->postcode) {
|
||||||
if ($rate->zip_code == '*' || $rate->zip_code == $address->postcode)
|
|
||||||
$haveTaxRate = true;
|
$haveTaxRate = true;
|
||||||
|
}
|
||||||
} else {
|
} 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;
|
$haveTaxRate = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($haveTaxRate) {
|
if ($haveTaxRate) {
|
||||||
$item->tax_percent = $rate->tax_rate;
|
$item->tax_percent = $rate->tax_rate;
|
||||||
$item->tax_amount = ($item->total * $rate->tax_rate) / 100;
|
$item->tax_amount = ($item->total * $rate->tax_rate) / 100;
|
||||||
$item->base_tax_amount = ($item->base_total * $rate->tax_rate) / 100;
|
$item->base_tax_amount = ($item->base_total * $rate->tax_rate) / 100;
|
||||||
|
|
||||||
$item->save();
|
|
||||||
break;
|
|
||||||
} else {
|
|
||||||
$this->setItemTaxToZero($item);
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
$this->setItemTaxToZero($item);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$item->save();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set Item tax to zero.
|
* 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_percent = 0;
|
||||||
$item->tax_amount = 0;
|
$item->tax_amount = 0;
|
||||||
$item->base_tax_amount = 0;
|
$item->base_tax_amount = 0;
|
||||||
|
|
||||||
$item->save();
|
return $item;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -791,11 +837,13 @@ class Cart {
|
||||||
*/
|
*/
|
||||||
public function hasError()
|
public function hasError()
|
||||||
{
|
{
|
||||||
if (! $this->getCart())
|
if (!$this->getCart()) {
|
||||||
return true;
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
if (! $this->isItemsHaveSufficientQuantity())
|
if (!$this->isItemsHaveSufficientQuantity()) {
|
||||||
return true;
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
@ -808,8 +856,9 @@ class Cart {
|
||||||
public function isItemsHaveSufficientQuantity()
|
public function isItemsHaveSufficientQuantity()
|
||||||
{
|
{
|
||||||
foreach ($this->getCart()->items as $item) {
|
foreach ($this->getCart()->items as $item) {
|
||||||
if (! $this->isItemHaveQuantity($item))
|
if (!$this->isItemHaveQuantity($item)) {
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
@ -819,6 +868,7 @@ class Cart {
|
||||||
* Checks if all cart items have sufficient quantity.
|
* Checks if all cart items have sufficient quantity.
|
||||||
*
|
*
|
||||||
* @param CartItem $item
|
* @param CartItem $item
|
||||||
|
*
|
||||||
* @return boolean
|
* @return boolean
|
||||||
*/
|
*/
|
||||||
public function isItemHaveQuantity($item)
|
public function isItemHaveQuantity($item)
|
||||||
|
|
@ -852,42 +902,42 @@ class Cart {
|
||||||
$data = $this->toArray();
|
$data = $this->toArray();
|
||||||
|
|
||||||
$finalData = [
|
$finalData = [
|
||||||
'cart_id' => $this->getCart()->id,
|
'cart_id' => $this->getCart()->id,
|
||||||
'customer_id' => $data['customer_id'],
|
'customer_id' => $data['customer_id'],
|
||||||
'is_guest' => $data['is_guest'],
|
'is_guest' => $data['is_guest'],
|
||||||
'customer_email' => $data['customer_email'],
|
'customer_email' => $data['customer_email'],
|
||||||
'customer_first_name' => $data['customer_first_name'],
|
'customer_first_name' => $data['customer_first_name'],
|
||||||
'customer_last_name' => $data['customer_last_name'],
|
'customer_last_name' => $data['customer_last_name'],
|
||||||
'customer' => $this->getCurrentCustomer()->check() ? $this->getCurrentCustomer()->user() : null,
|
'customer' => $this->getCurrentCustomer()->check() ? $this->getCurrentCustomer()->user() : null,
|
||||||
'total_item_count' => $data['items_count'],
|
'total_item_count' => $data['items_count'],
|
||||||
'total_qty_ordered' => $data['items_qty'],
|
'total_qty_ordered' => $data['items_qty'],
|
||||||
'base_currency_code' => $data['base_currency_code'],
|
'base_currency_code' => $data['base_currency_code'],
|
||||||
'channel_currency_code' => $data['channel_currency_code'],
|
'channel_currency_code' => $data['channel_currency_code'],
|
||||||
'order_currency_code' => $data['cart_currency_code'],
|
'order_currency_code' => $data['cart_currency_code'],
|
||||||
'grand_total' => $data['grand_total'],
|
'grand_total' => $data['grand_total'],
|
||||||
'base_grand_total' => $data['base_grand_total'],
|
'base_grand_total' => $data['base_grand_total'],
|
||||||
'sub_total' => $data['sub_total'],
|
'sub_total' => $data['sub_total'],
|
||||||
'base_sub_total' => $data['base_sub_total'],
|
'base_sub_total' => $data['base_sub_total'],
|
||||||
'tax_amount' => $data['tax_total'],
|
'tax_amount' => $data['tax_total'],
|
||||||
'base_tax_amount' => $data['base_tax_total'],
|
'base_tax_amount' => $data['base_tax_total'],
|
||||||
'coupon_code' => $data['coupon_code'],
|
'coupon_code' => $data['coupon_code'],
|
||||||
'applied_cart_rule_ids' => $data['applied_cart_rule_ids'],
|
'applied_cart_rule_ids' => $data['applied_cart_rule_ids'],
|
||||||
'discount_amount' => $data['discount_amount'],
|
'discount_amount' => $data['discount_amount'],
|
||||||
'base_discount_amount' => $data['base_discount_amount'],
|
'base_discount_amount' => $data['base_discount_amount'],
|
||||||
'billing_address' => Arr::except($data['billing_address'], ['id', 'cart_id']),
|
'billing_address' => Arr::except($data['billing_address'], ['id', 'cart_id']),
|
||||||
'payment' => Arr::except($data['payment'], ['id', 'cart_id']),
|
'payment' => Arr::except($data['payment'], ['id', 'cart_id']),
|
||||||
'channel' => core()->getCurrentChannel(),
|
'channel' => core()->getCurrentChannel(),
|
||||||
];
|
];
|
||||||
|
|
||||||
if ($this->getCart()->haveStockableItems()) {
|
if ($this->getCart()->haveStockableItems()) {
|
||||||
$finalData = array_merge($finalData, [
|
$finalData = array_merge($finalData, [
|
||||||
'shipping_method' => $data['selected_shipping_rate']['method'],
|
'shipping_method' => $data['selected_shipping_rate']['method'],
|
||||||
'shipping_title' => $data['selected_shipping_rate']['carrier_title'] . ' - ' . $data['selected_shipping_rate']['method_title'],
|
'shipping_title' => $data['selected_shipping_rate']['carrier_title'] . ' - ' . $data['selected_shipping_rate']['method_title'],
|
||||||
'shipping_description' => $data['selected_shipping_rate']['method_description'],
|
'shipping_description' => $data['selected_shipping_rate']['method_description'],
|
||||||
'shipping_amount' => $data['selected_shipping_rate']['price'],
|
'shipping_amount' => $data['selected_shipping_rate']['price'],
|
||||||
'base_shipping_amount' => $data['selected_shipping_rate']['base_price'],
|
'base_shipping_amount' => $data['selected_shipping_rate']['base_price'],
|
||||||
'shipping_address' => Arr::except($data['shipping_address'], ['id', 'cart_id']),
|
'shipping_address' => Arr::except($data['shipping_address'], ['id', 'cart_id']),
|
||||||
'shipping_discount_amount' => $data['selected_shipping_rate']['discount_amount'],
|
'shipping_discount_amount' => $data['selected_shipping_rate']['discount_amount'],
|
||||||
'base_shipping_discount_amount' => $data['selected_shipping_rate']['base_discount_amount'],
|
'base_shipping_discount_amount' => $data['selected_shipping_rate']['base_discount_amount'],
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
@ -903,29 +953,30 @@ class Cart {
|
||||||
* Prepares data for order item
|
* Prepares data for order item
|
||||||
*
|
*
|
||||||
* @param array $data
|
* @param array $data
|
||||||
|
*
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function prepareDataForOrderItem($data)
|
public function prepareDataForOrderItem($data)
|
||||||
{
|
{
|
||||||
$finalData = [
|
$finalData = [
|
||||||
'product' => $this->productRepository->find($data['product_id']),
|
'product' => $this->productRepository->find($data['product_id']),
|
||||||
'sku' => $data['sku'],
|
'sku' => $data['sku'],
|
||||||
'type' => $data['type'],
|
'type' => $data['type'],
|
||||||
'name' => $data['name'],
|
'name' => $data['name'],
|
||||||
'weight' => $data['weight'],
|
'weight' => $data['weight'],
|
||||||
'total_weight' => $data['total_weight'],
|
'total_weight' => $data['total_weight'],
|
||||||
'qty_ordered' => $data['quantity'],
|
'qty_ordered' => $data['quantity'],
|
||||||
'price' => $data['price'],
|
'price' => $data['price'],
|
||||||
'base_price' => $data['base_price'],
|
'base_price' => $data['base_price'],
|
||||||
'total' => $data['total'],
|
'total' => $data['total'],
|
||||||
'base_total' => $data['base_total'],
|
'base_total' => $data['base_total'],
|
||||||
'tax_percent' => $data['tax_percent'],
|
'tax_percent' => $data['tax_percent'],
|
||||||
'tax_amount' => $data['tax_amount'],
|
'tax_amount' => $data['tax_amount'],
|
||||||
'base_tax_amount' => $data['base_tax_amount'],
|
'base_tax_amount' => $data['base_tax_amount'],
|
||||||
'discount_percent' => $data['discount_percent'],
|
'discount_percent' => $data['discount_percent'],
|
||||||
'discount_amount' => $data['discount_amount'],
|
'discount_amount' => $data['discount_amount'],
|
||||||
'base_discount_amount' => $data['base_discount_amount'],
|
'base_discount_amount' => $data['base_discount_amount'],
|
||||||
'additional' => $data['additional'],
|
'additional' => $data['additional'],
|
||||||
];
|
];
|
||||||
|
|
||||||
if (isset($data['children']) && $data['children']) {
|
if (isset($data['children']) && $data['children']) {
|
||||||
|
|
@ -943,15 +994,18 @@ class Cart {
|
||||||
* Move a wishlist item to cart
|
* Move a wishlist item to cart
|
||||||
*
|
*
|
||||||
* @param WishlistItem $wishlistItem
|
* @param WishlistItem $wishlistItem
|
||||||
|
*
|
||||||
* @return boolean
|
* @return boolean
|
||||||
*/
|
*/
|
||||||
public function moveToCart($wishlistItem)
|
public function moveToCart($wishlistItem)
|
||||||
{
|
{
|
||||||
if (! $wishlistItem->product->getTypeInstance()->canBeMovedFromWishlistToCart($wishlistItem))
|
if (!$wishlistItem->product->getTypeInstance()->canBeMovedFromWishlistToCart($wishlistItem)) {
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
if (! $wishlistItem->additional)
|
if (!$wishlistItem->additional) {
|
||||||
$wishlistItem->additional = ['product_id' => $wishlistItem->product_id];
|
$wishlistItem->additional = ['product_id' => $wishlistItem->product_id];
|
||||||
|
}
|
||||||
|
|
||||||
request()->merge($wishlistItem->additional);
|
request()->merge($wishlistItem->additional);
|
||||||
|
|
||||||
|
|
@ -970,6 +1024,7 @@ class Cart {
|
||||||
* Function to move a already added product to wishlist will run only on customer authentication.
|
* Function to move a already added product to wishlist will run only on customer authentication.
|
||||||
*
|
*
|
||||||
* @param integer $itemId
|
* @param integer $itemId
|
||||||
|
*
|
||||||
* @return boolean|void
|
* @return boolean|void
|
||||||
*/
|
*/
|
||||||
public function moveToWishlist($itemId)
|
public function moveToWishlist($itemId)
|
||||||
|
|
@ -978,13 +1033,14 @@ class Cart {
|
||||||
|
|
||||||
$cartItem = $cart->items()->find($itemId);
|
$cartItem = $cart->items()->find($itemId);
|
||||||
|
|
||||||
if (! $cartItem)
|
if (!$cartItem) {
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
$wishlistItems = $this->wishlistRepository->findWhere([
|
$wishlistItems = $this->wishlistRepository->findWhere([
|
||||||
'customer_id' => $this->getCurrentCustomer()->user()->id,
|
'customer_id' => $this->getCurrentCustomer()->user()->id,
|
||||||
'product_id' => $cartItem->product_id
|
'product_id' => $cartItem->product_id,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$found = false;
|
$found = false;
|
||||||
|
|
||||||
|
|
@ -998,19 +1054,20 @@ class Cart {
|
||||||
$found = true;
|
$found = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (! $found) {
|
if (!$found) {
|
||||||
$this->wishlistRepository->create([
|
$this->wishlistRepository->create([
|
||||||
'channel_id' => $cart->channel_id,
|
'channel_id' => $cart->channel_id,
|
||||||
'customer_id' => $this->getCurrentCustomer()->user()->id,
|
'customer_id' => $this->getCurrentCustomer()->user()->id,
|
||||||
'product_id' => $cartItem->product_id,
|
'product_id' => $cartItem->product_id,
|
||||||
'additional' => $cartItem->additional
|
'additional' => $cartItem->additional,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
$result = $this->cartItemRepository->delete($itemId);
|
$result = $this->cartItemRepository->delete($itemId);
|
||||||
|
|
||||||
if (! $cart->items()->count())
|
if (!$cart->items()->count()) {
|
||||||
$this->cartRepository->delete($cart->id);
|
$this->cartRepository->delete($cart->id);
|
||||||
|
}
|
||||||
|
|
||||||
$this->collectTotals();
|
$this->collectTotals();
|
||||||
|
|
||||||
|
|
@ -1021,6 +1078,7 @@ class Cart {
|
||||||
* Set coupon code to the cart
|
* Set coupon code to the cart
|
||||||
*
|
*
|
||||||
* @param string $code
|
* @param string $code
|
||||||
|
*
|
||||||
* @return Cart
|
* @return Cart
|
||||||
*/
|
*/
|
||||||
public function setCouponCode($code)
|
public function setCouponCode($code)
|
||||||
|
|
|
||||||
|
|
@ -969,4 +969,15 @@ class Core
|
||||||
|
|
||||||
return $instance[$className] = app($className);
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -72,6 +72,7 @@ class Laravel5Helper extends Laravel5
|
||||||
* @param array $productStates
|
* @param array $productStates
|
||||||
*
|
*
|
||||||
* @return \Webkul\Product\Models\Product
|
* @return \Webkul\Product\Models\Product
|
||||||
|
* @part ORM
|
||||||
*/
|
*/
|
||||||
public function haveProduct(int $productType, array $configs = [], array $productStates = []): Product
|
public function haveProduct(int $productType, array $configs = [], array $productStates = []): Product
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -42,7 +42,7 @@ $factory->defineAs(ProductAttributeValue::class, 'tax_category_id', function (Fa
|
||||||
return factory(Product::class)->create()->id;
|
return factory(Product::class)->create()->id;
|
||||||
},
|
},
|
||||||
'channel' => 'default',
|
'channel' => 'default',
|
||||||
'integer_value' => null, // ToDo
|
'integer_value' => null,
|
||||||
'attribute_id' => 4,
|
'attribute_id' => 4,
|
||||||
];
|
];
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -73,7 +73,7 @@ class ProductFlatRepository extends Repository
|
||||||
public function getFilterableAttributes($category, $products) {
|
public function getFilterableAttributes($category, $products) {
|
||||||
$filterAttributes = [];
|
$filterAttributes = [];
|
||||||
|
|
||||||
if (count($category->filterableAttributes) > 0 && count($products)) {
|
if (count($category->filterableAttributes) > 0 ) {
|
||||||
$filterAttributes = $category->filterableAttributes;
|
$filterAttributes = $category->filterableAttributes;
|
||||||
} else {
|
} else {
|
||||||
$categoryProductAttributes = $this->getCategoryProductAttribute($category->id);
|
$categoryProductAttributes = $this->getCategoryProductAttribute($category->id);
|
||||||
|
|
|
||||||
|
|
@ -103,6 +103,10 @@ class OnepageController extends Controller
|
||||||
{
|
{
|
||||||
$data = request()->all();
|
$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['billing']['address1'] = implode(PHP_EOL, array_filter($data['billing']['address1']));
|
||||||
$data['shipping']['address1'] = implode(PHP_EOL, array_filter($data['shipping']['address1']));
|
$data['shipping']['address1'] = implode(PHP_EOL, array_filter($data['shipping']['address1']));
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -286,7 +286,7 @@
|
||||||
</li>
|
</li>
|
||||||
|
|
||||||
<li class="mb-15">
|
<li class="mb-15">
|
||||||
@{{ addresses.country }}.
|
@{{ addresses.country }} @{{ addresses.postcode }}
|
||||||
</li>
|
</li>
|
||||||
|
|
||||||
<li>
|
<li>
|
||||||
|
|
|
||||||
|
|
@ -18,10 +18,12 @@
|
||||||
@endif
|
@endif
|
||||||
|
|
||||||
@if ($cart->base_tax_total)
|
@if ($cart->base_tax_total)
|
||||||
|
@foreach (Webkul\Tax\Helpers\Tax::getTaxRatesWithAmount($cart, true) as $taxRate => $baseTaxAmount )
|
||||||
<div class="item-detail">
|
<div class="item-detail">
|
||||||
<label>{{ __('shop::app.checkout.total.tax') }}</label>
|
<label id="taxrate-{{ core()->taxRateAsIdentifier($taxRate) }}">{{ __('shop::app.checkout.total.tax') }} {{ $taxRate }} %</label>
|
||||||
<label class="right">{{ core()->currency($cart->base_tax_total) }}</label>
|
<label class="right" id="basetaxamount-{{ core()->taxRateAsIdentifier($taxRate) }}">{{ core()->currency($baseTaxAmount) }}</label>
|
||||||
</div>
|
</div>
|
||||||
|
@endforeach
|
||||||
@endif
|
@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>
|
<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>
|
||||||
|
|
|
||||||
|
|
@ -161,12 +161,14 @@
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
@foreach (Webkul\Tax\Helpers\Tax::getTaxRatesWithAmount($order, true) as $taxRate => $baseTaxAmount )
|
||||||
<div>
|
<div>
|
||||||
<span>{{ __('shop::app.mail.order.tax') }}</span>
|
<span id="taxrate-{{ core()->taxRateAsIdentifier($taxRate) }}">{{ __('shop::app.mail.order.tax') }} {{ $taxRate }} %</span>
|
||||||
<span style="float: right;">
|
<span id="basetaxamount-{{ core()->taxRateAsIdentifier($taxRate) }}" style="float: right;">
|
||||||
{{ core()->formatBasePrice($order->base_tax_amount) }}
|
{{ core()->formatBasePrice($baseTaxAmount) }}
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
|
@endforeach
|
||||||
|
|
||||||
@if ($order->discount_amount > 0)
|
@if ($order->discount_amount > 0)
|
||||||
<div>
|
<div>
|
||||||
|
|
|
||||||
|
|
@ -125,7 +125,7 @@
|
||||||
<tbody>
|
<tbody>
|
||||||
@foreach ($shipment->items as $item)
|
@foreach ($shipment->items as $item)
|
||||||
<tr>
|
<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">
|
<td data-value="{{ __('shop::app.customer.account.order.view.product-name') }}" style="text-align: left;padding: 8px">
|
||||||
{{ $item->name }}
|
{{ $item->name }}
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,8 @@
|
||||||
{{ __('shop::app.mail.invoice.summary') }}
|
{{ __('shop::app.mail.invoice.summary') }}
|
||||||
</div>
|
</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)
|
@if ($order->shipping_address)
|
||||||
<div style="line-height: 25px;">
|
<div style="line-height: 25px;">
|
||||||
<div style="font-weight: bold;font-size: 16px;color: #242424;">
|
<div style="font-weight: bold;font-size: 16px;color: #242424;">
|
||||||
|
|
@ -103,37 +104,41 @@
|
||||||
<table style="overflow-x: auto; border-collapse: collapse;
|
<table style="overflow-x: auto; border-collapse: collapse;
|
||||||
border-spacing: 0;width: 100%">
|
border-spacing: 0;width: 100%">
|
||||||
<thead>
|
<thead>
|
||||||
<tr style="background-color: #f2f2f2">
|
<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.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.price') }}</th>
|
||||||
<th style="text-align: left;padding: 8px">{{ __('shop::app.customer.account.order.view.qty') }}</th>
|
<th style="text-align: left;padding: 8px">{{ __('shop::app.customer.account.order.view.qty') }}</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
|
|
||||||
<tbody>
|
<tbody>
|
||||||
@foreach ($invoice->items as $item)
|
@foreach ($invoice->items as $item)
|
||||||
<tr>
|
<tr>
|
||||||
<td data-value="{{ __('shop::app.customer.account.order.view.product-name') }}" style="text-align: left;padding: 8px">
|
<td data-value="{{ __('shop::app.customer.account.order.view.product-name') }}"
|
||||||
{{ $item->name }}
|
style="text-align: left;padding: 8px">
|
||||||
|
{{ $item->name }}
|
||||||
|
|
||||||
@if (isset($item->additional['attributes']))
|
@if (isset($item->additional['attributes']))
|
||||||
<div class="item-options">
|
<div class="item-options">
|
||||||
|
|
||||||
@foreach ($item->additional['attributes'] as $attribute)
|
@foreach ($item->additional['attributes'] as $attribute)
|
||||||
<b>{{ $attribute['attribute_name'] }} : </b>{{ $attribute['option_label'] }}</br>
|
<b>{{ $attribute['attribute_name'] }}
|
||||||
@endforeach
|
: </b>{{ $attribute['option_label'] }}</br>
|
||||||
|
@endforeach
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
@endif
|
@endif
|
||||||
</td>
|
</td>
|
||||||
|
|
||||||
<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 data-value="{{ __('shop::app.customer.account.order.view.price') }}"
|
||||||
</td>
|
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>
|
<td data-value="{{ __('shop::app.customer.account.order.view.qty') }}"
|
||||||
</tr>
|
style="text-align: left;padding: 8px">{{ $item->qty }}</td>
|
||||||
|
</tr>
|
||||||
|
|
||||||
@endforeach
|
@endforeach
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
|
|
@ -158,8 +163,8 @@
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
<span>{{ __('shop::app.mail.order.tax') }}</span>
|
<span>{{ __('shop::app.mail.order.tax') }}</span>
|
||||||
<span style="float: right;">
|
<span id="taxamount" style="float: right;">
|
||||||
{{ core()->formatPrice($invoice->tax_amount, $invoice->order_currency_code) }}
|
{{ core()->formatPrice($invoice->tax_amount, $order->order_currency_code) }}
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
@ -180,7 +185,8 @@
|
||||||
</div>
|
</div>
|
||||||
</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;">
|
<p style="font-size: 16px;color: #5E5E5E;line-height: 24px;">
|
||||||
{!!
|
{!!
|
||||||
__('shop::app.mail.order.help', [
|
__('shop::app.mail.order.help', [
|
||||||
|
|
|
||||||
|
|
@ -156,12 +156,14 @@
|
||||||
</div>
|
</div>
|
||||||
@endif
|
@endif
|
||||||
|
|
||||||
|
@foreach (Webkul\Tax\Helpers\Tax::getTaxRatesWithAmount($order, false) as $taxRate => $taxAmount )
|
||||||
<div>
|
<div>
|
||||||
<span>{{ __('shop::app.mail.order.tax') }}</span>
|
<span id="taxrate-{{ core()->taxRateAsIdentifier($taxRate) }}">{{ __('shop::app.mail.order.tax') }} {{ $taxRate }} %</span>
|
||||||
<span style="float: right;">
|
<span id="taxamount-{{ core()->taxRateAsIdentifier($taxRate) }}" style="float: right;">
|
||||||
{{ core()->formatPrice($order->tax_amount, $order->order_currency_code) }}
|
{{ core()->formatPrice($taxAmount, $order->order_currency_code) }}
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
|
@endforeach
|
||||||
|
|
||||||
@if ($order->discount_amount > 0)
|
@if ($order->discount_amount > 0)
|
||||||
<div>
|
<div>
|
||||||
|
|
|
||||||
|
|
@ -160,12 +160,14 @@
|
||||||
@endif
|
@endif
|
||||||
|
|
||||||
@if ($refund->tax_amount > 0)
|
@if ($refund->tax_amount > 0)
|
||||||
|
@foreach (Webkul\Tax\Helpers\Tax::getTaxRatesWithAmount($refund, false) as $taxRate => $taxAmount)
|
||||||
<div>
|
<div>
|
||||||
<span>{{ __('shop::app.mail.order.tax') }}</span>
|
<span>{{ __('shop::app.mail.order.tax') }}</span>
|
||||||
<span style="float: right;">
|
<span style="float: right;">
|
||||||
{{ core()->formatPrice($refund->tax_amount, $refund->order_currency_code) }}
|
{{ core()->formatPrice($refund->tax_amount, $refund->order_currency_code) }}
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
|
@endforeach
|
||||||
@endif
|
@endif
|
||||||
|
|
||||||
@if ($refund->discount_amount > 0)
|
@if ($refund->discount_amount > 0)
|
||||||
|
|
|
||||||
|
|
@ -122,7 +122,7 @@
|
||||||
<tbody>
|
<tbody>
|
||||||
@foreach ($shipment->items as $item)
|
@foreach ($shipment->items as $item)
|
||||||
<tr>
|
<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">
|
<td data-value="{{ __('shop::app.customer.account.order.view.product-name') }}" style="text-align: left;padding: 8px">
|
||||||
{{ $item->name }}
|
{{ $item->name }}
|
||||||
|
|
|
||||||
|
|
@ -157,12 +157,14 @@
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div>
|
@foreach (Webkul\Tax\Helpers\Tax::getTaxRatesWithAmount($order, false) as $taxRate => $taxAmount )
|
||||||
<span>{{ __('shop::app.mail.order.cancel.tax') }}</span>
|
<div>
|
||||||
<span style="float: right;">
|
<span id="taxrate-{{ core()->taxRateAsIdentifier($taxRate) }}">{{ __('shop::app.mail.order.cancel.tax') }} {{ $taxRate }} %</span>
|
||||||
{{ core()->formatPrice($order->tax_amount, $order->order_currency_code) }}
|
<span id="taxamount-{{ core()->taxRateAsIdentifier($taxRate) }}" style="float: right;">
|
||||||
|
{{ core()->formatPrice($taxAmount, $order->order_currency_code) }}
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
|
@endforeach
|
||||||
|
|
||||||
@if ($order->discount_amount > 0)
|
@if ($order->discount_amount > 0)
|
||||||
<div>
|
<div>
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,9 @@
|
||||||
$products = $productRepository->getAll($category->id);
|
$products = $productRepository->getAll($category->id);
|
||||||
|
|
||||||
$filterAttributes = $productFlatRepository->getFilterableAttributes($category, $products);
|
$filterAttributes = $productFlatRepository->getFilterableAttributes($category, $products);
|
||||||
} else {
|
}
|
||||||
|
|
||||||
|
if (! count($filterAttributes) > 0) {
|
||||||
$filterAttributes = $attributeRepository->getFilterAttributes();
|
$filterAttributes = $attributeRepository->getFilterAttributes();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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),
|
||||||
|
];
|
||||||
|
});
|
||||||
|
|
@ -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;
|
||||||
|
},
|
||||||
|
];
|
||||||
|
});
|
||||||
|
|
@ -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),
|
||||||
|
];
|
||||||
|
});
|
||||||
|
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -22,5 +22,6 @@ class TaxServiceProvider extends ServiceProvider
|
||||||
*/
|
*/
|
||||||
public function register()
|
public function register()
|
||||||
{
|
{
|
||||||
|
$this->loadFactoriesFrom(__DIR__ . '/../Database/Factories');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -228,7 +228,7 @@ use Webkul\Velocity\Repositories\Product\ProductRepository as VelocityProductRep
|
||||||
'slug' => $product->url_key,
|
'slug' => $product->url_key,
|
||||||
'image' => $productImage,
|
'image' => $productImage,
|
||||||
'description' => $product->description,
|
'description' => $product->description,
|
||||||
'shortDescription' => $product->meta_description,
|
'shortDescription' => $product->short_description,
|
||||||
'galleryImages' => $galleryImages,
|
'galleryImages' => $galleryImages,
|
||||||
'priceHTML' => view('shop::products.price', ['product' => $product])->render(),
|
'priceHTML' => view('shop::products.price', ['product' => $product])->render(),
|
||||||
'totalReviews' => $totalReviews,
|
'totalReviews' => $totalReviews,
|
||||||
|
|
|
||||||
|
|
@ -108,6 +108,9 @@ return [
|
||||||
'footer-middle-content' => 'Footer Middle Content',
|
'footer-middle-content' => 'Footer Middle Content',
|
||||||
'advertisement-four' => 'Advertisement Four Images',
|
'advertisement-four' => 'Advertisement Four Images',
|
||||||
'advertisement-three' => 'Advertisement Three Images',
|
'advertisement-three' => 'Advertisement Three Images',
|
||||||
|
'images' => 'Images',
|
||||||
|
'general' => 'General',
|
||||||
|
'add-image-btn-title' => 'Add Image'
|
||||||
],
|
],
|
||||||
'category' => [
|
'category' => [
|
||||||
'save-btn-title' => 'Save Menu',
|
'save-btn-title' => 'Save Menu',
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,7 @@
|
||||||
</div>
|
</div>
|
||||||
</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 slot="body">
|
||||||
<div class="control-group">
|
<div class="control-group">
|
||||||
<label>{{ __('velocity::app.admin.meta-data.activate-slider') }}</label>
|
<label>{{ __('velocity::app.admin.meta-data.activate-slider') }}</label>
|
||||||
|
|
@ -106,19 +106,19 @@
|
||||||
</div>
|
</div>
|
||||||
</accordian>
|
</accordian>
|
||||||
|
|
||||||
<accordian :title="'{{ __('admin::app.catalog.products.images') }}'" :active="false">
|
<accordian :title="'{{ __('velocity::app.admin.meta-data.images') }}'" :active="false">
|
||||||
<div slot="body">
|
<div slot="body">
|
||||||
<div class="control-group">
|
<div class="control-group">
|
||||||
<label>{{ __('velocity::app.admin.meta-data.advertisement-four') }}</label>
|
<label>{{ __('velocity::app.admin.meta-data.advertisement-four') }}</label>
|
||||||
|
|
||||||
@if(! isset($metaData->advertisement[4]))
|
@if(! isset($metaData->advertisement[4]))
|
||||||
<image-wrapper
|
<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]">
|
input-name="images[4]">
|
||||||
</image-wrapper>
|
</image-wrapper>
|
||||||
@else
|
@else
|
||||||
<image-wrapper
|
<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])'>
|
input-name="images[4]" :images='@json($metaData->advertisement[4])'>
|
||||||
</image-wrapper>
|
</image-wrapper>
|
||||||
@endif
|
@endif
|
||||||
|
|
@ -128,12 +128,12 @@
|
||||||
<label>{{ __('velocity::app.admin.meta-data.advertisement-three') }}</label>
|
<label>{{ __('velocity::app.admin.meta-data.advertisement-three') }}</label>
|
||||||
@if(! isset($metaData->advertisement[3]))
|
@if(! isset($metaData->advertisement[3]))
|
||||||
<image-wrapper
|
<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]">
|
input-name="images[3]">
|
||||||
</image-wrapper>
|
</image-wrapper>
|
||||||
@else
|
@else
|
||||||
<image-wrapper
|
<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])'>
|
input-name="images[3]" :images='@json($metaData->advertisement[3])'>
|
||||||
</image-wrapper>
|
</image-wrapper>
|
||||||
@endif
|
@endif
|
||||||
|
|
@ -144,33 +144,16 @@
|
||||||
|
|
||||||
@if(! isset($metaData->advertisement[2]))
|
@if(! isset($metaData->advertisement[2]))
|
||||||
<image-wrapper
|
<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]">
|
input-name="images[2]">
|
||||||
</image-wrapper>
|
</image-wrapper>
|
||||||
@else
|
@else
|
||||||
<image-wrapper
|
<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])'>
|
input-name="images[2]" :images='@json($metaData->advertisement[2])'>
|
||||||
</image-wrapper>
|
</image-wrapper>
|
||||||
@endif
|
@endif
|
||||||
</div>
|
</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>
|
</div>
|
||||||
</accordian>
|
</accordian>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -218,9 +218,11 @@
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'shipping-form':
|
case 'shipping-form':
|
||||||
document.body.style.cursor = 'wait';
|
if (this.showShippingSection) {
|
||||||
this.saveShipping();
|
document.body.style.cursor = 'wait';
|
||||||
break;
|
this.saveShipping();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
case 'payment-form':
|
case 'payment-form':
|
||||||
document.body.style.cursor = 'wait';
|
document.body.style.cursor = 'wait';
|
||||||
|
|
|
||||||
|
|
@ -14,10 +14,12 @@
|
||||||
@endif
|
@endif
|
||||||
|
|
||||||
@if ($cart->base_tax_total)
|
@if ($cart->base_tax_total)
|
||||||
<div class="row">
|
@foreach (Webkul\Tax\Helpers\Tax::getTaxRatesWithAmount($cart, true) as $taxRate => $baseTaxAmount )
|
||||||
<span class="col-8">{{ __('shop::app.checkout.total.tax') }}</span>
|
<div class="row">
|
||||||
<span class="col-4 text-right">{{ core()->currency($cart->base_tax_total) }}</span>
|
<span class="col-8" id="taxrate-{{ core()->taxRateAsIdentifier($taxRate) }}">{{ __('shop::app.checkout.total.tax') }} {{ $taxRate }} %</span>
|
||||||
</div>
|
<span class="col-4 text-right" id="basetaxamount-{{ core()->taxRateAsIdentifier($taxRate) }}">{{ core()->currency($baseTaxAmount) }}</span>
|
||||||
|
</div>
|
||||||
|
@endforeach
|
||||||
@endif
|
@endif
|
||||||
|
|
||||||
@if (
|
@if (
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,9 @@
|
||||||
$products = $productRepository->getAll($category->id);
|
$products = $productRepository->getAll($category->id);
|
||||||
|
|
||||||
$filterAttributes = $productFlatRepository->getFilterableAttributes($category, $products);
|
$filterAttributes = $productFlatRepository->getFilterableAttributes($category, $products);
|
||||||
} else {
|
}
|
||||||
|
|
||||||
|
if (! count($filterAttributes) > 0) {
|
||||||
$filterAttributes = $attributeRepository->getFilterAttributes();
|
$filterAttributes = $attributeRepository->getFilterAttributes();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -202,9 +202,15 @@
|
||||||
|
|
||||||
computed: {
|
computed: {
|
||||||
product_qty: function() {
|
product_qty: function() {
|
||||||
return this.option.products[this.selected_product]
|
var self = this;
|
||||||
? this.option.products[this.selected_product].qty
|
self.qty = 0;
|
||||||
: 0;
|
|
||||||
|
self.option.products.forEach(function(product, key){
|
||||||
|
if (self.selected_product == product.id)
|
||||||
|
self.qty = self.option.products[key].qty;
|
||||||
|
});
|
||||||
|
|
||||||
|
return self.qty;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,7 @@ use Codeception\Stub;
|
||||||
* @method void pause()
|
* @method void pause()
|
||||||
*
|
*
|
||||||
* @SuppressWarnings(PHPMD)
|
* @SuppressWarnings(PHPMD)
|
||||||
*/
|
*/
|
||||||
class UnitTester extends \Codeception\Actor
|
class UnitTester extends \Codeception\Actor
|
||||||
{
|
{
|
||||||
use _generated\UnitTesterActions;
|
use _generated\UnitTesterActions;
|
||||||
|
|
|
||||||
|
|
@ -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();
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -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)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Tests\Webkul\Unit\Shop;
|
namespace Tests\Functional\Shop;
|
||||||
|
|
||||||
use Codeception\Example;
|
use Codeception\Example;
|
||||||
use FunctionalTester;
|
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->productNoGuestCheckout->refresh();
|
||||||
|
|
||||||
$this->productGuestCheckout = $I->haveProduct(Laravel5Helper::SIMPLE_PRODUCT, $pConfigGuestCheckout, ['simple']);
|
$this->productGuestCheckout = $I->haveProduct(Laravel5Helper::SIMPLE_PRODUCT, $pConfigGuestCheckout);
|
||||||
$this->productGuestCheckout->refresh();
|
$this->productGuestCheckout->refresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,34 +3,46 @@
|
||||||
namespace Tests\Unit\Checkout\Cart\Controllers;
|
namespace Tests\Unit\Checkout\Cart\Controllers;
|
||||||
|
|
||||||
use UnitTester;
|
use UnitTester;
|
||||||
|
use Codeception\Example;
|
||||||
use Webkul\Checkout\Models\Cart;
|
use Webkul\Checkout\Models\Cart;
|
||||||
use Webkul\Shop\Http\Controllers\CartController;
|
use Webkul\Shop\Http\Controllers\CartController;
|
||||||
|
|
||||||
class CartControllerCest
|
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,
|
'expected' => true,
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'result' => ['key' => 'value'],
|
'result' => ['key' => 'value'],
|
||||||
'expected' => false,
|
'expected' => false,
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'result' => new Cart(),
|
'result' => new Cart(),
|
||||||
'expected' => false,
|
'expected' => false,
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
|
|
||||||
foreach ($scenarios as $scenario) {
|
|
||||||
$I->assertEquals($scenario['expected'], $I->executeFunction(CartController::class, 'onWarningAddingToCart', [$scenario['result']]));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -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',
|
||||||
|
],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue