Merge pull request #1042 from bagisto/revert-1034-revert-1032-development
Revert "Revert "Development""
This commit is contained in:
commit
86c1b453ee
|
|
@ -1297,7 +1297,8 @@ class Cart {
|
|||
'id' => $item->id,
|
||||
'total' => $item->total,
|
||||
'base_total' => $leastValue,
|
||||
'quantity' => $item->quantity
|
||||
'quantity' => $item->quantity,
|
||||
'price' => $item->price
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -310,6 +310,8 @@ class Discount
|
|||
|
||||
\Cart::collectTotals();
|
||||
|
||||
$report['grand_total'] = core()->currency(\Cart::getCart()->grand_total);
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
@ -376,24 +378,36 @@ class Discount
|
|||
$leastWorthItem = \Cart::leastWorthItem();
|
||||
$realQty = $leastWorthItem['quantity'];
|
||||
|
||||
if ($cart->items_qty >= $disc_threshold && $realQty >= $disc_quantity) {
|
||||
if ($cart->items_qty >= $disc_threshold) {
|
||||
if ($action_type == config('pricerules.cart.validation.0')) {
|
||||
$amountDiscounted = $leastWorthItem['total'] * ($disc_amount / 100);
|
||||
$amountDiscounted = $leastWorthItem['price'] * ($disc_amount / 100);
|
||||
|
||||
if ($amountDiscounted > $leastWorthItem['total']) {
|
||||
$amountDiscounted = $leastWorthItem['total'];
|
||||
if ($realQty > $disc_quantity) {
|
||||
$amountDiscounted = $amountDiscounted * $disc_quantity;
|
||||
}
|
||||
|
||||
if ($amountDiscounted > $leastWorthItem['price']) {
|
||||
$amountDiscounted = $leastWorthItem['price'];
|
||||
}
|
||||
} else if ($action_type == config('pricerules.cart.validation.1')) {
|
||||
$amountDiscounted = $disc_amount;
|
||||
|
||||
if ($amountDiscounted > $leastWorthItem['total']) {
|
||||
$amountDiscounted = $leastWorthItem['total'];
|
||||
if ($realQty > $disc_quantity) {
|
||||
$amountDiscounted = $amountDiscounted * $disc_quantity;
|
||||
}
|
||||
|
||||
if ($amountDiscounted > $leastWorthItem['price']) {
|
||||
$amountDiscounted = $leastWorthItem['price'];
|
||||
}
|
||||
} else if ($action_type == config('pricerules.cart.validation.2')) {
|
||||
$amountDiscounted = $disc_amount;
|
||||
|
||||
if ($amountDiscounted > $leastWorthItem['total']) {
|
||||
$amountDiscounted = $leastWorthItem['total'];
|
||||
if ($realQty > $disc_quantity) {
|
||||
$amountDiscounted = $amountDiscounted * $disc_quantity;
|
||||
}
|
||||
|
||||
if ($amountDiscounted > $leastWorthItem['price']) {
|
||||
$amountDiscounted = $leastWorthItem['price'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -459,7 +473,6 @@ class Discount
|
|||
|
||||
if ($existingRule->count()) {
|
||||
if ($existingRule->first()->delete()) {
|
||||
|
||||
foreach ($cart->items as $item) {
|
||||
if ($item->discount_amount > 0) {
|
||||
$item->update([
|
||||
|
|
@ -477,6 +490,8 @@ class Discount
|
|||
'base_discount_amount' => 0
|
||||
]);
|
||||
|
||||
\Cart::collectTotals();
|
||||
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
|
|
|
|||
|
|
@ -305,12 +305,16 @@ class CartController extends Controller
|
|||
if ($result) {
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => trans('admin::app.promotion.status.coupon-removed')
|
||||
'message' => trans('admin::app.promotion.status.coupon-removed'),
|
||||
'data' => [
|
||||
'grand_total' => core()->currency(Cart::getCart()->grand_total)
|
||||
]
|
||||
]);
|
||||
} else {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => trans('admin::app.promotion.status.coupon-remove-failed')
|
||||
'message' => trans('admin::app.promotion.status.coupon-remove-failed'),
|
||||
'data' => null
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -538,7 +538,7 @@
|
|||
document.getElementById("discount-detail").style.display = "block";
|
||||
document.getElementById("discount-detail-discount-amount").innerHTML = response.data.result.formatted_discount;
|
||||
|
||||
document.getElementById("discount-detail-discount-amount").innerHTML = response.data.result.formatted_discount;
|
||||
document.getElementById("grand-total-amount-detail").innerHTML = response.data.result.grand_total;
|
||||
}).catch(function(error) {
|
||||
console.log(error.data);
|
||||
});
|
||||
|
|
@ -550,8 +550,14 @@
|
|||
axios.post('{{ route('shop.checkout.remove.coupon') }}')
|
||||
.then(function(response) {
|
||||
this_this.coupon_used = false;
|
||||
|
||||
this_this.code = '';
|
||||
|
||||
console.log(response.data.data.grand_total);
|
||||
|
||||
document.getElementById("discount-detail").style.display = "none";
|
||||
|
||||
document.getElementById("grand-total-amount-detail").innerHTML = response.data.data.grand_total;
|
||||
}).catch(function(error) {
|
||||
console.log(error.data);
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue