Made all changes for discount packages
This commit is contained in:
parent
2d0b26d78a
commit
795561ea58
|
|
@ -0,0 +1,86 @@
|
|||
<?php
|
||||
|
||||
namespace Webkul\Admin\DataGrids;
|
||||
|
||||
use Webkul\Ui\DataGrid\DataGrid;
|
||||
use DB;
|
||||
|
||||
/**
|
||||
* CartRuleCouponDataGrid class
|
||||
*
|
||||
* @author Jitendra Singh <jitendra@webkul.com>
|
||||
* @copyright 2018 Webkul Software Pvt Ltd (http://www.webkul.com)
|
||||
*/
|
||||
class CartRuleCouponDataGrid extends DataGrid
|
||||
{
|
||||
protected $index = 'id';
|
||||
|
||||
protected $sortOrder = 'desc';
|
||||
|
||||
public function prepareQueryBuilder()
|
||||
{
|
||||
$queryBuilder = DB::table('cart_rule_coupons')
|
||||
->addSelect('id', 'code', 'created_at', 'expired_at', 'times_used')
|
||||
->where('cart_rule_coupons.cart_rule_id', request('id'));
|
||||
|
||||
$this->setQueryBuilder($queryBuilder);
|
||||
}
|
||||
|
||||
public function addColumns()
|
||||
{
|
||||
$this->addColumn([
|
||||
'index' => 'id',
|
||||
'label' => trans('admin::app.datagrid.id'),
|
||||
'type' => 'number',
|
||||
'searchable' => false,
|
||||
'sortable' => true,
|
||||
'filterable' => true
|
||||
]);
|
||||
|
||||
$this->addColumn([
|
||||
'index' => 'code',
|
||||
'label' => trans('admin::app.datagrid.coupon-code'),
|
||||
'type' => 'string',
|
||||
'searchable' => true,
|
||||
'sortable' => true,
|
||||
'filterable' => true
|
||||
]);
|
||||
|
||||
$this->addColumn([
|
||||
'index' => 'created_at',
|
||||
'label' => trans('admin::app.datagrid.created-date'),
|
||||
'type' => 'datetime',
|
||||
'sortable' => true,
|
||||
'searchable' => false,
|
||||
'filterable' => true
|
||||
]);
|
||||
|
||||
$this->addColumn([
|
||||
'index' => 'expired_at',
|
||||
'label' => trans('admin::app.datagrid.expiration-date'),
|
||||
'type' => 'datetime',
|
||||
'sortable' => true,
|
||||
'searchable' => false,
|
||||
'filterable' => true
|
||||
]);
|
||||
|
||||
$this->addColumn([
|
||||
'index' => 'times_used',
|
||||
'label' => trans('admin::app.datagrid.times-used'),
|
||||
'type' => 'number',
|
||||
'searchable' => true,
|
||||
'sortable' => true,
|
||||
'filterable' => true
|
||||
]);
|
||||
}
|
||||
|
||||
public function prepareMassActions()
|
||||
{
|
||||
$this->addMassAction([
|
||||
'type' => 'delete',
|
||||
'action' => route('admin.cart-rule-coupons.mass-delete'),
|
||||
'label' => trans('admin::app.datagrid.delete'),
|
||||
'method' => 'DELETE'
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
|
@ -332,7 +332,13 @@
|
|||
|
||||
@if ($order->base_discount_amount > 0)
|
||||
<tr>
|
||||
<td>{{ __('admin::app.sales.orders.discount') }}</td>
|
||||
<td>
|
||||
{{ __('admin::app.sales.orders.discount') }}
|
||||
|
||||
@if ($order->coupon_code)
|
||||
({{ $order->coupon_code }})
|
||||
@endif
|
||||
</td>
|
||||
<td>-</td>
|
||||
<td>{{ core()->formatBasePrice($order->base_discount_amount) }}</td>
|
||||
</tr>
|
||||
|
|
|
|||
|
|
@ -380,6 +380,8 @@ class CartRule
|
|||
break;
|
||||
}
|
||||
|
||||
$selectedShipping->save();
|
||||
|
||||
$cartAppliedCartRuleIds = array_merge(explode(',', $cart->applied_cart_rule_ids), $appliedRuleIds);
|
||||
|
||||
$cartAppliedCartRuleIds = array_filter($cartAppliedCartRuleIds);
|
||||
|
|
|
|||
|
|
@ -2,6 +2,8 @@
|
|||
|
||||
namespace Webkul\CartRule\Listeners;
|
||||
|
||||
use Webkul\CartRule\Helpers\CartRule;
|
||||
|
||||
/**
|
||||
* Cart event handler
|
||||
*
|
||||
|
|
@ -10,5 +12,32 @@ namespace Webkul\CartRule\Listeners;
|
|||
*/
|
||||
class Cart
|
||||
{
|
||||
/**
|
||||
* CartRule object
|
||||
*
|
||||
* @var CartRule
|
||||
*/
|
||||
protected $cartRuleHepler;
|
||||
|
||||
/**
|
||||
* Create a new listener instance.
|
||||
*
|
||||
* @param Webkul\CartRule\Repositories\CartRule $cartRuleHepler
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(CartRule $cartRuleHepler)
|
||||
{
|
||||
$this->cartRuleHepler = $cartRuleHepler;
|
||||
}
|
||||
|
||||
/**
|
||||
* Aplly valid cart rules to cart
|
||||
*
|
||||
* @param Cart $cart
|
||||
* @return void
|
||||
*/
|
||||
public function applyCartRules($cart)
|
||||
{
|
||||
$this->cartRuleHepler->collect();
|
||||
}
|
||||
}
|
||||
|
|
@ -15,5 +15,7 @@ class EventServiceProvider extends ServiceProvider
|
|||
public function boot()
|
||||
{
|
||||
Event::listen('checkout.order.save.after', 'Webkul\CartRule\Listeners\Order@manageCartRule');
|
||||
|
||||
Event::listen('checkout.cart.collect.totals.before', 'Webkul\CartRule\Listeners\Cart@applyCartRules');
|
||||
}
|
||||
}
|
||||
|
|
@ -134,7 +134,7 @@ class CatalogRuleProduct
|
|||
return $qb;
|
||||
|
||||
foreach ($rule->conditions as $condition) {
|
||||
if (! $condition['attribute'] || ! $condition['value'])
|
||||
if (! $condition['attribute'] || ! isset($condition['value']) || is_null($condition['value']) || $condition['value'] == '')
|
||||
continue;
|
||||
|
||||
$chunks = explode('|', $condition['attribute']);
|
||||
|
|
@ -204,6 +204,7 @@ class CatalogRuleProduct
|
|||
->orderBy('channel_id', 'asc')
|
||||
->orderBy('customer_group_id', 'asc')
|
||||
->orderBy('product_id', 'asc')
|
||||
->orderBy('sort_order', 'asc')
|
||||
->orderBy('catalog_rule_id', 'asc');
|
||||
|
||||
if ($product) {
|
||||
|
|
|
|||
|
|
@ -12,8 +12,6 @@ class Cart extends Model implements CartContract
|
|||
|
||||
protected $guarded = ['id', 'created_at', 'updated_at'];
|
||||
|
||||
protected $hidden = ['coupon_code'];
|
||||
|
||||
protected $with = ['items', 'items.children'];
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -8,9 +8,6 @@ use Webkul\Shipping\Facades\Shipping;
|
|||
use Webkul\Payment\Facades\Payment;
|
||||
use Webkul\Checkout\Http\Requests\CustomerAddressForm;
|
||||
use Webkul\Sales\Repositories\OrderRepository;
|
||||
use Webkul\Discount\Helpers\Cart\CouponAbleRule as Coupon;
|
||||
use Webkul\Discount\Helpers\Cart\NonCouponAbleRule as NonCoupon;
|
||||
use Webkul\Discount\Helpers\Cart\ValidatesDiscount;
|
||||
use Webkul\Customer\Repositories\CustomerRepository;
|
||||
|
||||
/**
|
||||
|
|
@ -22,13 +19,6 @@ use Webkul\Customer\Repositories\CustomerRepository;
|
|||
*/
|
||||
class OnepageController extends Controller
|
||||
{
|
||||
/**
|
||||
* OrderRepository object
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $orderRepository;
|
||||
|
||||
/**
|
||||
* Contains route related configuration
|
||||
*
|
||||
|
|
@ -37,21 +27,11 @@ class OnepageController extends Controller
|
|||
protected $_config;
|
||||
|
||||
/**
|
||||
* CouponAbleRule instance object
|
||||
* OrderRepository object
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $coupon;
|
||||
|
||||
/**
|
||||
* NoncouponAbleRule instance object
|
||||
*
|
||||
*/
|
||||
protected $nonCoupon;
|
||||
|
||||
/**
|
||||
* ValidatesDiscount instance object
|
||||
*/
|
||||
protected $validatesDiscount;
|
||||
protected $orderRepository;
|
||||
|
||||
/**
|
||||
* customerRepository instance object
|
||||
|
|
@ -61,25 +41,17 @@ class OnepageController extends Controller
|
|||
/**
|
||||
* Create a new controller instance.
|
||||
*
|
||||
* @param \Webkul\Attribute\Repositories\OrderRepository $orderRepository
|
||||
* @param \Webkul\Attribute\Repositories\OrderRepository $orderRepository
|
||||
* @param \Webkul\Customer\Repositories\CustomerRepository $customerRepository
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(
|
||||
OrderRepository $orderRepository,
|
||||
Coupon $coupon,
|
||||
NonCoupon $nonCoupon,
|
||||
ValidatesDiscount $validatesDiscount,
|
||||
CustomerRepository $customerRepository
|
||||
)
|
||||
{
|
||||
$this->coupon = $coupon;
|
||||
|
||||
$this->nonCoupon = $nonCoupon;
|
||||
|
||||
$this->orderRepository = $orderRepository;
|
||||
|
||||
$this->validatesDiscount = $validatesDiscount;
|
||||
|
||||
$this->customerRepository = $customerRepository;
|
||||
|
||||
$this->_config = request('_config');
|
||||
|
|
@ -100,8 +72,6 @@ class OnepageController extends Controller
|
|||
if (! auth()->guard('customer')->check() && $cart->haveDownloadableItems())
|
||||
return redirect()->route('customer.session.index');
|
||||
|
||||
$this->nonCoupon->apply();
|
||||
|
||||
Cart::collectTotals();
|
||||
|
||||
return view($this->_config['view'], compact('cart'));
|
||||
|
|
@ -139,8 +109,6 @@ class OnepageController extends Controller
|
|||
} else {
|
||||
$cart = Cart::getCart();
|
||||
|
||||
$this->nonCoupon->apply();
|
||||
|
||||
Cart::collectTotals();
|
||||
|
||||
if ($cart->haveStockableItems()) {
|
||||
|
|
@ -166,8 +134,6 @@ class OnepageController extends Controller
|
|||
if (Cart::hasError() || !$shippingMethod || !Cart::saveShippingMethod($shippingMethod))
|
||||
return response()->json(['redirect_url' => route('shop.checkout.cart.index')], 403);
|
||||
|
||||
$this->nonCoupon->apply();
|
||||
|
||||
Cart::collectTotals();
|
||||
|
||||
return response()->json(Payment::getSupportedPaymentMethods());
|
||||
|
|
@ -185,8 +151,6 @@ class OnepageController extends Controller
|
|||
if (Cart::hasError() || ! $payment || ! Cart::savePaymentMethod($payment))
|
||||
return response()->json(['redirect_url' => route('shop.checkout.cart.index')], 403);
|
||||
|
||||
$this->nonCoupon->apply();
|
||||
|
||||
Cart::collectTotals();
|
||||
|
||||
$cart = Cart::getCart();
|
||||
|
|
@ -253,23 +217,53 @@ class OnepageController extends Controller
|
|||
{
|
||||
$cart = Cart::getCart();
|
||||
|
||||
$this->validatesDiscount->validate();
|
||||
|
||||
if ($cart->haveStockableItems() && ! $cart->shipping_address) {
|
||||
if ($cart->haveStockableItems() && ! $cart->shipping_address)
|
||||
throw new \Exception(trans('Please check shipping address.'));
|
||||
}
|
||||
|
||||
if (! $cart->billing_address) {
|
||||
if (! $cart->billing_address)
|
||||
throw new \Exception(trans('Please check billing address.'));
|
||||
}
|
||||
|
||||
if ($cart->haveStockableItems() && ! $cart->selected_shipping_rate) {
|
||||
if ($cart->haveStockableItems() && ! $cart->selected_shipping_rate)
|
||||
throw new \Exception(trans('Please specify shipping method.'));
|
||||
}
|
||||
|
||||
if (! $cart->payment) {
|
||||
if (! $cart->payment)
|
||||
throw new \Exception(trans('Please specify payment method.'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check Customer is exist or not
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function checkExistCustomer()
|
||||
{
|
||||
$customer = $this->customerRepository->findOneWhere([
|
||||
'email' => request()->email
|
||||
]);
|
||||
|
||||
if (! is_null($customer))
|
||||
return 'true';
|
||||
|
||||
return 'false';
|
||||
}
|
||||
|
||||
/**
|
||||
* Login for checkout
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function loginForCheckout()
|
||||
{
|
||||
$this->validate(request(), [
|
||||
'email' => 'required|email'
|
||||
]);
|
||||
|
||||
if (! auth()->guard('customer')->attempt(request(['email', 'password'])))
|
||||
return response()->json(['error' => trans('shop::app.customer.login-form.invalid-creds')]);
|
||||
|
||||
Cart::mergeCart();
|
||||
|
||||
return response()->json(['success' => 'Login successfully']);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -333,40 +327,4 @@ class OnepageController extends Controller
|
|||
], 422);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check Customer is exist or not
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function checkExistCustomer()
|
||||
{
|
||||
//check customer is exist or not
|
||||
$customer = $this->customerRepository->findOneWhere([
|
||||
'email' => request()->email
|
||||
]);
|
||||
|
||||
//if customer is exist
|
||||
if (! is_null($customer)) {
|
||||
return 'true';
|
||||
}
|
||||
return 'false';
|
||||
}
|
||||
|
||||
//login for checkout
|
||||
public function loginForCheckout()
|
||||
{
|
||||
$this->validate(request(), [
|
||||
'email' => 'required|email'
|
||||
]);
|
||||
|
||||
if (! auth()->guard('customer')->attempt(request(['email', 'password']))) {
|
||||
return response()->json(['error' => trans('shop::app.customer.login-form.invalid-creds')]);
|
||||
}
|
||||
|
||||
//Event passed to prepare cart after login
|
||||
Cart::mergeCart();
|
||||
|
||||
return response()->json(['success' => 'Login successfully']);
|
||||
}
|
||||
}
|
||||
|
|
@ -499,7 +499,8 @@ return [
|
|||
'free-desc' => 'This is a free shipping',
|
||||
'flat-desc' => 'This is a flat rate',
|
||||
'password' => 'Password',
|
||||
'login-exist-message' => 'You already have an account with us, Sign in or continue as guest.'
|
||||
'login-exist-message' => 'You already have an account with us, Sign in or continue as guest.',
|
||||
'enter-coupon-code' => 'Enter Coupon Code'
|
||||
],
|
||||
|
||||
'total' => [
|
||||
|
|
@ -513,9 +514,13 @@ return [
|
|||
'disc-amount' => 'Amount discounted',
|
||||
'new-grand-total' => 'New Grand Total',
|
||||
'coupon' => 'Coupon',
|
||||
'coupon-applied' => 'Coupon Applied',
|
||||
'coupon-applied' => 'Applied Coupon',
|
||||
'remove-coupon' => 'Remove Coupon',
|
||||
'cannot-apply-coupon' => 'Cannot Apply Coupon'
|
||||
'cannot-apply-coupon' => 'Cannot Apply Coupon',
|
||||
'invalid-coupon' => 'Coupon code is invalid.',
|
||||
'success-coupon' => 'Coupon code applied successfully.',
|
||||
'remove-coupon' => 'Coupon code removed successfully.',
|
||||
'coupon-apply-issue' => 'Coupon code can\'t be applied.'
|
||||
],
|
||||
|
||||
'success' => [
|
||||
|
|
|
|||
|
|
@ -127,6 +127,8 @@
|
|||
|
||||
@include('shop::checkout.total.summary', ['cart' => $cart])
|
||||
|
||||
<coupon-component></coupon-component>
|
||||
|
||||
{!! view_render_event('bagisto.shop.checkout.cart.summary.after', ['cart' => $cart]) !!}
|
||||
</div>
|
||||
</div>
|
||||
|
|
@ -155,6 +157,7 @@
|
|||
@endsection
|
||||
|
||||
@push('scripts')
|
||||
@include('shop::checkout.cart.coupon')
|
||||
|
||||
<script type="text/x-template" id="quantity-changer-template">
|
||||
<div class="quantity control-group" :class="[errors.has(controlName) ? 'has-error' : '']">
|
||||
|
|
|
|||
|
|
@ -9,6 +9,8 @@
|
|||
@endsection
|
||||
|
||||
@push('scripts')
|
||||
@include('shop::checkout.cart.coupon')
|
||||
|
||||
<script type="text/x-template" id="checkout-template">
|
||||
<div id="checkout" class="checkout-process">
|
||||
<div class="col-main">
|
||||
|
|
@ -76,12 +78,12 @@
|
|||
<div class="step-content review" v-show="current_step == 4" id="summary-section">
|
||||
<review-section v-if="current_step == 4" :key="reviewComponentKey">
|
||||
<div slot="summary-section">
|
||||
<summary-section
|
||||
discount="1"
|
||||
:key="summeryComponentKey"
|
||||
<summary-section :key="summeryComponentKey"></summary-section>
|
||||
|
||||
<coupon-component
|
||||
@onApplyCoupon="getOrderSummary"
|
||||
@onRemoveCoupon="getOrderSummary"
|
||||
></summary-section>
|
||||
@onRemoveCoupon="getOrderSummary">
|
||||
</coupon-component>
|
||||
</div>
|
||||
</review-section>
|
||||
|
||||
|
|
@ -563,25 +565,9 @@
|
|||
Vue.component('summary-section', {
|
||||
inject: ['$validator'],
|
||||
|
||||
props: {
|
||||
discount: {
|
||||
type: [String, Number],
|
||||
|
||||
default: 0,
|
||||
}
|
||||
},
|
||||
|
||||
data: function() {
|
||||
return {
|
||||
templateRender: null,
|
||||
|
||||
coupon_code: null,
|
||||
|
||||
error_message: null,
|
||||
|
||||
couponChanged: false,
|
||||
|
||||
changeCount: 0
|
||||
templateRender: null
|
||||
}
|
||||
},
|
||||
|
||||
|
|
@ -604,53 +590,6 @@
|
|||
this.templateRender() :
|
||||
'')
|
||||
]);
|
||||
},
|
||||
|
||||
methods: {
|
||||
onSubmit: function() {
|
||||
var this_this = this;
|
||||
const emptyCouponErrorText = "Please enter a coupon code";
|
||||
axios.post('{{ route('shop.checkout.check.coupons') }}', {code: this_this.coupon_code})
|
||||
.then(function(response) {
|
||||
this_this.$emit('onApplyCoupon');
|
||||
|
||||
this_this.couponChanged = true;
|
||||
})
|
||||
.catch(function(error) {
|
||||
this_this.couponChanged = true;
|
||||
|
||||
this_this.error_message = (error.response.data.message === "The given data was invalid.")?
|
||||
emptyCouponErrorText :
|
||||
(error.response.data.message === "Cannot Apply Coupon")?
|
||||
"Sorry, this Coupon code is invalid":error.response.data.message;
|
||||
});
|
||||
},
|
||||
|
||||
changeCoupon: function() {
|
||||
if (this.couponChanged == true && this.changeCount == 0) {
|
||||
this.changeCount++;
|
||||
|
||||
this.error_message = null;
|
||||
|
||||
this.couponChanged = false;
|
||||
} else {
|
||||
this.changeCount = 0;
|
||||
}
|
||||
},
|
||||
|
||||
removeCoupon: function () {
|
||||
var this_this = this;
|
||||
|
||||
axios.post('{{ route('shop.checkout.remove.coupon') }}')
|
||||
.then(function(response) {
|
||||
this_this.$emit('onRemoveCoupon')
|
||||
})
|
||||
.catch(function(error) {
|
||||
window.flashMessages = [{'type' : 'alert-error', 'message' : error.response.data.message}];
|
||||
|
||||
this_this.$root.addFlashMessages();
|
||||
});
|
||||
}
|
||||
}
|
||||
})
|
||||
</script>
|
||||
|
|
|
|||
|
|
@ -24,15 +24,12 @@
|
|||
</div>
|
||||
@endif
|
||||
|
||||
|
||||
<div class="item-detail" id="discount-detail" @if ($cart->base_discount_amount && $cart->base_discount_amount > 0) style="display: block;" @else style="display: none;" @endif>
|
||||
<label>
|
||||
<b>{{ __('shop::app.checkout.total.disc-amount') }}</b>
|
||||
{{ __('shop::app.checkout.total.disc-amount') }}
|
||||
</label>
|
||||
<label class="right">
|
||||
<b id="discount-detail-discount-amount">
|
||||
{{ core()->currency($cart->base_discount_amount) }}
|
||||
</b>
|
||||
-{{ core()->currency($cart->base_discount_amount) }}
|
||||
</label>
|
||||
</div>
|
||||
|
||||
|
|
@ -43,36 +40,4 @@
|
|||
{{ core()->currency($cart->base_grand_total) }}
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<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' : '']" style="margin-bottom: 10px">
|
||||
<input type="text" class="control" value="" v-model="coupon_code" name="code" placeholder="Enter Coupon Code" v-validate="'required'" style="width: 100%" @change="changeCoupon">
|
||||
</div>
|
||||
|
||||
<div class="control-error mb-10" v-if="error_message != null" style="color: #FF6472">* @{{ error_message }}</div>
|
||||
|
||||
<button class="btn btn-lg btn-black" :disabled="couponChanged">{{ __('shop::app.checkout.onepage.apply-coupon') }}</button>
|
||||
</form>
|
||||
</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;">
|
||||
<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>
|
||||
@endif
|
||||
@endif
|
||||
</div>
|
||||
</div>
|
||||
Loading…
Reference in New Issue