fixed bugs in discount helper
This commit is contained in:
commit
06f2216850
17
README.md
17
README.md
|
|
@ -12,10 +12,11 @@
|
|||
|
||||
# Topics
|
||||
1. ### [Introduction](#1-introduction-)
|
||||
2. ### [Requirements](#2-requirements-)
|
||||
3. ### [Installation & Configuration](#3-installation--configuration-)
|
||||
4. ### [License](#4-license-)
|
||||
5. ### [Miscellaneous](#user-content-6-miscellaneous--)
|
||||
2. ### [Documentation](#2-documentation-)
|
||||
3. ### [Requirements](#2-requirements-)
|
||||
4. ### [Installation & Configuration](#3-installation--configuration-)
|
||||
5. ### [License](#4-license-)
|
||||
6. ### [Miscellaneous](#5-miscellaneous-)
|
||||
|
||||
### 1. Introduction <a name="#1-introduction-"></a>:
|
||||
|
||||
|
|
@ -53,7 +54,11 @@ It packs in lots of demanding features that allows your business to scale in no
|
|||
Dev guys can take advantage of two of the hottest frameworks used in this project Laravel and Vue.js, both of these frameworks have been used in Bagisto.
|
||||
Bagisto is using power of both of these frameworks and making best out of it out of the box.
|
||||
|
||||
### 2. Requirements <a name="#requirements"></a>:
|
||||
### 2. Documentation <a name="#-documentation-"></a>:
|
||||
|
||||
# Visit our [Documentation](https://devdocs.bagisto.com)
|
||||
|
||||
### 3. Requirements <a name="#requirements"></a>:
|
||||
|
||||
* **OS**: Ubuntu 16.04 LTS or higher.
|
||||
* **SERVER**: Apache 2 or NGINX
|
||||
|
|
@ -65,7 +70,7 @@ Bagisto is using power of both of these frameworks and making best out of it out
|
|||
* **Node**: 8.11.3 LTS or higher.
|
||||
* **Composer**: 1.6.5 or higher.
|
||||
|
||||
### 3. Installation & Configuration <a name="#configuration"></a>:
|
||||
### 4. Installation & Configuration <a name="#configuration"></a>:
|
||||
|
||||
**1. Try our new GUI installer to install Bagisto:**
|
||||
|
||||
|
|
|
|||
|
|
@ -805,7 +805,7 @@ return [
|
|||
'uses-per-cust' => 'Uses per customer',
|
||||
'all' => 'All',
|
||||
'any' => 'Any',
|
||||
'end_other_rules' => 'End other rules',
|
||||
'end-other-rules' => 'End other rules',
|
||||
'status' => 'Is Active',
|
||||
'all-conditions-true' => 'Assuming all conditions are true',
|
||||
'assuming' => 'Assuming',
|
||||
|
|
|
|||
|
|
@ -301,9 +301,9 @@
|
|||
</div>
|
||||
|
||||
<div class="control-group" :class="[errors.has('end_other_rules') ? 'has-error' : '']">
|
||||
<label for="end_other_rules" class="required">{{ __('admin::app.promotion.general-info.is-guest') }}</label>
|
||||
<label for="end_other_rules" class="required">{{ __('admin::app.promotion.general-info.end-other-rules') }}</label>
|
||||
|
||||
<select type="text" class="control" name="end_other_rules" v-model="end_other_rules" v-validate="'required'" value="{{ old('end_other_rules')}}" data-vv-as=""{{ __('admin::app.promotion.general-info.is-guest') }}"">
|
||||
<select type="text" class="control" name="end_other_rules" v-model="end_other_rules" v-validate="'required'" value="{{ old('end_other_rules')}}" data-vv-as=""{{ __('admin::app.promotion.general-info.end-other-rules') }}"">
|
||||
<option value="1" :selected="end_other_rules == 1">{{ __('admin::app.promotion.general-info.is-coupon-yes') }}</option>
|
||||
<option value="0" :selected="end_other_rules == 0">{{ __('admin::app.promotion.general-info.is-coupon-no') }}</option>
|
||||
</select>
|
||||
|
|
|
|||
|
|
@ -893,7 +893,7 @@ class Cart {
|
|||
}
|
||||
|
||||
$item->update([
|
||||
'price' => $price,
|
||||
'price' => core()->convertPrice($price),
|
||||
'base_price' => $price,
|
||||
'total' => core()->convertPrice($price * ($item->quantity)),
|
||||
'base_total' => $price * ($item->quantity),
|
||||
|
|
@ -917,7 +917,7 @@ class Cart {
|
|||
}
|
||||
|
||||
$item->update([
|
||||
'price' => $price,
|
||||
'price' => core()->convertPrice($price),
|
||||
'base_price' => $price,
|
||||
'total' => core()->convertPrice($price * ($item->quantity)),
|
||||
'base_total' => $price * ($item->quantity),
|
||||
|
|
@ -1311,6 +1311,7 @@ class Cart {
|
|||
$leastValue = $item->price;
|
||||
$leastSubTotal = [
|
||||
'id' => $item->id,
|
||||
'total' => $item->total,
|
||||
'base_total' => $leastValue,
|
||||
'quantity' => $item->quantity
|
||||
];
|
||||
|
|
@ -1331,6 +1332,7 @@ class Cart {
|
|||
$maxValue = $item->total;
|
||||
$maxSubTotal = [
|
||||
'id' => $item->id,
|
||||
'total' => $item->total,
|
||||
'base_total' => $maxValue,
|
||||
'quantity' => $item->quantity
|
||||
];
|
||||
|
|
|
|||
|
|
@ -336,10 +336,10 @@ class Discount
|
|||
$result = $this->applyNonCouponAble();
|
||||
$cart = \Cart::getCart();
|
||||
$maxImpacts = array();
|
||||
// dd($result);
|
||||
|
||||
if (isset($result['id']) && count($result['id'])) {
|
||||
$rules = array();
|
||||
// dd(2);
|
||||
|
||||
if (count($result['id']) > 1) {
|
||||
$leastPriority = 999999999999;
|
||||
|
||||
|
|
@ -401,7 +401,7 @@ class Discount
|
|||
$disc_amount = $rule->disc_amount;
|
||||
$disc_quantity = $rule->disc_quantity;
|
||||
|
||||
$newBaseSubTotal = 0;
|
||||
$amountDiscounted = 0;
|
||||
$newQuantity = 0;
|
||||
|
||||
if ($cart->items_qty >= $disc_threshold && $disc_quantity > 0) {
|
||||
|
|
@ -414,22 +414,22 @@ class Discount
|
|||
|
||||
if ($action_type == config('pricerules.cart.validation.0')) {
|
||||
if ($realQty <= $disc_quantity) {
|
||||
$newBaseSubTotal = $cart->grand_total - ($leastWorthItem['base_total'] * ($disc_amount * $disc_quantity)) / 100;
|
||||
$amountDiscounted = (($leastWorthItem['total'] / $realQty) * ($disc_amount / 100)) * $disc_quantity;
|
||||
} else {
|
||||
$newBaseSubTotal = $cart->grand_total - ($leastWorthItem['base_total'] * $disc_amount) / 100;
|
||||
$amountDiscounted = ($leastWorthItem['total'] / $realQty) * ($disc_amount / 100);
|
||||
}
|
||||
} else if ($action_type == config('pricerules.cart.validation.1')) {
|
||||
if ($realQty <= $disc_quantity) {
|
||||
if ($disc_amount > ($disc_quantity * $leastWorthItem['base_total'])) {
|
||||
$newBaseSubTotal = 0;
|
||||
if ($disc_amount > ($disc_quantity * $leastWorthItem['total'])) {
|
||||
$amountDiscounted = 0;
|
||||
} else {
|
||||
$newBaseSubTotal = $cart->grand_total - $disc_amount;
|
||||
$amountDiscounted = $cart->sub_total - $disc_amount;
|
||||
}
|
||||
} else {
|
||||
if ($disc_amount > $leastWorthItem['base_total']) {
|
||||
$newBaseSubTotal = 0;
|
||||
if ($disc_amount > $leastWorthItem['total']) {
|
||||
$amountDiscounted = 0;
|
||||
} else {
|
||||
$newBaseSubTotal = $cart->grand_total - $disc_amount;
|
||||
$amountDiscounted = $cart->sub_total - $disc_amount;
|
||||
}
|
||||
}
|
||||
} else if ($action_type == config('pricerules.cart.validation.2')) {
|
||||
|
|
@ -439,7 +439,7 @@ class Discount
|
|||
$newQuantity = $this->cartItem->find($leastWorthItem['id'])->quantity + $disc_quantity;
|
||||
}
|
||||
} else if ($action_type == config('pricerules.cart.validation.3')) {
|
||||
$newBaseSubTotal = $disc_amount;
|
||||
$amountDiscounted = $disc_amount;
|
||||
}
|
||||
|
||||
//standard returns
|
||||
|
|
@ -458,7 +458,7 @@ class Discount
|
|||
'rule' => $rule,
|
||||
'item_id' => $leastWorthItem['id'],
|
||||
'amount_given' => true,
|
||||
'amount' => $newBaseSubTotal,
|
||||
'amount' => $amountDiscounted,
|
||||
'action_type' => $action_type
|
||||
]);
|
||||
}
|
||||
|
|
@ -506,7 +506,7 @@ class Discount
|
|||
]);
|
||||
}
|
||||
|
||||
return ['rule' => $maxImpacts[$leastId]['rule'], 'impact' => $maxImpacts[$leastId], 'endRuleActive' => $this->endRuleActive, 'success' => true];
|
||||
return ['rule' => $maxImpacts[$leastId]['rule'], 'impact' => $maxImpacts[$leastId], 'success' => true];
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -585,7 +585,7 @@ class Discount
|
|||
$disc_amount = $rule->disc_amount;
|
||||
$disc_quantity = $rule->disc_quantity;
|
||||
|
||||
$newBaseSubTotal = 0;
|
||||
$amountDiscounted = 0;
|
||||
$newQuantity = 0;
|
||||
|
||||
if ($cart->items_qty >= $disc_threshold && $disc_quantity > 0) {
|
||||
|
|
@ -598,22 +598,22 @@ class Discount
|
|||
|
||||
if ($action_type == config('pricerules.cart.validation.0')) {
|
||||
if ($realQty <= $disc_quantity) {
|
||||
$newBaseSubTotal = $cart->grand_total - ($leastWorthItem['base_total'] * ($disc_amount * $disc_quantity)) / 100;
|
||||
$amountDiscounted = (($leastWorthItem['total'] / $realQty) * ($disc_amount / 100)) * $disc_quantity;
|
||||
} else {
|
||||
$newBaseSubTotal = $cart->grand_total - ($leastWorthItem['base_total'] * $disc_amount) / 100;
|
||||
$amountDiscounted = ($leastWorthItem['total'] / $realQty) * ($disc_amount / 100);
|
||||
}
|
||||
} else if ($action_type == config('pricerules.cart.validation.1')) {
|
||||
if ($realQty <= $disc_quantity) {
|
||||
if ($disc_amount > ($disc_quantity * $leastWorthItem['base_total'])) {
|
||||
$newBaseSubTotal = 0;
|
||||
if ($disc_amount > ($disc_quantity * $leastWorthItem['total'])) {
|
||||
$amountDiscounted = 0;
|
||||
} else {
|
||||
$newBaseSubTotal = $cart->grand_total - $disc_amount;
|
||||
$amountDiscounted = $cart->sub_total - $disc_amount;
|
||||
}
|
||||
} else {
|
||||
if ($disc_amount > $leastWorthItem['base_total']) {
|
||||
$newBaseSubTotal = 0;
|
||||
if ($disc_amount > $leastWorthItem['total']) {
|
||||
$amountDiscounted = 0;
|
||||
} else {
|
||||
$newBaseSubTotal = $cart->grand_total - $disc_amount;
|
||||
$amountDiscounted = $cart->sub_total - $disc_amount;
|
||||
}
|
||||
}
|
||||
} else if ($action_type == config('pricerules.cart.validation.2')) {
|
||||
|
|
@ -623,7 +623,7 @@ class Discount
|
|||
$newQuantity = $this->cartItem->find($leastWorthItem['id'])->quantity + $disc_quantity;
|
||||
}
|
||||
} else if ($action_type == config('pricerules.cart.validation.3')) {
|
||||
$newBaseSubTotal = $disc_amount;
|
||||
$amountDiscounted = $disc_amount;
|
||||
}
|
||||
|
||||
if ($action_type == config('pricerules.cart.validation.2')) {
|
||||
|
|
@ -669,16 +669,21 @@ class Discount
|
|||
}
|
||||
|
||||
return response()->json([
|
||||
'id' => $appliedRule->id,
|
||||
'rule' => $appliedRule,
|
||||
'item_id' => $leastWorthItem['id'],
|
||||
'message' => trans('admin::app.promotion.status.coupon-applied'),
|
||||
'action' => $action_type,
|
||||
'amount_given' => true,
|
||||
'amount_payable' => core()->currency($newBaseSubTotal + $cart->tax_total),
|
||||
'amount' => core()->currency($cart->grand_total - $newBaseSubTotal),
|
||||
'amount' => $amountDiscounted,
|
||||
'action_type' => $action_type,
|
||||
'success' => true
|
||||
]);
|
||||
}
|
||||
} else {
|
||||
return response()->json([
|
||||
'id' => null,
|
||||
'rule' => null,
|
||||
'item_id' => null,
|
||||
'message' => trans('admin::app.promotion.status.coupon-failed'),
|
||||
'action' => $action_type,
|
||||
'amount_given' => null,
|
||||
|
|
@ -689,6 +694,9 @@ class Discount
|
|||
}
|
||||
} else {
|
||||
return response()->json([
|
||||
'id' => null,
|
||||
'rule' => null,
|
||||
'item_id' => null,
|
||||
'message' => trans('admin::app.promotion.status.coupon-failed'),
|
||||
'action' => null,
|
||||
'amount_given' => null,
|
||||
|
|
@ -771,20 +779,16 @@ class Discount
|
|||
break;
|
||||
}
|
||||
} else if ($test_condition == '()') {
|
||||
// dd($test_condition);
|
||||
} else if ($test_condition == '!()') {
|
||||
// dd($test_condition);
|
||||
}
|
||||
}
|
||||
// else if ($condition->type == 'boolean') {
|
||||
// if ($test_conditions[$condition->type][$test_condition]) {
|
||||
// if ($test_condition == 0) {
|
||||
// dd($test_condition);
|
||||
// } else if ($test_condition == 1) {
|
||||
// dd($test_condition);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// else if ($condition->type == 'boolean') {
|
||||
// if ($test_conditions[$condition->type][$test_condition]) {
|
||||
// if ($test_condition == 0) {
|
||||
// } else if ($test_condition == 1) {
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -96,8 +96,6 @@ class CartRuleController extends Controller
|
|||
|
||||
public function store()
|
||||
{
|
||||
// dd(request()->all()); // required_if:use_coupon,1
|
||||
$types = config('price_rules.cart.validations');
|
||||
$data = request()->all();
|
||||
|
||||
$validated = Validator::make($data, [
|
||||
|
|
@ -171,6 +169,7 @@ class CartRuleController extends Controller
|
|||
$data['conditions'] = null;
|
||||
} else {
|
||||
$data['conditions'] = json_encode($data['all_conditions']);
|
||||
unset($data['all_conditions']);
|
||||
}
|
||||
|
||||
if ($data['use_coupon']) {
|
||||
|
|
@ -378,12 +377,12 @@ class CartRuleController extends Controller
|
|||
$coupons['cart_rule_id'] = $ruleUpdated->id;
|
||||
$coupons['usage_per_customer'] = $data['per_customer']; //0 is for unlimited usage
|
||||
|
||||
$couponUpdated = $this->cartRuleCoupon->create($coupons);
|
||||
$couponUpdated = $ruleUpdated->coupons->update($coupons);
|
||||
}
|
||||
|
||||
if ($ruleUpdated && $ruleGroupUpdated && $ruleChannelUpdated) {
|
||||
if (isset($couponUpdated) && $couponUpdated) {
|
||||
session()->flash('success', trans('admin::app.promotion.status.success-coupon'));
|
||||
session()->flash('info', trans('admin::app.promotion.status.success-coupon'));
|
||||
}
|
||||
|
||||
session()->flash('info', trans('admin::app.promotion.status.update-success'));
|
||||
|
|
|
|||
|
|
@ -5,6 +5,8 @@ namespace Webkul\Discount\Repositories;
|
|||
use Webkul\Core\Eloquent\Repository;
|
||||
use Webkul\Discount\Repositories\CartRuleChannelsRepository as CartRuleChannels;
|
||||
use Webkul\Discount\Repositories\CartRuleCustomerGroupsRepository as CartRuleCustomerGroups;
|
||||
use Webkul\Discount\Repositories\CartRuleCouponsRepository as CartRuleCoupons;
|
||||
use Webkul\Discount\Repositories\CartRuleLabelsRepository as CartRuleLabels;
|
||||
use Illuminate\Container\Container as App;
|
||||
|
||||
/**
|
||||
|
|
@ -19,13 +21,19 @@ class CartRuleRepository extends Repository
|
|||
|
||||
protected $cartRuleCustomerGroups;
|
||||
|
||||
protected $cartRuleCoupons;
|
||||
|
||||
protected $cartRuleLabels;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function __construct(CartRuleChannels $cartRuleChannels, CartRuleCustomerGroups $cartRuleCustomerGroups, App $app)
|
||||
public function __construct(CartRuleChannels $cartRuleChannels, CartRuleCustomerGroups $cartRuleCustomerGroups, CartRuleCoupons $cartRuleCoupons, CartRuleLabels $cartRuleLabels, App $app)
|
||||
{
|
||||
$this->cartRuleChannels = $cartRuleChannels;
|
||||
$this->cartRuleCustomerGroups = $cartRuleCustomerGroups;
|
||||
$this->cartRuleCoupons = $cartRuleCoupons;
|
||||
$this->cartRuleLabels = $cartRuleLabels;
|
||||
|
||||
parent::__construct($app);
|
||||
}
|
||||
|
|
@ -135,8 +143,19 @@ class CartRuleRepository extends Repository
|
|||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* To sync the labels associated with the cart rule
|
||||
*/
|
||||
public function LabelsSync($labels, $cartRule)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* To sync the coupons associated with the cart rule
|
||||
*/
|
||||
public function CouponsSync($coupon, $cartRule)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -127,6 +127,7 @@ class OnepageController extends Controller
|
|||
$cart = Cart::getCart();
|
||||
|
||||
$rule = Cart::applyNonCoupon();
|
||||
// dd($rule);
|
||||
|
||||
return response()->json([
|
||||
'jump_to_section' => 'review',
|
||||
|
|
|
|||
|
|
@ -49,7 +49,7 @@
|
|||
</form>
|
||||
|
||||
@if(isset($rule))
|
||||
{{-- <div class="discounted">
|
||||
<div class="discounted">
|
||||
<div class="mt-15 mb-10">
|
||||
{{ $rule['rule']->name }} {{ __('shop::app.checkout.onepage.applied') }}
|
||||
</div>
|
||||
|
|
@ -58,44 +58,22 @@
|
|||
@if ($rule['impact']['amount_given'])
|
||||
<label style="float: left;">{{ __('shop::app.checkout.onepage.amt-payable') }}</label>
|
||||
|
||||
<label style="float: right;">{{ core()->currency($cart->tax_total + $rule['impact']['amount']) }}</label>
|
||||
<label style="float: right;">{{ core()->currency($cart->grand_total - $rule['impact']['amount']) }}</label>
|
||||
@else
|
||||
<label style="float: left;">{{ __('shop::app.checkout.onepage.got') }}</label>
|
||||
<label style="float: right;">{{ $rule['impact']['amount'] }} {{ __('shop::app.checkout.onepage.got') }}</label>
|
||||
@endif
|
||||
</span>
|
||||
</div> --}}
|
||||
@else
|
||||
{{-- {{dd('2')}} --}}
|
||||
{{-- <div class="discounted" v-if="discounted">
|
||||
<div class="mt-15 mb-10">
|
||||
@{{ code }} {{ __('shop::app.checkout.onepage.applied') }}
|
||||
</div>
|
||||
|
||||
<span class="payble-amount row mt-10">
|
||||
<label style="float: left;">{{ __('shop::app.checkout.onepage.amt-payable') }}</label>
|
||||
|
||||
<label style="float: right;">@{{ discount.amount }}</label>
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<div class="discounted" v-if="!discounted">
|
||||
<div class="mt-15 mb-10">
|
||||
<b>{{ __('shop::app.checkout.onepage.coupon-used') }}</b>
|
||||
</div>
|
||||
|
||||
<span class="row mb-10">
|
||||
<label style="float: left;">@{{ code }}</label>
|
||||
<label style="float: right;">@{{ discount.amount_given }}</label>
|
||||
</span>
|
||||
|
||||
<span class="payble-amount row mt-10">
|
||||
<label style="float: left;">{{ __('shop::app.checkout.onepage.amt-payable') }}</label>
|
||||
<label style="float: right;">@{{ discount.amount }}</label>
|
||||
</span>
|
||||
</div> --}}
|
||||
@endif
|
||||
@endif
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@push('scripts')
|
||||
<script type="text/x-template" id="discount-template">
|
||||
<div id="discount">
|
||||
|
||||
</div>
|
||||
</script>
|
||||
@endpush
|
||||
Loading…
Reference in New Issue