Merge branch 'master' of https://github.com/bagisto/bagisto into development
This commit is contained in:
commit
1144ce7e10
|
|
@ -0,0 +1,7 @@
|
|||
<?php
|
||||
|
||||
return [
|
||||
|
||||
];
|
||||
|
||||
?>
|
||||
|
|
@ -96,7 +96,7 @@ return [
|
|||
'key' => 'configuration',
|
||||
'name' => 'admin::app.layouts.configure',
|
||||
'route' => 'admin.configuration.index',
|
||||
'sort' => 5,
|
||||
'sort' => 7,
|
||||
'icon-class' => 'configuration-icon',
|
||||
], [
|
||||
'key' => 'settings',
|
||||
|
|
@ -177,23 +177,16 @@ return [
|
|||
'sort' => 2,
|
||||
'icon-class' => '',
|
||||
], [
|
||||
'key' => 'promotion',
|
||||
'key' => 'promotions',
|
||||
'name' => 'admin::app.layouts.promotion',
|
||||
'route' => 'admin.cart-rule.index',
|
||||
'sort' => 7,
|
||||
'sort' => 5,
|
||||
'icon-class' => 'promotion-icon',
|
||||
], [
|
||||
'key' => 'promotion.cart-rule',
|
||||
'key' => 'promotions.cart-rule',
|
||||
'name' => 'admin::app.promotion.cart-rule',
|
||||
'route' => 'admin.cart-rule.index',
|
||||
'sort' => 1,
|
||||
'icon-class' => '',
|
||||
]
|
||||
// , [
|
||||
// 'key' => 'promotion.catalog-rule',
|
||||
// 'name' => 'admin::app.promotion.catalog-rule',
|
||||
// 'route' => 'admin.catalog-rule.index',
|
||||
// 'sort' => 1,
|
||||
// 'icon-class' => '',
|
||||
// ]
|
||||
];
|
||||
|
|
@ -19,7 +19,7 @@ class CustomerGroupDataGrid extends DataGrid
|
|||
|
||||
public function prepareQueryBuilder()
|
||||
{
|
||||
$queryBuilder = DB::table('customer_groups')->addSelect('id', 'name');
|
||||
$queryBuilder = DB::table('customer_groups')->addSelect('id', 'code', 'name');
|
||||
|
||||
$this->setQueryBuilder($queryBuilder);
|
||||
}
|
||||
|
|
@ -35,6 +35,15 @@ class CustomerGroupDataGrid extends DataGrid
|
|||
'filterable' => true
|
||||
]);
|
||||
|
||||
$this->addColumn([
|
||||
'index' => 'code',
|
||||
'label' => 'Code',
|
||||
'type' => 'number',
|
||||
'searchable' => false,
|
||||
'sortable' => true,
|
||||
'filterable' => true
|
||||
]);
|
||||
|
||||
$this->addColumn([
|
||||
'index' => 'name',
|
||||
'label' => 'Name',
|
||||
|
|
|
|||
|
|
@ -83,7 +83,7 @@ class CustomerController extends Controller
|
|||
*/
|
||||
public function create()
|
||||
{
|
||||
$customerGroup = $this->customerGroup->all();
|
||||
$customerGroup = $this->customerGroup->findWhere([['code', '<>', 'guest']]);
|
||||
|
||||
$channelName = $this->channel->all();
|
||||
|
||||
|
|
@ -131,7 +131,7 @@ class CustomerController extends Controller
|
|||
{
|
||||
$customer = $this->customer->findOrFail($id);
|
||||
|
||||
$customerGroup = $this->customerGroup->all();
|
||||
$customerGroup = $this->customerGroup->findWhere([['code', '<>', 'guest']]);
|
||||
|
||||
$channelName = $this->channel->all();
|
||||
|
||||
|
|
|
|||
|
|
@ -72,7 +72,8 @@ class CustomerGroupController extends Controller
|
|||
public function store()
|
||||
{
|
||||
$this->validate(request(), [
|
||||
'name' => 'string|required',
|
||||
'code' => ['required', 'unique:customer_groups,code', new \Webkul\Core\Contracts\Validations\Code],
|
||||
'name' => 'required',
|
||||
]);
|
||||
|
||||
$data = request()->all();
|
||||
|
|
@ -109,7 +110,8 @@ class CustomerGroupController extends Controller
|
|||
public function update(Request $request, $id)
|
||||
{
|
||||
$this->validate(request(), [
|
||||
'name' => 'string|required',
|
||||
'code' => ['required', 'unique:customer_groups,code,' . $id, new \Webkul\Core\Contracts\Validations\Code],
|
||||
'name' => 'required',
|
||||
]);
|
||||
|
||||
$this->customerGroup->update(request()->all(), $id);
|
||||
|
|
|
|||
|
|
@ -649,27 +649,27 @@ Route::group(['middleware' => ['web']], function () {
|
|||
|
||||
// Route::post('fetch/options', 'Webkul\Discount\Http\Controllers\CatalogRuleController@fetchAttributeOptions')->name('admin.catalog-rule.options');
|
||||
|
||||
Route::get('/cart-rule', 'Webkul\Discount\Http\Controllers\CartRuleController@index')->defaults('_config', [
|
||||
Route::get('cart-rules', 'Webkul\Discount\Http\Controllers\CartRuleController@index')->defaults('_config', [
|
||||
'view' => 'admin::promotions.cart-rule.index'
|
||||
])->name('admin.cart-rule.index');
|
||||
|
||||
Route::get('/cart-rule/create', 'Webkul\Discount\Http\Controllers\CartRuleController@create')->defaults('_config', [
|
||||
Route::get('cart-rules/create', 'Webkul\Discount\Http\Controllers\CartRuleController@create')->defaults('_config', [
|
||||
'view' => 'admin::promotions.cart-rule.create'
|
||||
])->name('admin.cart-rule.create');
|
||||
|
||||
Route::post('/cart-rule/store', 'Webkul\Discount\Http\Controllers\CartRuleController@store')->defaults('_config', [
|
||||
Route::post('cart-rules/store', 'Webkul\Discount\Http\Controllers\CartRuleController@store')->defaults('_config', [
|
||||
'redirect' => 'admin.cart-rule.index'
|
||||
])->name('admin.cart-rule.store');
|
||||
|
||||
Route::get('/cart-rule/edit/{id}', 'Webkul\Discount\Http\Controllers\CartRuleController@edit')->defaults('_config', [
|
||||
Route::get('cart-rules/edit/{id}', 'Webkul\Discount\Http\Controllers\CartRuleController@edit')->defaults('_config', [
|
||||
'view' => 'admin::promotions.cart-rule.edit'
|
||||
])->name('admin.cart-rule.edit');
|
||||
|
||||
Route::post('/cart-rule/update/{id}', 'Webkul\Discount\Http\Controllers\CartRuleController@update')->defaults('_config', [
|
||||
Route::post('cart-rules/update/{id}', 'Webkul\Discount\Http\Controllers\CartRuleController@update')->defaults('_config', [
|
||||
'redirect' => 'admin.cart-rule.index'
|
||||
])->name('admin.cart-rule.update');
|
||||
|
||||
Route::post('/cart-rule/delete/{id}', 'Webkul\Discount\Http\Controllers\CartRuleController@destroy')->name('admin.cart-rule.delete');
|
||||
Route::post('cart-rules/delete/{id}', 'Webkul\Discount\Http\Controllers\CartRuleController@destroy')->name('admin.cart-rule.delete');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -659,6 +659,7 @@ return [
|
|||
'save-btn-title' => 'احفظ المجموعة',
|
||||
'title' => 'المجموعات',
|
||||
'save-btn-title' => 'احفظ المجموعة',
|
||||
'code' => 'Code',
|
||||
'name' => 'Name',
|
||||
'is_user_defined' => 'تعريف المستخدم',
|
||||
'yes' => 'نعم.'
|
||||
|
|
|
|||
|
|
@ -735,6 +735,7 @@ return [
|
|||
'save-btn-title' => 'Save Group',
|
||||
'title' => 'Groups',
|
||||
'save-btn-title' => 'Save Group',
|
||||
'code' => 'Code',
|
||||
'name' => 'Name',
|
||||
'is_user_defined' => 'User Defined',
|
||||
'yes' => 'Yes'
|
||||
|
|
@ -799,7 +800,7 @@ return [
|
|||
|
||||
'promotion' => [
|
||||
'catalog-rule' => 'Catalog Rules',
|
||||
'cart-rule' => 'Cart Rule',
|
||||
'cart-rule' => 'Cart Rules',
|
||||
'add-catalog-rule' => 'Add Catalog Rule',
|
||||
'add-cart-rule' => 'Add Cart Rule',
|
||||
'edit-cart-rule' => 'Edit Cart Rule',
|
||||
|
|
|
|||
|
|
@ -673,6 +673,7 @@ return [
|
|||
'save-btn-title' => 'Salvar Grupo',
|
||||
'title' => 'Grupos',
|
||||
'save-btn-title' => 'Salvar Grupo',
|
||||
'code' => 'Code',
|
||||
'name' => 'Nome',
|
||||
'is_user_defined' => 'Usuário Definido',
|
||||
'yes' => 'Sim'
|
||||
|
|
|
|||
|
|
@ -28,6 +28,13 @@
|
|||
<div class="form-container">
|
||||
@csrf()
|
||||
|
||||
|
||||
<div class="control-group" :class="[errors.has('code') ? 'has-error' : '']">
|
||||
<label for="code" class="required">{{ __('admin::app.customers.groups.code') }}</label>
|
||||
<input v-validate="'required'" class="control" id="code" name="code" data-vv-as=""{{ __('admin::app.customers.groups.code') }}"" v-code/>
|
||||
<span class="control-error" v-if="errors.has('code')">@{{ errors.first('code') }}</span>
|
||||
</div>
|
||||
|
||||
<div class="control-group" :class="[errors.has('name') ? 'has-error' : '']">
|
||||
<label for="name" class="required">
|
||||
{{ __('admin::app.customers.groups.name') }}
|
||||
|
|
|
|||
|
|
@ -31,6 +31,13 @@
|
|||
|
||||
<input name="_method" type="hidden" value="PUT">
|
||||
|
||||
<div class="control-group" :class="[errors.has('code') ? 'has-error' : '']">
|
||||
<label for="code" class="required">{{ __('admin::app.customers.groups.code') }}</label>
|
||||
<input type="text" v-validate="'required'" class="control" id="code" name="code" data-vv-as=""{{ __('admin::app.customers.groups.code') }}"" value="{{ $group->code }}" disabled="disabled"/>
|
||||
<input type="hidden" name="code" value="{{ $group->code }}"/>
|
||||
<span class="control-error" v-if="errors.has('code')">@{{ errors.first('code') }}</span>
|
||||
</div>
|
||||
|
||||
<div class="control-group" :class="[errors.has('name') ? 'has-error' : '']">
|
||||
<label for="name" class="required">
|
||||
{{ __('admin::app.customers.groups.name') }}
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@
|
|||
@endif
|
||||
</ul>
|
||||
|
||||
{{-- <div class="close-nav-aside">
|
||||
<!-- <div class="close-nav-aside">
|
||||
<i class="icon angle-left-icon close-icon"></i>
|
||||
</div> --}}
|
||||
</div> -->
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -74,7 +74,7 @@
|
|||
</div>
|
||||
</datetime>
|
||||
|
||||
{{-- <div class="control-group" :class="[errors.has('customer_groups[]') ? 'has-error' : '']">
|
||||
<div class="control-group" :class="[errors.has('customer_groups[]') ? 'has-error' : '']">
|
||||
<label for="customer_groups" class="required">{{ __('admin::app.promotion.general-info.cust-groups') }}</label>
|
||||
|
||||
<select type="text" class="control" name="customer_groups[]" v-model="customer_groups" v-validate="'required'" value="{{ old('customer_groups[]') }}" data-vv-as=""{{ __('admin::app.promotion.general-info.cust-groups') }}"" multiple="multiple">
|
||||
|
|
@ -85,7 +85,7 @@
|
|||
</select>
|
||||
|
||||
<span class="control-error" v-if="errors.has('customer_groups')">@{{ errors.first('customer_groups') }}</span>
|
||||
</div> --}}
|
||||
</div>
|
||||
|
||||
<div class="control-group" :class="[errors.has('channels[]') ? 'has-error' : '']">
|
||||
<label for="channels" class="required">{{ __('admin::app.promotion.general-info.channels') }}</label>
|
||||
|
|
@ -213,7 +213,7 @@
|
|||
|
||||
<div v-if='conditions_list[index].type == "string"'>
|
||||
<select class="control" name="cart_attributes[]" v-model="conditions_list[index].condition" style="margin-right: 15px;">
|
||||
<option v-for="(condition, index) in conditions.numeric" :value="index" :key="index">@{{ condition }}</option>
|
||||
<option v-for="(condition, index) in conditions.string" :value="index" :key="index">@{{ condition }}</option>
|
||||
</select>
|
||||
|
||||
<div v-if='conditions_list[index].attribute == "shipping_state"'>
|
||||
|
|
@ -459,15 +459,13 @@
|
|||
}
|
||||
},
|
||||
|
||||
mounted () {
|
||||
},
|
||||
|
||||
methods: {
|
||||
addCondition () {
|
||||
if (this.criteria == 'product_subselection' || this.criteria == 'cart') {
|
||||
this.condition_on = this.criteria;
|
||||
} else {
|
||||
alert('please try again');
|
||||
alert('Please select type of condition');
|
||||
|
||||
return false;
|
||||
}
|
||||
|
|
@ -476,7 +474,6 @@
|
|||
this.conditions_list.push(this.cart_object);
|
||||
|
||||
this.cart_object = {
|
||||
criteria: null,
|
||||
attribute: null,
|
||||
condition: null,
|
||||
value: []
|
||||
|
|
@ -503,7 +500,6 @@
|
|||
for (i in this.cart_input) {
|
||||
if (i == selectedIndex) {
|
||||
this.conditions_list[index].type = this.cart_input[i].type;
|
||||
console.log(this.conditions_list[index]);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
|
@ -526,10 +522,10 @@
|
|||
|
||||
onSubmit: function (e) {
|
||||
if (this.conditions_list.length != 0) {
|
||||
this.conditions_list.test_mode = this.match_criteria;
|
||||
}
|
||||
this.conditions_list.push({'criteria': this.match_criteria});
|
||||
|
||||
this.all_conditions = JSON.stringify(this.conditions_list);
|
||||
this.all_conditions = JSON.stringify(this.conditions_list);
|
||||
}
|
||||
|
||||
this.$validator.validateAll().then(result => {
|
||||
if (result) {
|
||||
|
|
|
|||
|
|
@ -76,7 +76,7 @@
|
|||
</div>
|
||||
</datetime>
|
||||
|
||||
{{-- <div class="control-group" :class="[errors.has('customer_groups[]') ? 'has-error' : '']">
|
||||
<div class="control-group" :class="[errors.has('customer_groups[]') ? 'has-error' : '']">
|
||||
<label for="customer_groups" class="required">{{ __('admin::app.promotion.general-info.cust-groups') }}</label>
|
||||
|
||||
<select type="text" class="control" name="customer_groups[]" v-model="customer_groups" v-validate="'required'" value="{{ old('customer_groups[]') }}" data-vv-as=""{{ __('admin::app.promotion.general-info.cust-groups') }}"" multiple="multiple">
|
||||
|
|
@ -86,8 +86,8 @@
|
|||
@endforeach
|
||||
</select>
|
||||
|
||||
<span class="control-error" v-if="errors.has('customer_groups')">@{{ errors.first('customer_groups') }}</span>
|
||||
</div> --}}
|
||||
<span class="control-error" v-if="errors.has('customer_groups[]')">@{{ errors.first('customer_groups[]') }}</span>
|
||||
</div>
|
||||
|
||||
<div class="control-group" :class="[errors.has('channels[]') ? 'has-error' : '']">
|
||||
<label for="channels" class="required">{{ __('admin::app.promotion.general-info.channels') }}</label>
|
||||
|
|
@ -187,7 +187,7 @@
|
|||
|
||||
<div class="control-group">
|
||||
{{ __('admin::app.promotion.general-info.test-mode') }}
|
||||
<select class="control" v-model="match_criteria" style="margin-right: 15px;">
|
||||
<select class="control" v-model="match_criteria" name="match_criteria" style="margin-right: 15px;">
|
||||
{{ $i = 0 }}
|
||||
@foreach(config('pricerules.test_mode') as $key => $value)
|
||||
<option value="{{ $key }}">{{ $value }}</option>
|
||||
|
|
@ -213,7 +213,7 @@
|
|||
|
||||
<div v-if='conditions_list[index].type == "string"'>
|
||||
<select class="control" name="cart_attributes[]" v-model="conditions_list[index].condition" style="margin-right: 15px;">
|
||||
<option v-for="(condition, index) in conditions.numeric" :value="index" :key="index">@{{ condition }}</option>
|
||||
<option v-for="(condition, index) in conditions.string" :value="index" :key="index">@{{ condition }}</option>
|
||||
</select>
|
||||
|
||||
<div v-if='conditions_list[index].attribute == "shipping_state"'>
|
||||
|
|
@ -501,6 +501,7 @@
|
|||
|
||||
if (data.conditions != null) {
|
||||
this.conditions_list = JSON.parse(JSON.parse(data.conditions));
|
||||
this.match_criteria = this.conditions_list.pop().criteria;
|
||||
}
|
||||
|
||||
criteria = null;
|
||||
|
|
@ -511,7 +512,7 @@
|
|||
if (this.criteria == 'product_subselection' || this.criteria == 'cart') {
|
||||
this.condition_on = this.criteria;
|
||||
} else {
|
||||
alert('please try again');
|
||||
alert('please select type of condition');
|
||||
|
||||
return false;
|
||||
}
|
||||
|
|
@ -567,14 +568,11 @@
|
|||
},
|
||||
|
||||
onSubmit: function (e) {
|
||||
if (this.conditions_list.length != 0) {
|
||||
this.conditions_list.push({'criteria': this.match_criteria});
|
||||
|
||||
// if (this.conditions_list.length != 0) {
|
||||
// this.conditions_list.push(this.match_criteria);
|
||||
// }
|
||||
|
||||
console.log(JSON.stringify(this.conditions_list));
|
||||
|
||||
this.all_conditions = JSON.stringify(this.conditions_list);
|
||||
this.all_conditions = JSON.stringify(this.conditions_list);
|
||||
}
|
||||
|
||||
this.$validator.validateAll().then(result => {
|
||||
if (result) {
|
||||
|
|
|
|||
|
|
@ -12,8 +12,6 @@ use Webkul\Tax\Repositories\TaxCategoryRepository;
|
|||
use Webkul\Checkout\Models\CartPayment;
|
||||
use Webkul\Customer\Repositories\WishlistRepository;
|
||||
use Webkul\Customer\Repositories\CustomerAddressRepository;
|
||||
use Webkul\Discount\Repositories\CartRuleRepository as CartRule;
|
||||
use Webkul\Discount\Helpers\Discount;
|
||||
use Webkul\Product\Helpers\Price;
|
||||
|
||||
/**
|
||||
|
|
@ -81,16 +79,6 @@ class Cart {
|
|||
*/
|
||||
protected $customerAddress;
|
||||
|
||||
/**
|
||||
* CartRule Repository instance
|
||||
*/
|
||||
protected $cartRule;
|
||||
|
||||
/**
|
||||
* Discount helper instance
|
||||
*/
|
||||
protected $discount;
|
||||
|
||||
/**
|
||||
* Suppress the session flash messages
|
||||
*/
|
||||
|
|
@ -125,8 +113,6 @@ class Cart {
|
|||
TaxCategoryRepository $taxCategory,
|
||||
WishlistRepository $wishlist,
|
||||
CustomerAddressRepository $customerAddress,
|
||||
CartRule $cartRule,
|
||||
Discount $discount,
|
||||
Price $price
|
||||
)
|
||||
{
|
||||
|
|
@ -146,10 +132,6 @@ class Cart {
|
|||
|
||||
$this->customerAddress = $customerAddress;
|
||||
|
||||
$this->cartRule = $cartRule;
|
||||
|
||||
$this->discount = $discount;
|
||||
|
||||
$this->price = $price;
|
||||
|
||||
$this->suppressFlash = false;
|
||||
|
|
@ -1092,59 +1074,6 @@ class Cart {
|
|||
return $finalData;
|
||||
}
|
||||
|
||||
/**
|
||||
* Save discount data for cart
|
||||
*/
|
||||
public function saveDiscount()
|
||||
{
|
||||
$rule = $impact['rule'];
|
||||
|
||||
$cart = $this->getCart();
|
||||
|
||||
//update the cart items
|
||||
foreach($cart->items as $item) {
|
||||
if ($rule->use_coupon) {
|
||||
if ($rule->action_type != config('pricerules.cart.validation.0')) {
|
||||
$item->update([
|
||||
'coupon_code' => $rule->coupon->code,
|
||||
'discount_amount' => core()->convertPrice($impact['amount'], $cart->channel_currency_code),
|
||||
'base_discount_amount' => $impact['amount']
|
||||
]);
|
||||
} else {
|
||||
$item->update([
|
||||
'coupon_code' => $rule->coupon->code,
|
||||
'discount_percent' => $rule->disc_amount
|
||||
]);
|
||||
}
|
||||
} else {
|
||||
if ($rule->action_type != config('pricerules.cart.validation.0')) {
|
||||
$item->update([
|
||||
'discount_amount' => core()->convertPrice($impact['amount'], $cart->channel_currency_code),
|
||||
'base_discount_amount' => $impact['amount']
|
||||
]);
|
||||
} else {
|
||||
$item->update([
|
||||
'discount_percent' => $rule->disc_amount
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// update the cart
|
||||
if ($rule->use_coupon) {
|
||||
$cart->update([
|
||||
'coupon_code' => $rule->coupons->code,
|
||||
'discount_amount' => core()->convertPrice($impact['amount'], $cart->channel_currency_code),
|
||||
'base_discount_amount' => $impact['amount']
|
||||
]);
|
||||
} else {
|
||||
$cart->update([
|
||||
'discount_amount' => core()->convertPrice($impact['amount'], $cart->channel_currency_code),
|
||||
'base_discount_amount' => $impact['amount']
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepares data for order item
|
||||
*
|
||||
|
|
@ -1288,94 +1217,4 @@ class Cart {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function applyCoupon($code)
|
||||
{
|
||||
$result = $this->discount->applyCouponAbleRule($code);
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function applyNonCoupon()
|
||||
{
|
||||
$result = $this->discount->applyNonCouponAbleRule();
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes discount from the cart and calls collect totals
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function clearDiscount()
|
||||
{
|
||||
$cartItems = $this->getCart()->items;
|
||||
|
||||
foreach($cartItems as $item) {
|
||||
$item->update([
|
||||
'coupon_code' => NULL,
|
||||
'discount_percent' => 0,
|
||||
'discount_amount' => 0,
|
||||
'base_discount_amount' => 0
|
||||
]);
|
||||
}
|
||||
|
||||
$this->getCart()->update([
|
||||
'coupon_code' => NULL,
|
||||
'discount_amount' => 0,
|
||||
'base_discount_amount' => 0
|
||||
]);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// public function removeCoupon()
|
||||
// {
|
||||
// $result = $this->discount->removeCoupon();
|
||||
|
||||
// return $result;
|
||||
// }
|
||||
|
||||
public function leastWorthItem()
|
||||
{
|
||||
$cart = $this->getCart();
|
||||
$leastValue = 999999999999;
|
||||
$leastSubTotal = [];
|
||||
|
||||
foreach ($cart->items as $item) {
|
||||
if ($item->price < $leastValue) {
|
||||
$leastValue = $item->price;
|
||||
$leastSubTotal = [
|
||||
'id' => $item->id,
|
||||
'total' => $item->total,
|
||||
'base_total' => $leastValue,
|
||||
'quantity' => $item->quantity
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
return $leastSubTotal;
|
||||
}
|
||||
|
||||
public function maxWorthItem()
|
||||
{
|
||||
$cart = $this->getCart();
|
||||
$maxValue = 0;
|
||||
$maxSubTotal = [];
|
||||
|
||||
foreach ($cart->items as $item) {
|
||||
if ($item->base_total > $maxValue) {
|
||||
$maxValue = $item->total;
|
||||
$maxSubTotal = [
|
||||
'id' => $item->id,
|
||||
'total' => $item->total,
|
||||
'base_total' => $maxValue,
|
||||
'quantity' => $item->quantity
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
return $maxSubTotal;
|
||||
}
|
||||
}
|
||||
|
|
@ -69,17 +69,17 @@ class Tree {
|
|||
/**
|
||||
* Add a Config item to the item stack
|
||||
*
|
||||
* @param string $item Dot seperated heirarchy
|
||||
* @param string $item Dot seperated heirarchy
|
||||
*/
|
||||
public function add($item, $type = '')
|
||||
{
|
||||
$item['children'] = [];
|
||||
|
||||
if ($type == 'menu') {
|
||||
$item['url'] = route($item['route']);
|
||||
$item['url'] = route($item['route']);
|
||||
|
||||
if (strpos($this->current, $item['url']) !== false) {
|
||||
$this->currentKey = $item['key'];
|
||||
$this->currentKey = $item['key'];
|
||||
}
|
||||
} else if ($type == 'acl') {
|
||||
$item['name'] = trans($item['name']);
|
||||
|
|
|
|||
|
|
@ -0,0 +1,32 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class AddCodeColumnInCustomerGroupsTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('customer_groups', function (Blueprint $table) {
|
||||
$table->string('code');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('customer_groups', function (Blueprint $table) {
|
||||
//
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
@ -12,17 +12,22 @@ class CustomerGroupTableSeeder extends Seeder
|
|||
DB::table('customer_groups')->delete();
|
||||
|
||||
DB::table('customer_groups')->insert([
|
||||
'id' => 0,
|
||||
'name' => 'Guest',
|
||||
'is_user_defined' => 0,
|
||||
], [
|
||||
'id' => 1,
|
||||
'name' => 'General',
|
||||
'is_user_defined' => 0,
|
||||
], [
|
||||
'id' => 2,
|
||||
'name' => 'Wholesale',
|
||||
'is_user_defined' => 0,
|
||||
[
|
||||
'id' => 1,
|
||||
'code' => 'guest',
|
||||
'name' => 'Guest',
|
||||
'is_user_defined' => 0,
|
||||
], [
|
||||
'id' => 2,
|
||||
'code' => 'general',
|
||||
'name' => 'General',
|
||||
'is_user_defined' => 0,
|
||||
], [
|
||||
'id' => 3,
|
||||
'code' => 'wholesale',
|
||||
'name' => 'Wholesale',
|
||||
'is_user_defined' => 0,
|
||||
]
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
|
@ -17,7 +17,6 @@ use Auth;
|
|||
* @author Prashant Singh <prashant.singh852@webkul.com>
|
||||
* @copyright 2018 Webkul Software Pvt Ltd (http://www.webkul.com)
|
||||
*/
|
||||
|
||||
class AccountController extends Controller
|
||||
{
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -75,7 +75,7 @@ class RegistrationController extends Controller
|
|||
$data['is_verified'] = 1;
|
||||
}
|
||||
|
||||
$data['customer_group_id'] = $this->customerGroup->findOneWhere(['name' => 'General'])->id;
|
||||
$data['customer_group_id'] = $this->customerGroup->findOneWhere(['code' => 'general'])->id;
|
||||
|
||||
$verificationData['email'] = $data['email'];
|
||||
$verificationData['token'] = md5(uniqid(rand(), true));
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ class CustomerGroup extends Model implements CustomerGroupContract
|
|||
{
|
||||
protected $table = 'customer_groups';
|
||||
|
||||
protected $fillable = ['name', 'is_user_defined'];
|
||||
protected $fillable = ['name', 'code', 'is_user_defined'];
|
||||
|
||||
/**
|
||||
* Get the customer for this group.
|
||||
|
|
|
|||
|
|
@ -0,0 +1,8 @@
|
|||
<?php
|
||||
|
||||
namespace Webkul\Discount\Actions;
|
||||
|
||||
abstract class Action
|
||||
{
|
||||
abstract public function calculate($rule, $item, $cart);
|
||||
}
|
||||
|
|
@ -0,0 +1,38 @@
|
|||
<?php
|
||||
|
||||
namespace Webkul\Discount\Actions;
|
||||
|
||||
use Webkul\Discount\Actions\Action;
|
||||
|
||||
class BuyAGetB extends Action
|
||||
{
|
||||
public function calculate($rule, $item, $cart)
|
||||
{
|
||||
//calculate discount amount
|
||||
$action_type = $rule->action_type; // action type used
|
||||
$disc_threshold = $rule->disc_threshold; // atleast quantity by default 1
|
||||
$disc_amount = $rule->disc_amount; // value of discount
|
||||
$disc_quantity = $rule->disc_quantity; //max quantity allowed to be discounted
|
||||
|
||||
$amountDiscounted = 0;
|
||||
|
||||
$realQty = $item['quantity'];
|
||||
|
||||
if ($cart->items_qty >= $disc_threshold) {
|
||||
$amountDiscounted = $disc_amount;
|
||||
|
||||
if ($realQty > $disc_quantity) {
|
||||
$amountDiscounted = $amountDiscounted * $disc_quantity;
|
||||
}
|
||||
|
||||
if ($amountDiscounted > $item['price']) {
|
||||
$amountDiscounted = $item['price'];
|
||||
}
|
||||
}
|
||||
|
||||
$report['discount'] = $amountDiscounted;
|
||||
$report['formatted_discount'] = core()->formatPrice($amountDiscounted, $cart->cart_currency_code);
|
||||
|
||||
return $report;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,38 @@
|
|||
<?php
|
||||
|
||||
namespace Webkul\Discount\Actions;
|
||||
|
||||
use Webkul\Discount\Actions\Action;
|
||||
|
||||
class FixedAmount extends Action
|
||||
{
|
||||
public function calculate($rule, $item, $cart)
|
||||
{
|
||||
//calculate discount amount
|
||||
$action_type = $rule->action_type; // action type used
|
||||
$disc_threshold = $rule->disc_threshold; // atleast quantity by default 1 --> may be omitted in near future
|
||||
$disc_amount = $rule->disc_amount; // value of discount
|
||||
$disc_quantity = $rule->disc_quantity; //max quantity allowed to be discounted
|
||||
|
||||
$amountDiscounted = 0;
|
||||
|
||||
$realQty = $item['quantity'];
|
||||
|
||||
if ($cart >= $disc_threshold) {
|
||||
$amountDiscounted = $disc_amount;
|
||||
|
||||
if ($realQty > $disc_quantity) {
|
||||
$amountDiscounted = $amountDiscounted * $disc_quantity;
|
||||
}
|
||||
|
||||
if ($amountDiscounted > $item['price']) {
|
||||
$amountDiscounted = $item['price'];
|
||||
}
|
||||
}
|
||||
|
||||
$report['discount'] = $amountDiscounted;
|
||||
$report['formatted_discount'] = core()->formatPrice($amountDiscounted, $cart->cart_currency_code);
|
||||
|
||||
return $report;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,35 @@
|
|||
<?php
|
||||
|
||||
namespace Webkul\Discount\Actions;
|
||||
|
||||
use Webkul\Discount\Actions\Action;
|
||||
|
||||
class PercentOfProduct extends Action
|
||||
{
|
||||
public function calculate($rule, $item, $cart)
|
||||
{
|
||||
$amountDiscounted = 0;
|
||||
$disc_threshold = $rule->disc_threshold;
|
||||
$disc_amount = $rule->disc_amount;
|
||||
$disc_quantity = $rule->disc_quantity;
|
||||
|
||||
$realQty = $item['quantity'];
|
||||
|
||||
if ($cart >= $disc_threshold) {
|
||||
$amountDiscounted = $item['price'] * ($disc_amount / 100);
|
||||
|
||||
if ($realQty > $disc_quantity) {
|
||||
$amountDiscounted = $amountDiscounted * $disc_quantity;
|
||||
}
|
||||
|
||||
if ($amountDiscounted > $item['price']) {
|
||||
$amountDiscounted = $item['price'];
|
||||
}
|
||||
}
|
||||
|
||||
$report['discount'] = $amountDiscounted;
|
||||
$report['formatted_discount'] = core()->formatPrice($amountDiscounted, $cart->cart_currency_code);
|
||||
|
||||
return $report;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
<?php
|
||||
|
||||
return [
|
||||
'percent_of_product' => 'Webkul\Discount\Actions\PercentOfProduct',
|
||||
'fixed_amount' => 'Webkul\Discount\Actions\FixedAmount',
|
||||
'buy_a_get_b' => 'Webkul\Discount\Actions\BuyAGetB'
|
||||
];
|
||||
|
|
@ -1,6 +1,13 @@
|
|||
<?php
|
||||
|
||||
return [
|
||||
'test_mode' => [
|
||||
'all_are_true' => 'All conditions are true',
|
||||
// 'all_are_false' => 'All conditions are false',
|
||||
'any_is_true' => 'Any condition is true',
|
||||
// 'any_is_false' => 'Any condition is false'
|
||||
],
|
||||
|
||||
'conditions' => [
|
||||
'numeric' => [
|
||||
0 => 'Equals',
|
||||
|
|
@ -23,59 +30,19 @@ return [
|
|||
]
|
||||
],
|
||||
|
||||
'catalog' => [
|
||||
'actions' => [
|
||||
0 => 'admin::app.promotion.catalog.apply-percent',
|
||||
1 => 'admin::app.promotion.catalog.apply-fixed',
|
||||
2 => 'admin::app.promotion.catalog.adjust-to-percent',
|
||||
// 3 => 'admin::app.promotion.catalog.adjust-to-value'
|
||||
],
|
||||
|
||||
'attributes' => [
|
||||
0 => [
|
||||
'name' => 'Sub-total',
|
||||
'type' => 'numeric'
|
||||
],
|
||||
1 => [
|
||||
'name' => 'Total Items Quantity',
|
||||
'type' => 'numeric'
|
||||
],
|
||||
2 => [
|
||||
'name' => 'Total Weight',
|
||||
'type' => 'numeric'
|
||||
],
|
||||
3 => [
|
||||
'name' => 'Payment Method',
|
||||
'type' => 'string'
|
||||
],
|
||||
4 => [
|
||||
'name' => 'Shipping Postcode',
|
||||
'type' => 'string'
|
||||
],
|
||||
5 => [
|
||||
'name' => 'Shipping State',
|
||||
'type' => 'string'
|
||||
],
|
||||
6 => [
|
||||
'name' => 'Shipping Country',
|
||||
'type' => 'string'
|
||||
]
|
||||
]
|
||||
],
|
||||
|
||||
'cart' => [
|
||||
'actions' => [
|
||||
'percent_of_product' => 'Percentage of product',
|
||||
'fixed_amount' => 'Apply as fixed amount',
|
||||
'buy_a_get_b' => 'Get B amount back',
|
||||
// 'fixed_amount_cart' => 'Fixed amount for whole cart'
|
||||
'fixed_amount_cart' => 'Whole cart gets discounted'
|
||||
],
|
||||
|
||||
'validation' => [
|
||||
0 => 'percent_of_product',
|
||||
1 => 'fixed_amount',
|
||||
2 => 'buy_a_get_b',
|
||||
3 => 'fixed_amount_cart'
|
||||
// 3 => 'fixed_amount_cart'
|
||||
],
|
||||
|
||||
'conditions' => [
|
||||
|
|
@ -87,22 +54,12 @@ return [
|
|||
'<' => 'Lesser than',
|
||||
],
|
||||
|
||||
'text' => [
|
||||
'=' => 'Equals',
|
||||
'>=' => 'Greater or equals',
|
||||
'<=' => 'Lesser or equals',
|
||||
'>' => 'Greater than',
|
||||
'<' => 'Lesser than',
|
||||
'{}' => 'Contains',
|
||||
'!{}' => 'Does not contains'
|
||||
],
|
||||
|
||||
'string' => [
|
||||
'=' => 'Equals',
|
||||
'>=' => 'Greater or equals',
|
||||
'<=' => 'Lesser or equals',
|
||||
'>' => 'Greater than',
|
||||
'<' => 'Lesser than',
|
||||
// '>=' => 'Greater or equals',
|
||||
// '<=' => 'Lesser or equals',
|
||||
// '>' => 'Greater than',
|
||||
// '<' => 'Lesser than',
|
||||
'{}' => 'Contains',
|
||||
'!{}' => 'Does not contains'
|
||||
],
|
||||
|
|
@ -162,10 +119,43 @@ return [
|
|||
]
|
||||
],
|
||||
|
||||
'test_mode' => [
|
||||
'all_are_true' => 'All conditions are true',
|
||||
'all_are_false' => 'All conditions are false',
|
||||
'any_is_true' => 'Any condition is true',
|
||||
'any_is_false' => 'Any condition is false'
|
||||
]
|
||||
'catalog' => [
|
||||
'actions' => [
|
||||
0 => 'admin::app.promotion.catalog.apply-percent',
|
||||
1 => 'admin::app.promotion.catalog.apply-fixed',
|
||||
2 => 'admin::app.promotion.catalog.adjust-to-percent',
|
||||
// 3 => 'admin::app.promotion.catalog.adjust-to-value'
|
||||
],
|
||||
|
||||
'attributes' => [
|
||||
0 => [
|
||||
'name' => 'Sub-total',
|
||||
'type' => 'numeric'
|
||||
],
|
||||
1 => [
|
||||
'name' => 'Total Items Quantity',
|
||||
'type' => 'numeric'
|
||||
],
|
||||
2 => [
|
||||
'name' => 'Total Weight',
|
||||
'type' => 'numeric'
|
||||
],
|
||||
3 => [
|
||||
'name' => 'Payment Method',
|
||||
'type' => 'string'
|
||||
],
|
||||
4 => [
|
||||
'name' => 'Shipping Postcode',
|
||||
'type' => 'string'
|
||||
],
|
||||
5 => [
|
||||
'name' => 'Shipping State',
|
||||
'type' => 'string'
|
||||
],
|
||||
6 => [
|
||||
'name' => 'Shipping Country',
|
||||
'type' => 'string'
|
||||
]
|
||||
]
|
||||
],
|
||||
];
|
||||
|
|
@ -39,8 +39,8 @@ class CreateCartRuleTable extends Migration
|
|||
$table->integer('sort_order')->unsigned()->default(0);
|
||||
$table->string('action_type')->nullable();
|
||||
$table->decimal('disc_amount', 12, 4)->default(0);
|
||||
$table->decimal('disc_quantity', 12, 4)->default(0);
|
||||
$table->string('disc_threshold')->default(0);
|
||||
$table->decimal('disc_quantity', 12, 4)->default(1);
|
||||
$table->string('disc_threshold')->default(1);
|
||||
$table->integer('coupon_type')->default(1);
|
||||
$table->boolean('auto_generation')->default(0);
|
||||
$table->boolean('apply_to_shipping')->default(0);
|
||||
|
|
|
|||
|
|
@ -0,0 +1,156 @@
|
|||
<?php
|
||||
|
||||
namespace Webkul\Discount\Helpers;
|
||||
|
||||
use Webkul\Discount\Helpers\Discount;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Cart;
|
||||
|
||||
class CouponAbleRule extends Discount
|
||||
{
|
||||
/**
|
||||
* Applies the couponable rule on the current cart instance
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function apply($code)
|
||||
{
|
||||
$cart = Cart::getCart();
|
||||
|
||||
if (auth()->guard('customer')->check()) {
|
||||
$rules = $this->cartRule->findWhere([
|
||||
'use_coupon' => 1,
|
||||
'status' => 1
|
||||
]);
|
||||
} else {
|
||||
$rules = $this->cartRule->findWhere([
|
||||
'use_coupon' => 1,
|
||||
'is_guest' => 1,
|
||||
'status' => 1
|
||||
]);
|
||||
}
|
||||
|
||||
$applicableRule = null;
|
||||
|
||||
foreach($rules as $rule) {
|
||||
if ($rule->use_coupon && ($rule->coupons->code == $code)) {
|
||||
$applicableRule = $rule;
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$applicability = $this->checkApplicability($applicableRule);
|
||||
|
||||
if ($applicability) {
|
||||
$item = $this->leastWorthItem();
|
||||
|
||||
$actionInstance = new $this->rules[$applicableRule->action_type];
|
||||
|
||||
$impact = $actionInstance->calculate($applicableRule, $item, $cart);
|
||||
|
||||
$ifAlreadyApplied = $this->cartRuleCart->findWhere([
|
||||
'cart_id' => $cart->id,
|
||||
'cart_rule_id' => $applicableRule->id
|
||||
]);
|
||||
|
||||
if ($ifAlreadyApplied->count() == 1) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$ifAlreadyApplied = $this->cartRuleCart->findWhere([
|
||||
'cart_id' => $cart->id,
|
||||
]);
|
||||
|
||||
if ($ifAlreadyApplied->count() == 0) {
|
||||
$this->save($applicableRule);
|
||||
|
||||
return $impact;
|
||||
}
|
||||
|
||||
$alreadyAppliedRule = $ifAlreadyApplied->first()->cart_rule;
|
||||
|
||||
if ($alreadyAppliedRule->priority < $rule->priority) {
|
||||
return false;
|
||||
} else if ($alreadyAppliedRule->priority == $applicableRule->priority) {
|
||||
// tie breaker case
|
||||
|
||||
// end other rules
|
||||
if ($alreadyAppliedRule->end_other_rules) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$actionInstance = new $this->rules[$alreadyAppliedRule->action_type];
|
||||
|
||||
$alreadyAppliedRuleImpact = $actionInstance->calculate($alreadyAppliedRule, $item, $cart);
|
||||
|
||||
if ($alreadyAppliedRule['discount'] > $impact['discount']) {
|
||||
return false;
|
||||
} else if ($alreadyAppliedRule['discount'] < $impact['discount']) {
|
||||
$this->save($applicableRule);
|
||||
|
||||
return $impact;
|
||||
} else {
|
||||
// least id case
|
||||
if ($applicableRule->id < $alreadyAppliedRule->id) {
|
||||
$this->save($applicableRule);
|
||||
|
||||
return $impact;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$this->save($applicableRule);
|
||||
|
||||
return $impact;
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the already applied coupon on the current cart instance
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function remove()
|
||||
{
|
||||
$cart = Cart::getCart();
|
||||
|
||||
$existingRule = $this->cartRuleCart->findWhere([
|
||||
'cart_id' => $cart->id
|
||||
]);
|
||||
|
||||
if ($existingRule->count()) {
|
||||
if ($existingRule->first()->cart_rule->use_coupon) {
|
||||
$existingRule->first()->delete();
|
||||
|
||||
foreach ($cart->items as $item) {
|
||||
if ($item->discount_amount > 0) {
|
||||
$item->update([
|
||||
'discount_amount' => 0,
|
||||
'base_discount_amount' => 0,
|
||||
'discount_percent' => 0,
|
||||
'coupon_code' => NULL
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
$cart->update([
|
||||
'coupon_code' => NULL,
|
||||
'discount_amount' => 0,
|
||||
'base_discount_amount' => 0
|
||||
]);
|
||||
|
||||
Cart::collectTotals();
|
||||
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -5,9 +5,9 @@ namespace Webkul\Discount\Helpers;
|
|||
use Webkul\Discount\Repositories\CartRuleRepository as CartRule;
|
||||
use Webkul\Discount\Repositories\CartRuleCartRepository as CartRuleCart;
|
||||
use Carbon\Carbon;
|
||||
use Arr;
|
||||
use Cart;
|
||||
|
||||
class Discount
|
||||
abstract class Discount
|
||||
{
|
||||
/**
|
||||
* To hold the cart rule repository instance
|
||||
|
|
@ -24,6 +24,11 @@ class Discount
|
|||
*/
|
||||
protected $endRuleActive = false;
|
||||
|
||||
/**
|
||||
* To hold the rule classes
|
||||
*/
|
||||
protected $rules;
|
||||
|
||||
/**
|
||||
* disable coupon
|
||||
*/
|
||||
|
|
@ -32,364 +37,95 @@ class Discount
|
|||
public function __construct(CartRule $cartRule, CartRuleCart $cartRuleCart)
|
||||
{
|
||||
$this->cartRule = $cartRule;
|
||||
$this->endRuleActive = false;
|
||||
|
||||
$this->cartRuleCart = $cartRuleCart;
|
||||
}
|
||||
|
||||
public function applyNonCouponAbleRule()
|
||||
{
|
||||
$cart = \Cart::getCart();
|
||||
|
||||
$previousRule = $this->cartRuleCart->findWhere([
|
||||
'cart_id' => $cart->id
|
||||
]);
|
||||
|
||||
if ($previousRule->count()) {
|
||||
$previousRule = $previousRule->first()->cart_rule;
|
||||
|
||||
if ($previousRule->use_coupon) {
|
||||
|
||||
return 'false';
|
||||
}
|
||||
} else {
|
||||
\Cart::clearDiscount();
|
||||
}
|
||||
|
||||
if (auth()->guard('customer')->check()) {
|
||||
$nonCouponAbleRules = $this->cartRule->findWhere([
|
||||
'use_coupon' => 0,
|
||||
'status' => 1
|
||||
]);
|
||||
} else {
|
||||
$nonCouponAbleRules = $this->cartRule->findWhere([
|
||||
'use_coupon' => 0,
|
||||
'is_guest' => 1,
|
||||
'status' => 1
|
||||
]);
|
||||
}
|
||||
|
||||
$canBeApplied = array();
|
||||
|
||||
// time based filter
|
||||
foreach($nonCouponAbleRules as $rule) {
|
||||
$report = $this->checkApplicability($rule);
|
||||
$report['rule'] = $rule;
|
||||
|
||||
$passed = 0;
|
||||
if ($rule->starts_from != null && $rule->ends_till == null) {
|
||||
if (Carbon::parse($rule->starts_from) < now()) {
|
||||
$passed = 1;
|
||||
}
|
||||
} else if ($rule->starts_from == null && $rule->ends_till != null) {
|
||||
if (Carbon::parse($rule->ends_till) > now()) {
|
||||
$passed = 1;
|
||||
}
|
||||
} else if ($rule->starts_from != null && $rule->ends_till != null) {
|
||||
if (Carbon::parse($rule->starts_from) < now() && now() < Carbon::parse($rule->ends_till)) {
|
||||
$passed = 1;
|
||||
}
|
||||
} else {
|
||||
$passed = 1;
|
||||
}
|
||||
|
||||
if ($passed) {
|
||||
$report['used_coupon'] = false;
|
||||
array_push($canBeApplied, $report);
|
||||
}
|
||||
}
|
||||
|
||||
//min priority
|
||||
$minPriority = collect($canBeApplied)->min('priority');
|
||||
|
||||
$canBeApplied = collect($canBeApplied)->where('priority', $minPriority);
|
||||
|
||||
if (count($canBeApplied) > 1) {
|
||||
$maxDiscount = collect($canBeApplied)->max('discount');
|
||||
|
||||
$canBeApplied = collect($canBeApplied)->where('discount', $maxDiscount);
|
||||
|
||||
$leastId = 999999999999;
|
||||
if (count($canBeApplied) > 1) {
|
||||
foreach($canBeApplied as $rule) {
|
||||
if ($rule['rule']->id < $leastId) {
|
||||
$leastId = $rule['rule']->id;
|
||||
}
|
||||
}
|
||||
|
||||
// fighting the edge case for non couponable discount rule
|
||||
foreach($canBeApplied as $rule) {
|
||||
if ($rule['rule']->id == $leastId) {
|
||||
$rule['used_coupon'] = false;
|
||||
|
||||
foreach (\Cart::getCart()->items as $item) {
|
||||
if ($item->id == $itemId['item_id']) {
|
||||
$item->update([
|
||||
'discount_amount' => array_first($canBeApplied)['discount'],
|
||||
'base_discount_amount' => array_first($canBeApplied)['discount']
|
||||
]);
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$this->save($rule['rule']);
|
||||
|
||||
return $rule;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($canBeApplied->count()) {
|
||||
$itemId = array_first($canBeApplied);
|
||||
|
||||
foreach (\Cart::getCart()->items as $item) {
|
||||
if ($item->id == $itemId['item_id']) {
|
||||
$item->update([
|
||||
'discount_amount' => array_first($canBeApplied)['discount'],
|
||||
'base_discount_amount' => array_first($canBeApplied)['discount']
|
||||
]);
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$this->save(array_first($canBeApplied)['rule']);
|
||||
|
||||
return array_first($canBeApplied);
|
||||
} else {
|
||||
return 'false';
|
||||
}
|
||||
}
|
||||
|
||||
public function applyCouponAbleRule($code)
|
||||
{
|
||||
$cart = \Cart::getCart();
|
||||
|
||||
if (auth()->guard('customer')->check()) {
|
||||
$couponAbleRules = $this->cartRule->findWhere([
|
||||
'use_coupon' => 1,
|
||||
'status' => 1
|
||||
]);
|
||||
} else {
|
||||
$couponAbleRules = $this->cartRule->findWhere([
|
||||
'use_coupon' => 1,
|
||||
'is_guest' => 1,
|
||||
'status' => 1
|
||||
]);
|
||||
}
|
||||
|
||||
foreach ($couponAbleRules as $couponAbleRule) {
|
||||
if ($couponAbleRule->coupons->code == $code) {
|
||||
$rule = $couponAbleRule;
|
||||
}
|
||||
}
|
||||
|
||||
$useCouponable = false;
|
||||
if (isset($rule)) {
|
||||
$canBeApplied = array();
|
||||
|
||||
// time based filter
|
||||
$report = $this->checkApplicability($rule);
|
||||
$report['rule'] = $rule;
|
||||
|
||||
$passed = 0;
|
||||
if ($rule->starts_from != null && $rule->ends_till == null) {
|
||||
if (Carbon::parse($rule->starts_from) < now()) {
|
||||
$passed = 1;
|
||||
}
|
||||
} else if ($rule->starts_from == null && $rule->ends_till != null) {
|
||||
if (Carbon::parse($rule->ends_till) > now()) {
|
||||
$passed = 1;
|
||||
}
|
||||
} else if ($rule->starts_from != null && $rule->ends_till != null) {
|
||||
if (Carbon::parse($rule->starts_from) < now() && now() < Carbon::parse($rule->ends_till)) {
|
||||
$passed = 1;
|
||||
}
|
||||
} else {
|
||||
$passed = 1;
|
||||
}
|
||||
|
||||
if ($passed) {
|
||||
array_push($canBeApplied, $report);
|
||||
|
||||
$useCouponable = true;
|
||||
$alreadyAppliedRule = $this->cartRuleCart->findWhere([
|
||||
'cart_id' => \Cart::getCart()->id
|
||||
]);
|
||||
|
||||
if ($alreadyAppliedRule->count() && ! ($alreadyAppliedRule->first()->cart_rule->priority < $canBeApplied[0]['rule']->priority)) {
|
||||
unset($report);
|
||||
|
||||
$alreadyAppliedRule = $alreadyAppliedRule->first()->cart_rule;
|
||||
|
||||
// analyze impact
|
||||
if ($alreadyAppliedRule->id != $rule->id) {
|
||||
$report = $this->checkApplicability($alreadyAppliedRule);
|
||||
$report['rule'] = $alreadyAppliedRule;
|
||||
|
||||
array_push($canBeApplied, $report);
|
||||
|
||||
//min priority
|
||||
$minPriority = collect($canBeApplied)->min('priority');
|
||||
//min priority rule
|
||||
$canBeApplied = collect($canBeApplied)->where('priority', $minPriority);
|
||||
|
||||
if (count($canBeApplied) > 1) {
|
||||
$maxDiscount = collect($canBeApplied)->max('discount');
|
||||
|
||||
$canBeApplied = collect($canBeApplied)->where('discount', $maxDiscount);
|
||||
|
||||
$leastId = 999999999999;
|
||||
if (count($canBeApplied) > 1) {
|
||||
foreach($canBeApplied as $rule) {
|
||||
if ($rule['rule']->id < $leastId) {
|
||||
$leastId = $rule['rule']->id;
|
||||
}
|
||||
}
|
||||
|
||||
// fighting the edge case for couponable discount rule
|
||||
foreach($canBeApplied as $rule) {
|
||||
if ($rule['rule']->id == $leastId) {
|
||||
if($rule['rule']->use_coupon) {
|
||||
$useCouponable = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (array_first($canBeApplied)['rule']->use_coupon) {
|
||||
$useCouponable = true;
|
||||
}
|
||||
}
|
||||
} else if (count($canBeApplied)) {
|
||||
if (array_first($canBeApplied)['rule']->use_coupon) {
|
||||
$useCouponable = true;
|
||||
}
|
||||
}
|
||||
|
||||
if ($alreadyAppliedRule->end_other_rules) {
|
||||
$useCouponable = false;
|
||||
}
|
||||
} else {
|
||||
$report = $this->checkApplicability($rule);
|
||||
|
||||
array_push($canBeApplied, $report);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($useCouponable) {
|
||||
$report = $this->checkApplicability($rule);
|
||||
$report['rule'] = $rule;
|
||||
$report['used_coupon'] = $useCouponable;
|
||||
|
||||
$itemId = array_first($canBeApplied);
|
||||
|
||||
foreach ($cart->items as $item) {
|
||||
if ($item->id == $itemId['item_id']) {
|
||||
$item->update([
|
||||
'discount_amount' => array_first($canBeApplied)['discount'],
|
||||
'base_discount_amount' => array_first($canBeApplied)['discount'],
|
||||
'coupon_code' => $rule->coupons->code
|
||||
]);
|
||||
|
||||
$cart->update([
|
||||
'coupon_code' => $rule->coupons->code
|
||||
]);
|
||||
|
||||
\Cart::collectTotals();
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// saves the rule in cart rule cart
|
||||
$this->save($rule);
|
||||
|
||||
return $report;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
$this->rules = config('discount-rules');
|
||||
}
|
||||
|
||||
/**
|
||||
* This function checks whether the rule is getting applied on the current cart or noy
|
||||
*
|
||||
* @return mixed
|
||||
* Abstract method apply
|
||||
*/
|
||||
public function checkApplicability($rule = null)
|
||||
abstract public function apply($code);
|
||||
|
||||
/**
|
||||
* Checks whether coupon is getting applied on current cart instance or not
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function checkApplicability($rule)
|
||||
{
|
||||
$cart = \Cart::getCart();
|
||||
$report = array();
|
||||
$result = 0;
|
||||
|
||||
$timeBased = false;
|
||||
|
||||
// time based constraints
|
||||
if ($rule->starts_from != null && $rule->ends_till == null) {
|
||||
if (Carbon::parse($rule->starts_from) < now()) {
|
||||
$timeBased = true;
|
||||
}
|
||||
} else if ($rule->starts_from == null && $rule->ends_till != null) {
|
||||
if (Carbon::parse($rule->ends_till) > now()) {
|
||||
$timeBased = true;
|
||||
}
|
||||
} else if ($rule->starts_from != null && $rule->ends_till != null) {
|
||||
if (Carbon::parse($rule->starts_from) < now() && now() < Carbon::parse($rule->ends_till)) {
|
||||
$timeBased = true;
|
||||
}
|
||||
} else {
|
||||
$timeBased = true;
|
||||
}
|
||||
|
||||
$channelBased = false;
|
||||
|
||||
// channel based constraints
|
||||
foreach ($rule->channels as $channel) {
|
||||
if ($channel->channel_id == core()->getCurrentChannel()->id) {
|
||||
$channelBased = true;
|
||||
}
|
||||
}
|
||||
|
||||
$customerGroupBased = false;
|
||||
|
||||
// customer groups based constraints
|
||||
if (auth()->guard('customer')->check()) {
|
||||
foreach ($rule->customer_groups as $customer_group) {
|
||||
if ($customer_group->customer_group_id == auth()->guard('customer')->user()->group->id) {
|
||||
$customerGroupBased = true;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if ($rule->is_guest) {
|
||||
$customerGroupBased = true;
|
||||
}
|
||||
}
|
||||
|
||||
$conditionsBased = true;
|
||||
|
||||
//check conditions
|
||||
if ($rule->conditions != null) {
|
||||
$conditions = json_decode(json_decode($rule->conditions));
|
||||
$test_mode = config('pricerules.test_mode.0');
|
||||
|
||||
if ($test_mode == config('pricerules.test_mode.0')) {
|
||||
$result = $this->testIfAllConditionAreTrue($conditions, $cart);
|
||||
} else if ($test_mode == config('pricerules.test_mode.1')) {
|
||||
$result = $this->testIfAllConditionAreFalse($conditions, $cart);
|
||||
} else if ($test_mode == config('pricerules.test_mode.2')) {
|
||||
$result = $this->testIfAnyConditionIsTrue($conditions, $cart);
|
||||
} else if ($test_mode == config('pricerules.test_mode.3')) {
|
||||
$result = $this->testIfAnyConditionIsFalse($conditions, $cart);
|
||||
$test_mode = array_last($conditions);
|
||||
|
||||
if ($test_mode->criteria == 'any_is_true') {
|
||||
$conditionsBased = $this->testIfAnyConditionIsTrue($conditions, $cart);
|
||||
}
|
||||
|
||||
if ($test_mode->criteria == 'all_are_true') {
|
||||
$conditionsBased = $this->testIfAllConditionAreTrue($conditions, $cart);
|
||||
}
|
||||
}
|
||||
|
||||
if ($result) {
|
||||
$report['conditions'] = true;
|
||||
if ($timeBased && $channelBased && $customerGroupBased && $conditionsBased) {
|
||||
return true;
|
||||
} else {
|
||||
if ($rule->conditions == null)
|
||||
$report['conditions'] = true;
|
||||
else
|
||||
$report['conditions'] = false;
|
||||
return false;
|
||||
}
|
||||
|
||||
//check endrule
|
||||
if ($rule->end_other_rules) {
|
||||
$report['end_other_rules'] = true;
|
||||
} else {
|
||||
$report['end_other_rules'] = false;
|
||||
}
|
||||
|
||||
//calculate discount amount
|
||||
$action_type = $rule->action_type; // action type used
|
||||
$disc_threshold = $rule->disc_threshold; // atleast quantity by default 1 --> may be omitted in near future
|
||||
$disc_amount = $rule->disc_amount; // value of discount
|
||||
$disc_quantity = $rule->disc_quantity; //max quantity allowed to be discounted
|
||||
|
||||
$amountDiscounted = 0;
|
||||
$leastWorthItem = \Cart::leastWorthItem();
|
||||
$realQty = $leastWorthItem['quantity'];
|
||||
|
||||
if ($cart->items_qty >= $disc_threshold && $realQty >= $disc_quantity) {
|
||||
if ($action_type == config('pricerules.cart.validation.0')) {
|
||||
$amountDiscounted = $leastWorthItem['total'] * ($disc_amount / 100);
|
||||
} else if ($action_type == config('pricerules.cart.validation.1')) {
|
||||
$amountDiscounted = $disc_amount;
|
||||
} else if ($action_type == config('pricerules.cart.validation.2')) {
|
||||
$amountDiscounted = $disc_amount;
|
||||
}
|
||||
}
|
||||
|
||||
$report['item_id'] = $leastWorthItem['id'];
|
||||
$report['item_price'] = $leastWorthItem['total'];
|
||||
$report['discount'] = $amountDiscounted;
|
||||
$report['action'] = $action_type;
|
||||
$report['formatted_discount'] = core()->formatPrice($amountDiscounted, $cart->cart_currency_code);
|
||||
$report['new_grand_total'] = $cart->grand_total - $amountDiscounted;
|
||||
$report['formatted_new_grand_total'] = core()->formatPrice($cart->grand_total - $amountDiscounted, $cart->cart_currency_code);
|
||||
$report['priority'] = $rule->priority;
|
||||
|
||||
return $report;
|
||||
}
|
||||
|
||||
/**
|
||||
* Save the rule in the cart rule cart
|
||||
* Save the rule in the CartRule for current cart instance
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
|
|
@ -403,19 +139,27 @@ class Discount
|
|||
]);
|
||||
|
||||
if (count($existingRule)) {
|
||||
// $this->clearDiscount();
|
||||
|
||||
if ($existingRule->first()->cart_rule_id != $rule->id) {
|
||||
$existingRule->first()->update([
|
||||
'cart_rule_id' => $rule->id
|
||||
]);
|
||||
|
||||
$this->updateCartItemAndCart($rule);
|
||||
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
// $this->clearDiscount();
|
||||
|
||||
$this->cartRuleCart->create([
|
||||
'cart_id' => $cart->id,
|
||||
'cart_rule_id' => $rule->id
|
||||
]);
|
||||
|
||||
$this->updateCartItemAndCart($rule);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -423,45 +167,148 @@ class Discount
|
|||
}
|
||||
|
||||
/**
|
||||
* Removes the cart rule from the cart
|
||||
* Removes any cart rule from the current cart instance
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function removeRule()
|
||||
public function clearDiscount()
|
||||
{
|
||||
$cart = Cart::getCart();
|
||||
|
||||
$appliedRule = $this->cartRuleCart->findWhere([
|
||||
'cart_id' => $cart->id
|
||||
]);
|
||||
$cartItems = $cart->items;
|
||||
|
||||
if ($appliedRule->count() == 0) {
|
||||
Cart::clearDiscount();
|
||||
|
||||
Cart::collectTotals();
|
||||
foreach($cartItems as $item) {
|
||||
$item->update([
|
||||
'coupon_code' => NULL,
|
||||
'discount_percent' => 0,
|
||||
'discount_amount' => 0,
|
||||
'base_discount_amount' => 0
|
||||
]);
|
||||
}
|
||||
|
||||
$cart->update([
|
||||
'coupon_code' => NULL,
|
||||
'discount_amount' => 0,
|
||||
'base_discount_amount' => 0
|
||||
]);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function removeCoupon()
|
||||
/**
|
||||
* To find the least worth item in current cart instance
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function leastWorthItem()
|
||||
{
|
||||
$cart = \Cart::getCart();
|
||||
$cart = Cart::getCart();
|
||||
|
||||
$existingRule = $this->cartRuleCart->findWhere([
|
||||
'cart_id' => $cart->id
|
||||
]);
|
||||
$leastValue = 999999999999;
|
||||
$leastWorthItem = [];
|
||||
|
||||
if ($existingRule->count()) {
|
||||
if ($existingRule->first()->delete()) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
foreach ($cart->items as $item) {
|
||||
if ($item->price < $leastValue) {
|
||||
$leastValue = $item->price;
|
||||
$leastWorthItem = [
|
||||
'id' => $item->id,
|
||||
'price' => $item->price,
|
||||
'base_price' => $item->base_price,
|
||||
'quantity' => $item->quantity
|
||||
];
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $leastWorthItem;
|
||||
}
|
||||
|
||||
protected function testIfAllConditionAreTrue($conditions, $cart) {
|
||||
/**
|
||||
* Update discount for least worth item
|
||||
*/
|
||||
public function updateCartItemAndCart($rule)
|
||||
{
|
||||
$cart = Cart::getCart();
|
||||
|
||||
$leastWorthItem = $this->leastWorthItem();
|
||||
|
||||
$actionInstance = new $this->rules[$rule->action_type];
|
||||
|
||||
$impact = $actionInstance->calculate($rule, $leastWorthItem, $cart);
|
||||
|
||||
foreach ($cart->items as $item) {
|
||||
if ($item->id == $leastWorthItem['id']) {
|
||||
if ($rule->action_type == 'percent_of_product') {
|
||||
$item->update([
|
||||
'discount_percent' => $rule->discount_amount,
|
||||
'discount_amount' => $impact['discount'],
|
||||
'base_discount_amount' => $impact['discount']
|
||||
]);
|
||||
} else {
|
||||
$item->update([
|
||||
'discount_amount' => $impact['discount'],
|
||||
'base_discount_amount' => $impact['discount']
|
||||
]);
|
||||
}
|
||||
|
||||
// save coupon if rule has it
|
||||
if ($rule->use_coupon) {
|
||||
$coupon = $rule->coupons->code;
|
||||
|
||||
$item->update([
|
||||
'coupon_code' => $coupon
|
||||
]);
|
||||
|
||||
$cart->update([
|
||||
'coupon_code' => $coupon
|
||||
]);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Cart::collectTotals();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* To find the max worth item in current cart instance
|
||||
*
|
||||
* @return Array
|
||||
*/
|
||||
public function maxWorthItem()
|
||||
{
|
||||
$cart = Cart::getCart();
|
||||
|
||||
$maxValue = 0;
|
||||
$maxWorthItem = [];
|
||||
|
||||
foreach ($cart->items as $item) {
|
||||
if ($item->base_total > $maxValue) {
|
||||
$maxValue = $item->total;
|
||||
$maxWorthItem = [
|
||||
'id' => $item->id,
|
||||
'price' => $item->price,
|
||||
'base_price' => $item->base_price,
|
||||
'quantity' => $item->quantity
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
return $maxWorthItem;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks the rule against the current cart instance whether rule conditions are applicable
|
||||
* or not
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
protected function testIfAllConditionAreTrue($conditions, $cart)
|
||||
{
|
||||
array_pop($conditions);
|
||||
|
||||
$shipping_address = $cart->getShippingAddressAttribute() ?? '';
|
||||
|
||||
$shipping_method = $cart->shipping_method ?? '';
|
||||
|
|
@ -480,10 +327,8 @@ class Discount
|
|||
$total_weight = $total_weight + $item->base_total_weight;
|
||||
}
|
||||
|
||||
$test_mode = config('pricerules.test_mode.0');
|
||||
$test_conditions = config('pricerules.cart.conditions');
|
||||
$result = true;
|
||||
|
||||
$result = 1;
|
||||
foreach ($conditions as $condition) {
|
||||
$actual_value = ${$condition->attribute};
|
||||
$test_value = $condition->value;
|
||||
|
|
@ -492,43 +337,127 @@ class Discount
|
|||
if ($condition->type == 'numeric' || $condition->type == 'string' || $condition->type == 'text') {
|
||||
if ($test_condition == '=') {
|
||||
if ($actual_value != $test_value) {
|
||||
$result = 0;
|
||||
$result = false;
|
||||
|
||||
break;
|
||||
}
|
||||
} else if ($test_condition == '>=') {
|
||||
if (! ($actual_value >= $test_value)) {
|
||||
$result = 0;
|
||||
$result = false;
|
||||
|
||||
break;
|
||||
}
|
||||
} else if ($test_condition == '<=') {
|
||||
if (! ($actual_value <= $test_value)) {
|
||||
$result = 0;
|
||||
$result = false;
|
||||
|
||||
break;
|
||||
}
|
||||
} else if ($test_condition == '>') {
|
||||
if (! ($actual_value > $test_value)) {
|
||||
$result = 0;
|
||||
$result = false;
|
||||
|
||||
break;
|
||||
}
|
||||
} else if ($test_condition == '<') {
|
||||
if (! ($actual_value < $test_value)) {
|
||||
$result = 0;
|
||||
$result = false;
|
||||
|
||||
break;
|
||||
}
|
||||
} else if ($test_condition == '{}') {
|
||||
if (! str_contains($actual_value, $test_value)) {
|
||||
$result = 0;
|
||||
$result = false;
|
||||
|
||||
break;
|
||||
}
|
||||
} else if ($test_condition == '!{}') {
|
||||
if (str_contains($actual_value, $test_value)) {
|
||||
$result = 0;
|
||||
$result = false;
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks the rule against the current cart instance whether rule conditions are applicable
|
||||
* or not
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
protected function testIfAnyConditionIsTrue($conditions, $cart) {
|
||||
array_pop($conditions);
|
||||
|
||||
$result = false;
|
||||
|
||||
$shipping_address = $cart->getShippingAddressAttribute() ?? '';
|
||||
|
||||
$shipping_method = $cart->shipping_method ?? '';
|
||||
$shipping_country = $shipping_address->country ?? '';
|
||||
$shipping_state = $shipping_address->state ?? '';
|
||||
$shipping_postcode = $shipping_address->postcode ?? '';
|
||||
$shipping_city = $shipping_address->city ?? '';
|
||||
|
||||
$payment_method = $cart->payment->method ?? '';
|
||||
$sub_total = $cart->base_sub_total;
|
||||
|
||||
$total_items = $cart->items_qty;
|
||||
$total_weight = 0;
|
||||
|
||||
foreach($cart->items as $item) {
|
||||
$total_weight = $total_weight + $item->base_total_weight;
|
||||
}
|
||||
|
||||
foreach ($conditions as $condition) {
|
||||
$actual_value = ${$condition->attribute};
|
||||
$test_value = $condition->value;
|
||||
$test_condition = $condition->condition;
|
||||
|
||||
if ($condition->type == 'numeric' || $condition->type == 'string' || $condition->type == 'text') {
|
||||
if ($test_condition == '=') {
|
||||
if ($actual_value == $test_value) {
|
||||
$result = true;
|
||||
|
||||
break;
|
||||
}
|
||||
} else if ($test_condition == '>=') {
|
||||
if ($actual_value >= $test_value) {
|
||||
$result = true;
|
||||
|
||||
break;
|
||||
}
|
||||
} else if ($test_condition == '<=') {
|
||||
if ($actual_value <= $test_value) {
|
||||
$result = true;
|
||||
|
||||
break;
|
||||
}
|
||||
} else if ($test_condition == '>') {
|
||||
if ($actual_value > $test_value) {
|
||||
$result = true;
|
||||
|
||||
break;
|
||||
}
|
||||
} else if ($test_condition == '<') {
|
||||
if ($actual_value < $test_value) {
|
||||
$result = true;
|
||||
|
||||
break;
|
||||
}
|
||||
} else if ($test_condition == '{}') {
|
||||
if (str_contains($actual_value, $test_value)) {
|
||||
$result = true;
|
||||
|
||||
break;
|
||||
}
|
||||
} else if ($test_condition == '!{}') {
|
||||
if (str_contains($actual_value, $test_value)) {
|
||||
$result = true;
|
||||
|
||||
break;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,185 @@
|
|||
<?php
|
||||
|
||||
namespace Webkul\Discount\Helpers;
|
||||
|
||||
use Webkul\Discount\Helpers\Discount;
|
||||
|
||||
use Cart;
|
||||
|
||||
class NonCouponAbleRule extends Discount
|
||||
{
|
||||
/**
|
||||
* Applies the non couponable rule on the current cart instance
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function apply($code = null)
|
||||
{
|
||||
$cart = Cart::getCart();
|
||||
|
||||
$applicableRules = array();
|
||||
|
||||
if (auth()->guard('customer')->check()) {
|
||||
$rules = $this->cartRule->findWhere([
|
||||
'use_coupon' => 0,
|
||||
'status' => 1
|
||||
]);
|
||||
} else {
|
||||
$rules = $this->cartRule->findWhere([
|
||||
'use_coupon' => 0,
|
||||
'is_guest' => 1,
|
||||
'status' => 1
|
||||
]);
|
||||
}
|
||||
|
||||
$alreadyAppliedRule = $this->cartRuleCart->findWhere([
|
||||
'cart_id' => $cart->id,
|
||||
]);
|
||||
|
||||
|
||||
if (count($alreadyAppliedRule)) {
|
||||
$alreadyAppliedRule = $alreadyAppliedRule->first()->cart_rule;
|
||||
|
||||
if ($alreadyAppliedRule->use_coupon) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// time based filter
|
||||
foreach($rules as $rule) {
|
||||
$applicability = $this->checkApplicability($rule);
|
||||
|
||||
if ($applicability) {
|
||||
$item = $this->leastWorthItem();
|
||||
|
||||
$actionInstance = new $this->rules[$rule->action_type];
|
||||
|
||||
$impact = $actionInstance->calculate($rule, $item, $cart);
|
||||
|
||||
array_push($applicableRules, [
|
||||
'rule' => $rule,
|
||||
'impact' => $impact
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
if (count($applicableRules) > 1) {
|
||||
// priority criteria
|
||||
$prioritySorted = array();
|
||||
$leastPriority = 999999999999;
|
||||
|
||||
foreach ($applicableRules as $applicableRule) {
|
||||
if ($applicableRule['rule']->priority <= $leastPriority) {
|
||||
$leastPriority = $applicableRule['rule']->priority;
|
||||
array_push($prioritySorted, $applicableRule);
|
||||
}
|
||||
}
|
||||
|
||||
// end rule criteria with end rule
|
||||
$endRules = array();
|
||||
|
||||
if (count($prioritySorted) > 1) {
|
||||
foreach ($prioritySorted as $prioritySortedRule) {
|
||||
if ($prioritySortedRule['rule']->end_other_rules) {
|
||||
array_push($endRules, $prioritySortedRule);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$this->save(array_first($prioritySorted)['rule']);
|
||||
|
||||
return $prioritySorted;
|
||||
}
|
||||
|
||||
// max impact criteria with end rule
|
||||
$maxImpacts = array();
|
||||
|
||||
if (count($endRules)) {
|
||||
$this->endRuleActive = true;
|
||||
|
||||
if (count($endRules) == 1) {
|
||||
$this->save(array_first($endRules)['rule']);
|
||||
|
||||
return $endRules;
|
||||
}
|
||||
|
||||
$maxImpact = 0;
|
||||
|
||||
foreach ($endRules as $endRule) {
|
||||
if ($endRule['impact']['discount'] >= $maxImpact) {
|
||||
$maxImpact = $endRule['impact']['discount'];
|
||||
|
||||
array_push($maxImpacts, $endRule);
|
||||
}
|
||||
}
|
||||
|
||||
// oldest and max impact criteria
|
||||
$leastId = 999999999999;
|
||||
$leastIdImpactIndex = 0;
|
||||
|
||||
if (count($maxImpacts) > 1) {
|
||||
foreach ($maxImpacts as $index => $maxImpactRule) {
|
||||
if ($maxImpactRule['rule']->id < $leastId) {
|
||||
$leastId = $maxImpactRule['rule']->id;
|
||||
|
||||
$leastIdImpactIndex = $index;
|
||||
}
|
||||
}
|
||||
|
||||
$this->save($maxImpacts[$leastIdImpactIndex]['rule']);
|
||||
|
||||
return $maxImpacts[$leastIdImpactIndex];
|
||||
} else {
|
||||
$this->save(array_first($maxImpacts)['rule']);
|
||||
|
||||
return $maxImpacts;
|
||||
}
|
||||
}
|
||||
|
||||
if (count($prioritySorted) > 1) {
|
||||
$maxImpact = 0;
|
||||
|
||||
foreach ($prioritySorted as $prioritySortedRule) {
|
||||
if ($prioritySortedRule['impact']['discount'] >= $maxImpact) {
|
||||
$maxImpact = $prioritySortedRule['impact']['discount'];
|
||||
|
||||
array_push($maxImpacts, $prioritySortedRule);
|
||||
}
|
||||
}
|
||||
|
||||
// oldest and max impact criteria
|
||||
$leastId = 999999999999;
|
||||
$leastIdImpactIndex = 0;
|
||||
|
||||
if (count($maxImpacts) > 1) {
|
||||
foreach ($maxImpacts as $index => $maxImpactRule) {
|
||||
if ($maxImpactRule['rule']->id < $leastId) {
|
||||
$leastId = $maxImpactRule['rule']->id;
|
||||
|
||||
$leastIdImpactIndex = $index;
|
||||
}
|
||||
}
|
||||
|
||||
$this->save($maxImpacts[$leastIdImpactIndex]['rule']);
|
||||
|
||||
return $maxImpacts[$leastIdImpactIndex];
|
||||
} else {
|
||||
$this->save(array_first($maxImpacts)['rule']);
|
||||
|
||||
return $maxImpacts;
|
||||
}
|
||||
} else {
|
||||
$this->save(array_first($prioritySorted)['rule']);
|
||||
|
||||
return $prioritySorted;
|
||||
}
|
||||
} else if (count($applicableRules) == 1) {
|
||||
$rule = array_first($applicableRules)['rule'];
|
||||
|
||||
$this->save($applicableRules);
|
||||
|
||||
return array_first($applicableRules)['impact'];
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -79,16 +79,14 @@ class CartRuleController extends Controller
|
|||
}
|
||||
|
||||
/**
|
||||
* @return Redirect
|
||||
* @return redirect
|
||||
*/
|
||||
public function store()
|
||||
{
|
||||
$data = request()->all();
|
||||
|
||||
$validated = $this->validate($data, [
|
||||
$validated = $this->validate(request(), [
|
||||
'name' => 'required|string',
|
||||
'description' => 'string',
|
||||
// 'customer_groups' => 'required|array',
|
||||
'customer_groups' => 'required|array',
|
||||
'channels' => 'required|array',
|
||||
'status' => 'required|boolean',
|
||||
'use_coupon' => 'boolean|required',
|
||||
|
|
@ -105,32 +103,49 @@ class CartRuleController extends Controller
|
|||
'label' => 'array|nullable'
|
||||
]);
|
||||
|
||||
$data = [
|
||||
'usage_limit' => 0,
|
||||
'per_customer' => 0
|
||||
];
|
||||
$data = request()->all();
|
||||
|
||||
if ($data['starts_from'] == "" || $data['ends_till'] == "") {
|
||||
// unset token
|
||||
unset($data['_token']);
|
||||
|
||||
// set usage limit
|
||||
$data['usage_limit'] = 0;
|
||||
|
||||
// set per customer usage limit
|
||||
$data['per_customer'] = 0;
|
||||
|
||||
// check if starts_from is null
|
||||
if ($data['starts_from'] == "") {
|
||||
$data['starts_from'] = null;
|
||||
}
|
||||
|
||||
// check if end_till is null
|
||||
if ($data['ends_till'] == "") {
|
||||
$data['ends_till'] = null;
|
||||
}
|
||||
|
||||
unset($data['_token']);
|
||||
// customer groups
|
||||
$customer_groups = $data['customer_groups'];
|
||||
|
||||
$channels = $data['channels'];
|
||||
// unset customer groups
|
||||
unset($data['customer_groups']);
|
||||
|
||||
unset($data['channels']);
|
||||
|
||||
// $customer_groups = $data['customer_groups'];
|
||||
// unset($data['customer_groups']);
|
||||
// unset criteria
|
||||
unset($data['criteria']);
|
||||
|
||||
// channels
|
||||
$channels = $data['channels'];
|
||||
|
||||
// unset channels
|
||||
unset($data['channels']);
|
||||
|
||||
// make labels
|
||||
$labels = $data['label'];
|
||||
|
||||
// unset labels
|
||||
unset($data['label']);
|
||||
unset($data['cart_attributes']);
|
||||
unset($data['attributes']);
|
||||
|
||||
// prepare json object from actions
|
||||
if (isset($data['disc_amount']) && $data['action_type'] == config('pricerules.cart.validations.2')) {
|
||||
$data['actions'] = [
|
||||
'action_type' => $data['action_type'],
|
||||
|
|
@ -147,22 +162,37 @@ class CartRuleController extends Controller
|
|||
];
|
||||
}
|
||||
|
||||
// prepare json object from conditions
|
||||
$data['actions'] = json_encode($data['actions']);
|
||||
|
||||
if (! isset($data['all_conditions']) || $data['all_conditions'] == "[]") {
|
||||
// check if all
|
||||
if (! isset($data['all_conditions']) || $data['all_conditions'] == "[]" || $data['all_conditions'] == "") {
|
||||
$data['conditions'] = null;
|
||||
} else {
|
||||
$data['conditions'] = json_encode($data['all_conditions']);
|
||||
}
|
||||
|
||||
// unset cart_attributes from conditions
|
||||
unset($data['cart_attributes']);
|
||||
|
||||
// unset attributes from conditions
|
||||
unset($data['attributes']);
|
||||
|
||||
// unset all_conditions from conditions
|
||||
unset($data['all_conditions']);
|
||||
|
||||
// prepare coupons if coupons are used
|
||||
if ($data['use_coupon']) {
|
||||
// if (isset($data['auto_generation']) && $data['auto_generation']) {
|
||||
// auto generation is off for now
|
||||
$data['auto_generation'] = 0;
|
||||
|
||||
// save the coupon used in coupon section
|
||||
$coupons['code'] = $data['code'];
|
||||
|
||||
// set coupon usage per customer same as per_customer limit which is disabled for now
|
||||
$coupons['usage_per_customer'] = $data['per_customer']; //0 is for unlimited usage
|
||||
// unset coupon code from coupon section
|
||||
unset($data['code']);
|
||||
// } else {
|
||||
// $data['auto_generation'] = 1;
|
||||
|
|
@ -181,15 +211,21 @@ class CartRuleController extends Controller
|
|||
// $coupons['limit'] = 0;
|
||||
}
|
||||
|
||||
// per coupon usage limit
|
||||
// if(isset($data['usage_limit'])) {
|
||||
// $coupons['limit'] = $data['usage_limit'];
|
||||
// }
|
||||
|
||||
// create a cart rule
|
||||
$ruleCreated = $this->cartRule->create($data);
|
||||
|
||||
// $ruleGroupCreated = $this->cartRule->CustomerGroupSync($customer_groups, $ruleCreated);
|
||||
// create customer groups for cart rule
|
||||
$ruleGroupCreated = $this->cartRule->CustomerGroupSync($customer_groups, $ruleCreated);
|
||||
|
||||
// create customer groups for channels
|
||||
$ruleChannelCreated = $this->cartRule->ChannelSync($channels, $ruleCreated);
|
||||
|
||||
// prepare labels
|
||||
if (isset($labels['global'])) {
|
||||
foreach (core()->getAllChannels() as $channel) {
|
||||
$label1['channel_id'] = $channel->id;
|
||||
|
|
@ -209,14 +245,13 @@ class CartRuleController extends Controller
|
|||
$ruleLabelCreated = $this->cartRuleLabel->create($label2);
|
||||
}
|
||||
|
||||
// create coupon if present
|
||||
if (isset($coupons)) {
|
||||
$coupons['cart_rule_id'] = $ruleCreated->id;
|
||||
$coupons['usage_per_customer'] = $data['per_customer']; //0 is for unlimited usage
|
||||
|
||||
$couponCreated = $this->cartRuleCoupon->create($coupons);
|
||||
}
|
||||
|
||||
if ($ruleCreated && $ruleChannelCreated) {
|
||||
if ($ruleCreated && $ruleChannelCreated && $ruleGroupCreated) {
|
||||
if (isset($couponCreated) && $couponCreated) {
|
||||
session()->flash('success', trans('admin::app.promotion.status.success-coupon'));
|
||||
}
|
||||
|
|
@ -251,12 +286,10 @@ class CartRuleController extends Controller
|
|||
*/
|
||||
public function update($id)
|
||||
{
|
||||
$types = config('price_rules.cart.validations');
|
||||
|
||||
$this->validate(request(), [
|
||||
'name' => 'required|string',
|
||||
'description' => 'string',
|
||||
// 'customer_groups' => 'required|array',
|
||||
'customer_groups' => 'required|array',
|
||||
'channels' => 'required|array',
|
||||
'status' => 'required|boolean',
|
||||
'use_coupon' => 'boolean|required',
|
||||
|
|
@ -273,35 +306,52 @@ class CartRuleController extends Controller
|
|||
'label' => 'array|nullable'
|
||||
]);
|
||||
|
||||
$data['usage_limit'] = 0;
|
||||
$data['per_customer'] = 0;
|
||||
|
||||
// collecting request in $data
|
||||
$data = request()->all();
|
||||
|
||||
if ($data['starts_from'] == "" || $data['ends_till'] == "") {
|
||||
// unset request token from $data
|
||||
unset($data['_token']);
|
||||
|
||||
// set rule uasge limit
|
||||
$data['usage_limit'] = 0;
|
||||
|
||||
// set rule usage per customer
|
||||
$data['per_customer'] = 0;
|
||||
|
||||
// check if starts_from is null
|
||||
if ($data['starts_from'] == "") {
|
||||
$data['starts_from'] = null;
|
||||
}
|
||||
|
||||
// check if end_till is null
|
||||
if ($data['ends_till'] == "") {
|
||||
$data['ends_till'] = null;
|
||||
}
|
||||
|
||||
unset($data['_token']);
|
||||
|
||||
// set channels
|
||||
$channels = $data['channels'];
|
||||
|
||||
// unset the channels from $data
|
||||
unset($data['channels']);
|
||||
|
||||
// $customer_groups = $data['customer_groups'];
|
||||
// unset($data['customer_groups']);
|
||||
// unset($data['criteria']);
|
||||
// set customer_groups
|
||||
$customer_groups = $data['customer_groups'];
|
||||
|
||||
// unset customer groups
|
||||
unset($data['customer_groups']);
|
||||
|
||||
// set labels and unset them from $data
|
||||
if (isset($data['label'])) {
|
||||
$labels = $data['label'];
|
||||
|
||||
unset($data['label']);
|
||||
}
|
||||
|
||||
// unset cart_attributes and attributes from $data
|
||||
unset($data['cart_attributes']);
|
||||
unset($data['attributes']);
|
||||
|
||||
// prepare actions from data for json action
|
||||
if (isset($data['disc_amount']) && $data['action_type'] == config('pricerules.cart.validations.2')) {
|
||||
$data['actions'] = [
|
||||
'action_type' => $data['action_type'],
|
||||
|
|
@ -318,16 +368,22 @@ class CartRuleController extends Controller
|
|||
];
|
||||
}
|
||||
|
||||
// encode php array to json for actions
|
||||
$data['actions'] = json_encode($data['actions']);
|
||||
|
||||
if (! isset($data['all_conditions']) || $data['all_conditions'] == "[]") {
|
||||
// Prepares conditions from all conditions
|
||||
if (! isset($data['all_conditions']) || $data['all_conditions'] == "[]" || $data['all_conditions'] == "") {
|
||||
$data['conditions'] = null;
|
||||
} else {
|
||||
$data['conditions'] = json_encode($data['all_conditions']);
|
||||
}
|
||||
|
||||
unset($data['match_criteria']);
|
||||
|
||||
// unset all_conditions from conditions
|
||||
unset($data['all_conditions']);
|
||||
|
||||
// set coupons from $data
|
||||
if ($data['use_coupon']) {
|
||||
// if (isset($data['auto_generation']) && $data['auto_generation']) {
|
||||
$data['auto_generation'] = 0;
|
||||
|
|
@ -355,13 +411,19 @@ class CartRuleController extends Controller
|
|||
// $coupons['limit'] = $data['usage_limit'];
|
||||
// }
|
||||
|
||||
// update cart rule
|
||||
$ruleUpdated = $this->cartRule->update($data, $id);
|
||||
|
||||
// $ruleGroupUpdated = $this->cartRule->CustomerGroupSync($customer_groups, $ruleUpdated);
|
||||
// update customer groups for cart rule
|
||||
$ruleGroupUpdated = $this->cartRule->CustomerGroupSync($customer_groups, $ruleUpdated);
|
||||
|
||||
// update customer groups for cart rule
|
||||
$ruleChannelUpdated = $this->cartRule->ChannelSync($channels, $ruleUpdated);
|
||||
|
||||
// update labels
|
||||
$labelsUpdated = $this->cartRule->LabelSync($labels, $ruleUpdated);
|
||||
|
||||
// check coupons set conditions
|
||||
if (isset($coupons)) {
|
||||
$coupons['cart_rule_id'] = $ruleUpdated->id;
|
||||
// $coupons['usage_per_customer'] = $data['per_customer']; //0 is for unlimited usage
|
||||
|
|
@ -369,7 +431,7 @@ class CartRuleController extends Controller
|
|||
$couponUpdated = $ruleUpdated->coupons->update($coupons);
|
||||
}
|
||||
|
||||
if ($ruleUpdated && $ruleChannelUpdated) {
|
||||
if ($ruleUpdated && $ruleGroupUpdated && $ruleChannelUpdated) {
|
||||
if (isset($couponUpdated) && $couponUpdated) {
|
||||
session()->flash('info', trans('admin::app.promotion.status.success-coupon'));
|
||||
}
|
||||
|
|
@ -384,6 +446,11 @@ class CartRuleController extends Controller
|
|||
return redirect()->route($this->_config['redirect']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes the cart rule
|
||||
*
|
||||
* @return JSON
|
||||
*/
|
||||
public function destroy($id)
|
||||
{
|
||||
$cartRule = $this->cartRule->findOrFail($id);
|
||||
|
|
@ -399,6 +466,11 @@ class CartRuleController extends Controller
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Countries and states list from core helpers
|
||||
*
|
||||
* @return Array
|
||||
*/
|
||||
public function getStatesAndCountries()
|
||||
{
|
||||
$countries = core()->countries()->toArray();
|
||||
|
|
|
|||
|
|
@ -35,5 +35,9 @@ class DiscountServiceProvider extends ServiceProvider
|
|||
$this->mergeConfigFrom(
|
||||
dirname(__DIR__) . '/Config/rule-conditions.php', 'pricerules'
|
||||
);
|
||||
|
||||
$this->mergeConfigFrom(
|
||||
dirname(__DIR__) . '/Config/discount-rules.php', 'discount-rules'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
@ -9,7 +9,6 @@ use Webkul\Checkout\Repositories\CartItemRepository;
|
|||
use Webkul\Product\Repositories\ProductRepository;
|
||||
use Webkul\Customer\Repositories\CustomerRepository;
|
||||
use Webkul\Customer\Repositories\WishlistRepository;
|
||||
use Webkul\Discount\Repositories\CartRuleCartRepository as CartRuleCart;
|
||||
use Illuminate\Support\Facades\Event;
|
||||
use Cart;
|
||||
|
||||
|
|
@ -34,11 +33,15 @@ class CartController extends Controller
|
|||
* @param $productView
|
||||
*/
|
||||
protected $_config;
|
||||
|
||||
protected $cart;
|
||||
|
||||
protected $cartItem;
|
||||
|
||||
protected $customer;
|
||||
|
||||
protected $product;
|
||||
protected $cartRuleCart;
|
||||
|
||||
protected $suppressFlash = false;
|
||||
|
||||
/**
|
||||
|
|
@ -53,8 +56,7 @@ class CartController extends Controller
|
|||
CartItemRepository $cartItem,
|
||||
CustomerRepository $customer,
|
||||
ProductRepository $product,
|
||||
WishlistRepository $wishlist,
|
||||
CartRuleCart $cartRuleCart
|
||||
WishlistRepository $wishlist
|
||||
)
|
||||
{
|
||||
|
||||
|
|
@ -70,8 +72,6 @@ class CartController extends Controller
|
|||
|
||||
$this->wishlist = $wishlist;
|
||||
|
||||
$this->cartRuleCart = $cartRuleCart;
|
||||
|
||||
$this->_config = request('_config');
|
||||
}
|
||||
|
||||
|
|
@ -252,60 +252,4 @@ class CartController extends Controller
|
|||
return redirect()->back();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* To apply coupon rules
|
||||
*/
|
||||
public function applyCoupon()
|
||||
{
|
||||
$this->validate(request(), [
|
||||
'code' => 'string|required'
|
||||
]);
|
||||
|
||||
$code = request()->input('code');
|
||||
|
||||
$result = Cart::applyCoupon($code);
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch the non couponable rule
|
||||
*/
|
||||
public function getNonCouponAbleRule()
|
||||
{
|
||||
$cart = Cart::getCart();
|
||||
$nonCouponAbleRules = Cart::applyNonCoupon();
|
||||
|
||||
return $nonCouponAbleRules;
|
||||
}
|
||||
|
||||
/**
|
||||
* To save the discount values inside the tables of orders and cart
|
||||
*/
|
||||
public function saveDiscount()
|
||||
{
|
||||
return ['hellow'];
|
||||
}
|
||||
|
||||
/**
|
||||
* To remove the currently active
|
||||
* couponable rule
|
||||
*/
|
||||
public function removeCoupon()
|
||||
{
|
||||
$result = Cart::removeCoupon();
|
||||
|
||||
if ($result) {
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => trans('admin::app.promotion.status.coupon-removed')
|
||||
]);
|
||||
} else {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => trans('admin::app.promotion.status.coupon-remove-failed')
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -3,20 +3,22 @@
|
|||
namespace Webkul\Shop\Http\Controllers;
|
||||
|
||||
use Webkul\Shop\Http\Controllers\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Response;
|
||||
use Auth;
|
||||
use Webkul\Checkout\Facades\Cart;
|
||||
use Webkul\Shipping\Facades\Shipping;
|
||||
use Webkul\Payment\Facades\Payment;
|
||||
use Webkul\Discount\Repositories\CartRuleCartRepository as CartRuleCart;
|
||||
use Webkul\Checkout\Http\Requests\CustomerAddressForm;
|
||||
use Webkul\Sales\Repositories\OrderRepository;
|
||||
use Webkul\Discount\Helpers\CouponAbleRule as Coupon;
|
||||
use Webkul\Discount\Helpers\NonCouponAbleRule as NonCoupon;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Response;
|
||||
use Auth;
|
||||
|
||||
/**
|
||||
* Chekout controller for the customer and guest for placing order
|
||||
*
|
||||
* @author Jitendra Singh <jitendra@webkul.com>
|
||||
* @author Jitendra Singh <jitendra@webkul.com> @jitendra-webkul
|
||||
* @author Prashant Singh <prashant.singh852@webkul.com> @prashant-webkul
|
||||
* @copyright 2018 Webkul Software Pvt Ltd (http://www.webkul.com)
|
||||
*/
|
||||
class OnepageController extends Controller
|
||||
|
|
@ -28,13 +30,6 @@ class OnepageController extends Controller
|
|||
*/
|
||||
protected $orderRepository;
|
||||
|
||||
/**
|
||||
* CartRuleCartRepository object
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $cartRuleCart;
|
||||
|
||||
/**
|
||||
* Contains route related configuration
|
||||
*
|
||||
|
|
@ -42,17 +37,31 @@ class OnepageController extends Controller
|
|||
*/
|
||||
protected $_config;
|
||||
|
||||
/**
|
||||
*
|
||||
* CouponAbleRule instance
|
||||
*/
|
||||
protected $coupon;
|
||||
|
||||
/**
|
||||
*
|
||||
* NoncouponAbleRule instance
|
||||
*/
|
||||
protected $nonCoupon;
|
||||
|
||||
/**
|
||||
* Create a new controller instance.
|
||||
*
|
||||
* @param \Webkul\Attribute\Repositories\OrderRepository $orderRepository
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(OrderRepository $orderRepository, CartRuleCart $cartRuleCart)
|
||||
public function __construct(OrderRepository $orderRepository, Coupon $coupon, NonCoupon $nonCoupon)
|
||||
{
|
||||
$this->orderRepository = $orderRepository;
|
||||
$this->coupon = $coupon;
|
||||
|
||||
$this->cartRuleCart = $cartRuleCart;
|
||||
$this->nonCoupon = $nonCoupon;
|
||||
|
||||
$this->orderRepository = $orderRepository;
|
||||
|
||||
$this->_config = request('_config');
|
||||
}
|
||||
|
|
@ -67,7 +76,9 @@ class OnepageController extends Controller
|
|||
if (Cart::hasError())
|
||||
return redirect()->route('shop.checkout.cart.index');
|
||||
|
||||
Cart::applyNonCoupon();
|
||||
$this->nonCoupon->apply();
|
||||
|
||||
Cart::collectTotals();
|
||||
|
||||
return view($this->_config['view'])->with('cart', Cart::getCart());
|
||||
}
|
||||
|
|
@ -99,13 +110,13 @@ class OnepageController extends Controller
|
|||
$data['billing']['address1'] = implode(PHP_EOL, array_filter($data['billing']['address1']));
|
||||
$data['shipping']['address1'] = implode(PHP_EOL, array_filter($data['shipping']['address1']));
|
||||
|
||||
if (Cart::hasError() || !Cart::saveCustomerAddress($data) || ! $rates = Shipping::collectRates())
|
||||
return response()->json(['redirect_url' => route('shop.checkout.cart.index')], 403);
|
||||
|
||||
Cart::applyNonCoupon();
|
||||
$this->nonCoupon->apply();
|
||||
|
||||
Cart::collectTotals();
|
||||
|
||||
if (Cart::hasError() || !Cart::saveCustomerAddress($data) || ! $rates = Shipping::collectRates())
|
||||
return response()->json(['redirect_url' => route('shop.checkout.cart.index')], 403);
|
||||
|
||||
return response()->json($rates);
|
||||
}
|
||||
|
||||
|
|
@ -118,13 +129,13 @@ class OnepageController extends Controller
|
|||
{
|
||||
$shippingMethod = request()->get('shipping_method');
|
||||
|
||||
if (Cart::hasError() || !$shippingMethod || !Cart::saveShippingMethod($shippingMethod))
|
||||
return response()->json(['redirect_url' => route('shop.checkout.cart.index')], 403);
|
||||
|
||||
Cart::applyNonCoupon();
|
||||
$this->nonCoupon->apply();
|
||||
|
||||
Cart::collectTotals();
|
||||
|
||||
if (Cart::hasError() || !$shippingMethod || !Cart::saveShippingMethod($shippingMethod))
|
||||
return response()->json(['redirect_url' => route('shop.checkout.cart.index')], 403);
|
||||
|
||||
return response()->json(Payment::getSupportedPaymentMethods());
|
||||
}
|
||||
|
||||
|
|
@ -137,15 +148,15 @@ class OnepageController extends Controller
|
|||
{
|
||||
$payment = request()->get('payment');
|
||||
|
||||
$this->nonCoupon->apply();
|
||||
|
||||
Cart::collectTotals();
|
||||
|
||||
if (Cart::hasError() || !$payment || !Cart::savePaymentMethod($payment))
|
||||
return response()->json(['redirect_url' => route('shop.checkout.cart.index')], 403);
|
||||
|
||||
$cart = Cart::getCart();
|
||||
|
||||
Cart::applyNonCoupon();
|
||||
|
||||
Cart::collectTotals();
|
||||
|
||||
return response()->json([
|
||||
'jump_to_section' => 'review',
|
||||
'html' => view('shop::checkout.onepage.review', compact('cart', 'rule'))->render()
|
||||
|
|
@ -208,6 +219,9 @@ class OnepageController extends Controller
|
|||
{
|
||||
$cart = Cart::getCart();
|
||||
|
||||
// extra validation check if some the conditions is changed for the coupons but not using it now
|
||||
// $this->nonCoupon->apply();
|
||||
|
||||
if (! $cart->shipping_address) {
|
||||
throw new \Exception(trans('Please check shipping address.'));
|
||||
}
|
||||
|
|
@ -224,4 +238,79 @@ class OnepageController extends Controller
|
|||
throw new \Exception(trans('Please specify payment method.'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* To apply couponable rule requested
|
||||
*
|
||||
* @return JSON
|
||||
*/
|
||||
public function applyCoupon()
|
||||
{
|
||||
$this->validate(request(), [
|
||||
'code' => 'string|required'
|
||||
]);
|
||||
|
||||
$code = request()->input('code');
|
||||
|
||||
$result = $this->coupon->apply($code);
|
||||
|
||||
if ($result) {
|
||||
Cart::collectTotals();
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => trans('shop::app.checkout.onepage.total.coupon-applied'),
|
||||
'result' => $result
|
||||
], 200);
|
||||
} else {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => trans('shop::app.checkout.onepage.total.cannot-apply-coupon'),
|
||||
'result' => null
|
||||
], 422);
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Applies non couponable rule if present
|
||||
*
|
||||
* @return Void
|
||||
*/
|
||||
public function applyNonCouponAbleRule()
|
||||
{
|
||||
$cart = Cart::getCart();
|
||||
$nonCouponAbleRules = Cart::applyNonCoupon();
|
||||
|
||||
return $nonCouponAbleRules;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initiates the removal of couponable cart rule
|
||||
*
|
||||
* @return Void
|
||||
*/
|
||||
public function removeCoupon()
|
||||
{
|
||||
$result = $this->coupon->remove();
|
||||
|
||||
if ($result) {
|
||||
Cart::collectTotals();
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => trans('admin::app.promotion.status.coupon-removed'),
|
||||
'data' => [
|
||||
'grand_total' => core()->currency(Cart::getCart()->grand_total)
|
||||
]
|
||||
], 200);
|
||||
} else {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => trans('admin::app.promotion.status.coupon-remove-failed'),
|
||||
'data' => null
|
||||
], 422);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -39,13 +39,9 @@ Route::group(['middleware' => ['web', 'locale', 'theme', 'currency']], function
|
|||
'view' => 'shop::checkout.cart.index'
|
||||
])->name('shop.checkout.cart.index');
|
||||
|
||||
Route::post('checkout/check/coupons', 'Webkul\Shop\Http\Controllers\CartController@applyCoupon')->name('shop.checkout.check.coupons');
|
||||
Route::post('checkout/check/coupons', 'Webkul\Shop\Http\Controllers\OnepageController@applyCoupon')->name('shop.checkout.check.coupons');
|
||||
|
||||
Route::post('checkout/save/discounts', 'Webkul\Shop\Http\Controllers\CartController@saveDiscount')->name('shop.checkout.save.discount');
|
||||
|
||||
Route::post('checkout/fetch/noncoupon', 'Webkul\Shop\Http\Controllers\CartController@getNonCouponAbleRule')->name('shop.checkout.fetch.non-coupon');
|
||||
|
||||
Route::post('checkout/remove/coupon', 'Webkul\Shop\Http\Controllers\CartController@removeCoupon')->name('shop.checkout.remove.coupon');
|
||||
Route::post('checkout/remove/coupon', 'Webkul\Shop\Http\Controllers\OnepageController@removeCoupon')->name('shop.checkout.remove.coupon');
|
||||
|
||||
//Cart Items Add
|
||||
Route::post('checkout/cart/add/{id}', 'Webkul\Shop\Http\Controllers\CartController@add')->defaults('_config', [
|
||||
|
|
|
|||
|
|
@ -456,7 +456,8 @@ return [
|
|||
'new-grand-total' => 'New Grand Total',
|
||||
'coupon' => 'Coupon',
|
||||
'coupon-applied' => 'Coupon Applied',
|
||||
'remove-coupon' => 'Remove Coupon'
|
||||
'remove-coupon' => 'Remove Coupon',
|
||||
'cannot-apply-coupon' => 'Cannot Apply Coupon'
|
||||
],
|
||||
|
||||
'success' => [
|
||||
|
|
|
|||
|
|
@ -72,7 +72,11 @@
|
|||
</div>
|
||||
|
||||
<div class="step-content review" v-show="currentStep == 4" id="summary-section">
|
||||
<review-section v-if="currentStep == 4"></review-section>
|
||||
<review-section v-if="currentStep == 4">
|
||||
<div slot="summary-section" v-if="resetSummary">
|
||||
<summary-section discount="1" @onApplyCoupon="getOrderSummary" @onRemoveCoupon="getOrderSummary"></summary-section>
|
||||
</div>
|
||||
</review-section>
|
||||
|
||||
<div class="button-group">
|
||||
<button type="button" class="btn btn-lg btn-primary" @click="placeOrder()" :disabled="disable_button" id="checkout-place-order-button">
|
||||
|
|
@ -83,7 +87,7 @@
|
|||
</div>
|
||||
|
||||
<div class="col-right" v-if="resetSummary" v-show="currentStep != 4">
|
||||
<summary-section hide-discount="1"></summary-section>
|
||||
<summary-section></summary-section>
|
||||
</div>
|
||||
</div>
|
||||
</script>
|
||||
|
|
@ -203,7 +207,7 @@
|
|||
|
||||
setTimeout(function() {
|
||||
this_this.resetSummary = true;
|
||||
}, 0);
|
||||
}, 500);
|
||||
})
|
||||
.catch(function (error) {})
|
||||
},
|
||||
|
|
@ -341,56 +345,6 @@
|
|||
}
|
||||
})
|
||||
|
||||
var summaryTemplateRenderFns = [];
|
||||
|
||||
Vue.component('summary-section', {
|
||||
inject: ['$validator'],
|
||||
|
||||
data: function() {
|
||||
return {
|
||||
templateRender: null,
|
||||
|
||||
code: null,
|
||||
|
||||
coupon_used: false,
|
||||
|
||||
hide_discount: 0
|
||||
}
|
||||
},
|
||||
|
||||
staticRenderFns: summaryTemplateRenderFns,
|
||||
|
||||
mounted: function() {
|
||||
this.templateRender = summaryHtml.render;
|
||||
|
||||
for (var i in summaryHtml.staticRenderFns) {
|
||||
summaryTemplateRenderFns.push(summaryHtml.staticRenderFns[i]);
|
||||
}
|
||||
},
|
||||
|
||||
render: function(h) {
|
||||
return h('div', [
|
||||
(this.templateRender ?
|
||||
this.templateRender() :
|
||||
'')
|
||||
]);
|
||||
},
|
||||
|
||||
methods: {
|
||||
onSubmit: function() {
|
||||
var this_this = this;
|
||||
|
||||
axios.post('{{ route('shop.checkout.check.coupons') }}', {
|
||||
code: this_this.code
|
||||
}).then(function(response) {
|
||||
console.log(response.data);
|
||||
}).catch(function(error) {
|
||||
console.log(error.data);
|
||||
});
|
||||
},
|
||||
}
|
||||
})
|
||||
|
||||
var shippingTemplateRenderFns = [];
|
||||
|
||||
Vue.component('shipping-section', {
|
||||
|
|
@ -479,23 +433,67 @@
|
|||
var reviewTemplateRenderFns = [];
|
||||
|
||||
Vue.component('review-section', {
|
||||
props: ['resetSummary'],
|
||||
|
||||
data: function() {
|
||||
return {
|
||||
templateRender: null,
|
||||
|
||||
code: '',
|
||||
|
||||
hide_discount: 1
|
||||
error_message: ''
|
||||
}
|
||||
},
|
||||
|
||||
staticRenderFns: reviewTemplateRenderFns,
|
||||
|
||||
render: function(h) {
|
||||
return h('div', [
|
||||
(this.templateRender ?
|
||||
this.templateRender() :
|
||||
'')
|
||||
]);
|
||||
},
|
||||
|
||||
mounted: function() {
|
||||
this.templateRender = reviewHtml.render;
|
||||
|
||||
for (var i in reviewHtml.staticRenderFns) {
|
||||
reviewTemplateRenderFns.push(reviewHtml.staticRenderFns[i]);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
var summaryTemplateRenderFns = [];
|
||||
|
||||
Vue.component('summary-section', {
|
||||
inject: ['$validator'],
|
||||
|
||||
props: {
|
||||
discount: {
|
||||
type: [String, Number],
|
||||
|
||||
default: 0,
|
||||
}
|
||||
},
|
||||
|
||||
data: function() {
|
||||
return {
|
||||
templateRender: null,
|
||||
|
||||
coupon_code: null,
|
||||
|
||||
error_message: ''
|
||||
}
|
||||
},
|
||||
|
||||
staticRenderFns: summaryTemplateRenderFns,
|
||||
|
||||
mounted: function() {
|
||||
this.templateRender = summaryHtml.render;
|
||||
|
||||
for (var i in summaryHtml.staticRenderFns) {
|
||||
summaryTemplateRenderFns.push(summaryHtml.staticRenderFns[i]);
|
||||
}
|
||||
},
|
||||
|
||||
render: function(h) {
|
||||
|
|
@ -504,8 +502,30 @@
|
|||
this.templateRender() :
|
||||
'')
|
||||
]);
|
||||
},
|
||||
|
||||
methods: {
|
||||
onSubmit: function() {
|
||||
var this_this = this;
|
||||
|
||||
axios.post('{{ route('shop.checkout.check.coupons') }}', {code: this_this.coupon_code})
|
||||
.then(function(response) {
|
||||
this_this.$emit('onApplyCoupon')
|
||||
})
|
||||
.catch(function(error) {});
|
||||
},
|
||||
|
||||
removeCoupon: function () {
|
||||
var this_this = this;
|
||||
|
||||
axios.post('{{ route('shop.checkout.remove.coupon') }}')
|
||||
.then(function(response) {
|
||||
this_this.$emit('onRemoveCoupon')
|
||||
})
|
||||
.catch(function(error) {});
|
||||
}
|
||||
}
|
||||
});
|
||||
})
|
||||
</script>
|
||||
|
||||
@endpush
|
||||
|
|
@ -155,7 +155,7 @@
|
|||
</div>
|
||||
|
||||
<div class="pull-right" style="width: 40%; float: left;">
|
||||
@include('shop::checkout.total.summary', ['cart' => $cart])
|
||||
<slot name="summary-section"></slot>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
@ -24,38 +24,53 @@
|
|||
</div>
|
||||
@endif
|
||||
|
||||
@if ($cart->discount_amount && $cart->discount_amount > 0)
|
||||
<div class="item-detail">
|
||||
<label><b>{{ __('shop::app.checkout.total.disc-amount') }}</b></label>
|
||||
<label class="right"><b>{{ core()->currency($cart->discount_amount) }}</b></label>
|
||||
</div>
|
||||
@endif
|
||||
|
||||
<div class="payable-amount">
|
||||
<label>{{ __('shop::app.checkout.total.grand-total') }}</label>
|
||||
<label class="right">{{ core()->currency($cart->base_grand_total) }}</label>
|
||||
<div class="item-detail" id="discount-detail" @if ($cart->discount_amount && $cart->discount_amount > 0) style="display: block;" @else style="display: none;" @endif>
|
||||
<label>
|
||||
<b>{{ __('shop::app.checkout.total.disc-amount') }}</b>
|
||||
</label>
|
||||
<label class="right">
|
||||
<b id="discount-detail-discount-amount">
|
||||
{{ core()->currency($cart->discount_amount) }}
|
||||
</b>
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<div v-if="hide_discount">
|
||||
@if (! request()->is('checkout/cart') && ! $cart->coupon_code)
|
||||
<div class="discount">
|
||||
<div class="discount-group">
|
||||
<form class="coupon-form" method="post" @submit.prevent="onSubmit">
|
||||
<div class="control-group mt-20" :class="[errors.has('code') ? 'has-error' : '']">
|
||||
<input type="text" class="control" value="" v-model="code" name="code" placeholder="Enter Coupon Code" v-validate="'required'" style="width: 100%">
|
||||
</div>
|
||||
<div class="payable-amount" id="grand-total-detail">
|
||||
<label>{{ __('shop::app.checkout.total.grand-total') }}</label>
|
||||
<label class="right" id="grand-total-amount-detail">
|
||||
{{ core()->currency($cart->base_grand_total) }}
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<button class="btn btn-lg btn-black">{{ __('shop::app.checkout.onepage.apply-coupon') }}</button>
|
||||
</form>
|
||||
<div @if (! request()->is('checkout/cart')) v-if="parseInt(discount)" @endif>
|
||||
@if (! request()->is('checkout/cart'))
|
||||
@if (! $cart->coupon_code)
|
||||
<div class="discount">
|
||||
<div class="discount-group">
|
||||
<form class="coupon-form" method="post" @submit.prevent="onSubmit">
|
||||
<div class="control-group mt-20" :class="[errors.has('code') ? 'has-error' : '']">
|
||||
<input type="text" class="control" value="" v-model="coupon_code" name="code" placeholder="Enter Coupon Code" v-validate="'required'" style="width: 100%">
|
||||
</div>
|
||||
|
||||
<span class="control-error" v-if="error_message.length > 0">@{{ error_message }}</span>
|
||||
|
||||
<button class="btn btn-lg btn-black">{{ __('shop::app.checkout.onepage.apply-coupon') }}</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@else
|
||||
<div class="discount-details-group">
|
||||
<div class="item-detail">
|
||||
<label>{{ __('shop::app.checkout.total.coupon-applied') }}</label>
|
||||
<label class="right" style="display: inline-flex; align-items: center;">{{ $cart->coupon_code }} <span class="icon cross-icon" title="{{ __('shop::app.checkout.total.remove-coupon') }}"></span></label>
|
||||
@else
|
||||
<div class="discount-details-group">
|
||||
<div class="item-detail">
|
||||
<label>{{ __('shop::app.checkout.total.coupon-applied') }}</label>
|
||||
|
||||
<label class="right" style="display: inline-flex; align-items: center;">
|
||||
<b>{{ $cart->coupon_code }}</b>
|
||||
|
||||
<span class="icon cross-icon" title="{{ __('shop::app.checkout.total.remove-coupon') }}" v-on:click="removeCoupon"></span>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@endif
|
||||
@endif
|
||||
</div>
|
||||
</div>
|
||||
|
|
@ -205,6 +205,19 @@
|
|||
}
|
||||
document.getElementById("quantity").value = quantity;
|
||||
|
||||
var buyNowLink = $('.btn.buynow').attr('data-href');
|
||||
var splitted = buyNowLink.split("/");
|
||||
lastItem = splitted[splitted.length - 2];
|
||||
|
||||
splitted.pop();
|
||||
splitted.pop();
|
||||
|
||||
var joined = splitted.join('/');
|
||||
|
||||
var newBuyNowUrl = joined + '/' + lastItem + '/' + quantity;
|
||||
|
||||
$('.btn.buynow').attr('data-href', newBuyNowUrl);
|
||||
|
||||
event.preventDefault();
|
||||
}
|
||||
</script>
|
||||
|
|
|
|||
|
|
@ -148,13 +148,14 @@
|
|||
if (this.selectedProductId != '' && buyNowLink) {
|
||||
var splitted = buyNowLink.split("/");
|
||||
|
||||
splitted.pop();
|
||||
splitted.pop();
|
||||
|
||||
lastItem = this.selectedProductId;
|
||||
|
||||
var joined = splitted.join('/');
|
||||
|
||||
var newBuyNowUrl = joined + '/' + lastItem;
|
||||
var newBuyNowUrl = joined + '/' + lastItem + '/' + quantity;
|
||||
|
||||
$('.btn.buynow').attr('data-href', newBuyNowUrl);
|
||||
}
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
|
|
@ -1,4 +1,4 @@
|
|||
{
|
||||
"/js/ui.js": "/js/ui.js?id=97343143e38eeba34064",
|
||||
"/js/ui.js": "/js/ui.js?id=f4ffa4c6ada363152cf9",
|
||||
"/css/ui.css": "/css/ui.css?id=c846938a649c221ac297"
|
||||
}
|
||||
}
|
||||
|
|
@ -241,7 +241,7 @@ abstract class DataGrid
|
|||
$this->operators[$condition],
|
||||
'%'.$filter_value.'%'
|
||||
);
|
||||
} else if($this->enableFilterMap && !isset($this->filterMap[$columnName])) {
|
||||
} else if ($this->enableFilterMap && ! isset($this->filterMap[$columnName])) {
|
||||
$collection->where(
|
||||
$columnName,
|
||||
$this->operators[$condition],
|
||||
|
|
@ -264,7 +264,7 @@ abstract class DataGrid
|
|||
$this->operators[$condition],
|
||||
$filter_value
|
||||
);
|
||||
} else if($this->enableFilterMap && !isset($this->filterMap[$columnName])) {
|
||||
} else if ($this->enableFilterMap && ! isset($this->filterMap[$columnName])) {
|
||||
$collection->whereDate(
|
||||
$columnName,
|
||||
$this->operators[$condition],
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
|
||||
Vue.component("flash-wrapper", require("./components/flash-wrapper"));
|
||||
Vue.component("flash", require("./components/flash"));
|
||||
Vue.component("tabs", require("./components/tabs/tabs"));
|
||||
|
|
@ -18,6 +17,7 @@ Vue.directive("alert", require("./directives/alert"));
|
|||
Vue.component("datetime", require("./components/datetime"));
|
||||
Vue.component("date", require("./components/date"));
|
||||
Vue.component("swatch-picker", require("./components/swatch-picker"));
|
||||
Vue.directive("debounce", require("./directives/debounce"));
|
||||
|
||||
require('flatpickr/dist/flatpickr.css');
|
||||
|
||||
|
|
|
|||
|
|
@ -45,7 +45,7 @@
|
|||
computed: {
|
||||
iconClass() {
|
||||
return {
|
||||
'accordian-down-icon': !this.isActive,
|
||||
'accordian-down-icon': ! this.isActive,
|
||||
'accordian-up-icon': this.isActive,
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,12 @@
|
|||
module.exports = function debounce (fn, delay) {
|
||||
var timeoutID = null
|
||||
|
||||
return function () {
|
||||
clearTimeout(timeoutID)
|
||||
var args = arguments
|
||||
var that = this
|
||||
timeoutID = setTimeout(function () {
|
||||
fn.apply(that, args)
|
||||
}, delay)
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
<script>
|
||||
const debounce = require('../debounce')
|
||||
|
||||
export default {
|
||||
bind(el, binding, vnode) {
|
||||
if (binding.value !== binding.oldValue) {
|
||||
el.oninput = debounce(function (evt) {
|
||||
el.dispatchEvent(new Event('change'))
|
||||
}, parseInt(binding.value) || 500)
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
Loading…
Reference in New Issue