added the table for cart rule cart for managing rules with cart and removed various bug fixes
This commit is contained in:
parent
26270979fd
commit
33774c4c46
|
|
@ -15,7 +15,7 @@
|
|||
2. ### [Requirements](#2-requirements-)
|
||||
3. ### [Installation & Configuration](#3-installation--configuration-)
|
||||
4. ### [License](#4-license-)
|
||||
5. ### [Miscellaneous](#5-miscellaneous-)
|
||||
5. ### [Miscellaneous](#user-content-6-miscellaneous--)
|
||||
|
||||
### 1. Introduction <a name="#1-introduction-"></a>:
|
||||
|
||||
|
|
@ -26,6 +26,8 @@ a progressive Javascript framework.
|
|||
**Bagisto is viable attempt to cut down your time, cost and workforce for building online stores or migrating from physical stores
|
||||
to the ever demanding online world. Your business whether small or huge it suits all and very simple to set it up.**
|
||||
|
||||
**Read our documentation: [Bagisto Docs](https://devdocs.bagisto.com/)**
|
||||
|
||||
**We are also having a forum for any type of your concern, feature request discussions. Please visit: [Bagisto Forums](https://forums.bagisto.com/)**
|
||||
|
||||
# Visit our live [Demo](https://demo.bagisto.com)
|
||||
|
|
|
|||
|
|
@ -1092,6 +1092,59 @@ 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
|
||||
*
|
||||
|
|
|
|||
|
|
@ -85,10 +85,10 @@ return [
|
|||
'<=' => 'Lesser or equals',
|
||||
'>' => 'Greater than',
|
||||
'<' => 'Lesser than',
|
||||
'{}' => 'Contains',
|
||||
'!{}' => 'Does not contains',
|
||||
'()' => 'Is one of',
|
||||
'!()' => 'Not is one of'
|
||||
'{}' => 'Contains'
|
||||
// '!{}' => 'Does not contains',
|
||||
// '()' => 'Is one of',
|
||||
// '!()' => 'Not is one of'
|
||||
],
|
||||
|
||||
'text' => [
|
||||
|
|
@ -98,9 +98,9 @@ return [
|
|||
'>' => 'Greater than',
|
||||
'<' => 'Lesser than',
|
||||
'{}' => 'Contains',
|
||||
'!{}' => 'Does not contains',
|
||||
'()' => 'Is one of',
|
||||
'!()' => 'Not is one of'
|
||||
'!{}' => 'Does not contains'
|
||||
// '()' => 'Is one of',
|
||||
// '!()' => 'Not is one of'
|
||||
],
|
||||
|
||||
'string' => [
|
||||
|
|
@ -110,14 +110,14 @@ return [
|
|||
'>' => 'Greater than',
|
||||
'<' => 'Lesser than',
|
||||
'{}' => 'Contains',
|
||||
'!{}' => 'Does not contains',
|
||||
'()' => 'Is one of',
|
||||
'!()' => 'Not is one of'
|
||||
'!{}' => 'Does not contains'
|
||||
// '()' => 'Is one of',
|
||||
// '!()' => 'Not is one of'
|
||||
],
|
||||
|
||||
'boolean' => [
|
||||
0 => 'True/Yes',
|
||||
1 => 'False/No',
|
||||
1 => 'False/No'
|
||||
]
|
||||
],
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,7 @@
|
|||
<?php
|
||||
|
||||
namespace Webkul\Discount\Contracts;
|
||||
|
||||
interface CartRuleCart
|
||||
{
|
||||
}
|
||||
|
|
@ -1,52 +0,0 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class CreateCatalogRulesTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::dropIfExists('discount_customer_group');
|
||||
Schema::dropIfExists('discount_channels');
|
||||
Schema::dropIfExists('discount_rules');
|
||||
Schema::dropIfExists('discounts');
|
||||
Schema::dropIfExists('products_grid');
|
||||
|
||||
Schema::create('catalog_rules', function (Blueprint $table) {
|
||||
$table->increments('id');
|
||||
$table->string('name')->nullable();
|
||||
$table->string('description')->nullable();
|
||||
$table->boolean('is_guest')->default(0);
|
||||
$table->datetime('starts_from')->nullable();
|
||||
$table->datetime('ends_till')->nullable();
|
||||
$table->boolean('status')->default(0);
|
||||
$table->integer('priority')->unsigned()->default(0);
|
||||
$table->json('conditions')->nullable();
|
||||
$table->string('test_mode')->nullable();
|
||||
$table->json('actions')->nullable();
|
||||
$table->boolean('end_other_rules')->default(0);
|
||||
$table->integer('sort_order')->unsigned()->default(0);
|
||||
$table->string('action_type')->nullable();
|
||||
$table->decimal('disc_amount', 12, 4)->default(0);
|
||||
$table->decimal('disc_percent', 12, 4)->default(0);
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::dropIfExists('catalog_rules');
|
||||
}
|
||||
}
|
||||
|
|
@ -1,38 +0,0 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class CreateCatalogRuleProductsTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create('catalog_rule_products', function (Blueprint $table) {
|
||||
$table->increments('id');
|
||||
$table->integer('catalog_rule_id')->unsigned()->unique();
|
||||
$table->foreign('catalog_rule_id')->references('id')->on('catalog_rules')->onDelete('cascade');
|
||||
$table->integer('product_id')->unsigned();
|
||||
$table->foreign('product_id')->references('id')->on('products')->onDelete('cascade');
|
||||
$table->string('act_operator')->default('fixed');
|
||||
$table->decimal('act_amount', 12, 4)->default(0.0000);
|
||||
$table->unsignedSmallInteger('act_stop')->default(0);
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::dropIfExists('catalog_products');
|
||||
}
|
||||
}
|
||||
|
|
@ -1,35 +0,0 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class CreateCatalogRuleCustomerGroupsTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create('catalog_rule_customer_groups', function (Blueprint $table) {
|
||||
$table->increments('id');
|
||||
$table->integer('catalog_rule_id')->unsigned();
|
||||
$table->foreign('catalog_rule_id')->references('id')->on('catalog_rules')->onDelete('cascade');
|
||||
$table->integer('customer_group_id')->unsigned();
|
||||
$table->foreign('customer_group_id')->references('id')->on('customer_groups')->onDelete('cascade');
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::dropIfExists('catalog_rule_customer_groups');
|
||||
}
|
||||
}
|
||||
|
|
@ -1,35 +0,0 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class CreateCatalogRuleChannelsTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create('catalog_rule_channels', function (Blueprint $table) {
|
||||
$table->increments('id');
|
||||
$table->integer('catalog_rule_id')->unsigned();
|
||||
$table->foreign('catalog_rule_id')->references('id')->on('catalog_rules')->onDelete('cascade');
|
||||
$table->integer('channel_id')->unsigned();
|
||||
$table->foreign('channel_id')->references('id')->on('channels')->onDelete('cascade');
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::dropIfExists('catalog_rule_channels');
|
||||
}
|
||||
}
|
||||
|
|
@ -1,36 +0,0 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class CreateCatalogRuleProductsPriceTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create('catalog_rule_products_price', function (Blueprint $table) {
|
||||
$table->increments('id');
|
||||
$table->integer('cart_rule_product_id')->unsigned();
|
||||
$table->foreign('cart_rule_product_id')->references('id')->on('cart_rules')->onDelete('cascade');
|
||||
$table->datetime('starts_from')->nullable();
|
||||
$table->datetime('ends_till')->nullable();
|
||||
$table->decimal('price', 12, 4)->default(0.0000);
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::dropIfExists('cart_rule_products_price');
|
||||
}
|
||||
}
|
||||
|
|
@ -20,7 +20,7 @@ class CreateCartruleCouponsTable extends Migration
|
|||
$table->string('prefix')->nullable();
|
||||
$table->string('suffix')->nullable();
|
||||
$table->string('code')->nullable();
|
||||
$table->integer('limit')->unsigned()->default(0);
|
||||
$table->integer('usage_limit')->unsigned()->default(0);
|
||||
$table->integer('usage_per_customer')->unsigned()->default(0);
|
||||
$table->integer('usage_throttle')->unsigned()->default(0);
|
||||
$table->integer('type')->unsigned()->default(0);
|
||||
|
|
|
|||
|
|
@ -19,6 +19,8 @@ class CreateCartRuleCouponsUsageTable extends Migration
|
|||
$table->foreign('coupon_id')->references('id')->on('cart_rules')->onDelete('cascade');
|
||||
$table->integer('channel_id')->unsigned();
|
||||
$table->foreign('channel_id')->references('id')->on('channels')->onDelete('cascade');
|
||||
$table->integer('customer_id')->unsigned();
|
||||
$table->foreign('customer_id')->references('id')->on('customers')->onDelete('cascade');
|
||||
$table->bigInteger('usage')->unsigned()->default(0);
|
||||
$table->date('expired_on');
|
||||
$table->timestamps();
|
||||
|
|
|
|||
|
|
@ -0,0 +1,35 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class CreateCartRuleCartTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create('cart_rule_cart', function (Blueprint $table) {
|
||||
$table->increments('id');
|
||||
$table->integer('cart_rule_id')->unsigned()->nullable();
|
||||
$table->foreign('cart_rule_id')->references('id')->on('cart_rules')->onDelete('cascade');
|
||||
$table->integer('cart_id')->unsigned()->nullable();
|
||||
$table->foreign('cart_id')->references('id')->on('cart')->onDelete('cascade');
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::dropIfExists('cart_rule_order');
|
||||
}
|
||||
}
|
||||
|
|
@ -3,8 +3,10 @@
|
|||
namespace Webkul\Discount\Helpers;
|
||||
|
||||
use Webkul\Discount\Repositories\CartRuleRepository as CartRule;
|
||||
use Webkul\Discount\Repositories\CartRuleCartRepository as CartRuleCart;
|
||||
use Carbon\Carbon;
|
||||
|
||||
|
||||
class Discount
|
||||
{
|
||||
/**
|
||||
|
|
@ -12,15 +14,26 @@ class Discount
|
|||
*/
|
||||
protected $cartRule;
|
||||
|
||||
/**
|
||||
* To hold the cart rule cart repository instance
|
||||
*/
|
||||
protected $cartRuleCart;
|
||||
|
||||
/**
|
||||
* To hold if end rules are present or not.
|
||||
*/
|
||||
protected $endRuleActive;
|
||||
protected $endRuleActive = false;
|
||||
|
||||
public function __construct(CartRule $cartRule)
|
||||
/**
|
||||
* disable coupon
|
||||
*/
|
||||
protected $disableCoupon = false;
|
||||
|
||||
public function __construct(CartRule $cartRule, CartRuleCart $cartRuleCart)
|
||||
{
|
||||
$this->cartRule = $cartRule;
|
||||
$this->endRuleActive = false;
|
||||
$this->cartRuleCart = $cartRuleCart;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -222,12 +235,14 @@ class Discount
|
|||
if (count($id)) {
|
||||
return [
|
||||
'couponable' => true,
|
||||
'id' => $id
|
||||
'id' => $id,
|
||||
'end_rule' => true
|
||||
];
|
||||
} else {
|
||||
return [
|
||||
'couponable' => false,
|
||||
'id' => null
|
||||
'id' => null,
|
||||
'end_rule' => null
|
||||
];
|
||||
}
|
||||
} else {
|
||||
|
|
@ -243,12 +258,14 @@ class Discount
|
|||
if (count($id)) {
|
||||
return [
|
||||
'couponable' => true,
|
||||
'id' => $id
|
||||
'id' => $id,
|
||||
'end_rule' => false
|
||||
];
|
||||
} else {
|
||||
return [
|
||||
'couponable' => false,
|
||||
'id' => null
|
||||
'id' => null,
|
||||
'end_rule' => false
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
@ -275,13 +292,15 @@ class Discount
|
|||
return [
|
||||
'end_rule' => false,
|
||||
'noncouponable' => true,
|
||||
'id' => $id
|
||||
'id' => $id,
|
||||
'end_rule' => false
|
||||
];
|
||||
} else {
|
||||
return [
|
||||
'end_rule' => false,
|
||||
'noncouponable' => false,
|
||||
'id' => null
|
||||
'id' => null,
|
||||
'end_rule' => false
|
||||
];
|
||||
}
|
||||
} else {
|
||||
|
|
@ -299,13 +318,15 @@ class Discount
|
|||
return [
|
||||
'end_rule' => true,
|
||||
'noncouponable' => true,
|
||||
'id' => $id
|
||||
'id' => $id,
|
||||
'end_rule' => true
|
||||
];
|
||||
} else {
|
||||
return [
|
||||
'end_rule' => true,
|
||||
'noncouponable' => false,
|
||||
'id' => null
|
||||
'id' => null,
|
||||
'end_rule' => null
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
@ -315,13 +336,6 @@ class Discount
|
|||
{
|
||||
$result = $this->applyNonCouponAble();
|
||||
$cart = \Cart::getCart();
|
||||
|
||||
if ($result['end_rule']) {
|
||||
$this->endRuleActive = true;
|
||||
} else {
|
||||
$this->endRuleActive = false;
|
||||
}
|
||||
|
||||
$maxImpacts = array();
|
||||
|
||||
if (isset($result['id']) && count($result['id'])) {
|
||||
|
|
@ -398,15 +412,31 @@ class Discount
|
|||
$realQty = $leastWorthItem['quantity'];
|
||||
|
||||
if ($action_type == config('pricerules.cart.validation.0')) {
|
||||
$newBaseSubTotal = $cart->grand_total - ($leastWorthItem['base_total'] * $disc_amount) / 100;
|
||||
} else if ($action_type == config('pricerules.cart.validation.1')) {
|
||||
if ($disc_amount > ($disc_quantity * $leastWorthItem['base_total'])) {
|
||||
$newBaseSubTotal = 0;
|
||||
if ($realQty <= $disc_quantity) {
|
||||
$newBaseSubTotal = $cart->grand_total - ($leastWorthItem['base_total'] * ($disc_amount * $disc_quantity)) / 100;
|
||||
} else {
|
||||
$newBaseSubTotal = $cart->grand_total - $disc_amount;
|
||||
$newBaseSubTotal = $cart->grand_total - ($leastWorthItem['base_total'] * $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;
|
||||
} else {
|
||||
$newBaseSubTotal = $cart->grand_total - $disc_amount;
|
||||
}
|
||||
} else {
|
||||
if ($disc_amount > $leastWorthItem['base_total']) {
|
||||
$newBaseSubTotal = 0;
|
||||
} else {
|
||||
$newBaseSubTotal = $cart->grand_total - $disc_amount;
|
||||
}
|
||||
}
|
||||
} else if ($action_type == config('pricerules.cart.validation.2')) {
|
||||
$newQuantity = $this->cartItem->find($leastWorthItem['id'])->quantity + $disc_amount;
|
||||
if ($realQty <= $disc_quantity) {
|
||||
$newQuantity = $this->cartItem->find($leastWorthItem['id'])->quantity + $disc_amount;
|
||||
} else {
|
||||
$newQuantity = $this->cartItem->find($leastWorthItem['id'])->quantity + $disc_quantity;
|
||||
}
|
||||
} else if ($action_type == config('pricerules.cart.validation.3')) {
|
||||
$newBaseSubTotal = $disc_amount;
|
||||
}
|
||||
|
|
@ -459,7 +489,23 @@ class Discount
|
|||
}
|
||||
|
||||
if ($leastId != -1) {
|
||||
return $maxImpacts[$leastId];
|
||||
$cartRuleCart = $this->cartRuleCart->findWhere([
|
||||
'cart_id' => $cart->id,
|
||||
]);
|
||||
|
||||
if (count($cartRuleCart)) {
|
||||
$this->cartRuleCart->update([
|
||||
'cart_id' => $cart->id,
|
||||
'cart_rule_id' => $maxImpacts[$leastId]['rule']->id
|
||||
], $cartRuleCart->first()->id);
|
||||
} else {
|
||||
$this->cartRuleCart->create([
|
||||
'cart_id' => $cart->id,
|
||||
'cart_rule_id' => $maxImpacts[$leastId]['rule']->id
|
||||
]);
|
||||
}
|
||||
|
||||
return ['rule' => $maxImpacts[$leastId]['rule'], 'impact' => $maxImpacts[$leastId], 'endRuleActive' => $this->endRuleActive];
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -467,11 +513,9 @@ class Discount
|
|||
{
|
||||
$rules = $this->applyCouponAble();
|
||||
$appliedRule = null;
|
||||
$coupons = [];
|
||||
|
||||
foreach($rules['id'] as $rule) {
|
||||
array_push($coupons, $rule->coupons->code);
|
||||
if ($rule->use_coupon && $rule->auto_generation == 0) {
|
||||
if ($rule->auto_generation == 0) {
|
||||
if ($rule->coupons->code == $code) {
|
||||
$appliedRule = $rule;
|
||||
|
||||
|
|
@ -517,7 +561,7 @@ class Discount
|
|||
} else if ($test_mode == config('pricerules.test_mode.2')) {
|
||||
$result = $this->testAnyConditionIsTrue($conditions, $cart);
|
||||
} else if ($test_mode == config('pricerules.test_mode.3')) {
|
||||
$result = $this->testAbyConditionIsFalse($conditions, $cart);
|
||||
$result = $this->testAnyConditionIsFalse($conditions, $cart);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
|
@ -548,34 +592,84 @@ class Discount
|
|||
$realQty = $leastWorthItem['quantity'];
|
||||
|
||||
if ($action_type == config('pricerules.cart.validation.0')) {
|
||||
$newBaseSubTotal = $cart->grand_total - ($leastWorthItem['base_total'] * $disc_amount) / 100;
|
||||
} else if ($action_type == config('pricerules.cart.validation.1')) {
|
||||
if ($disc_amount > ($disc_quantity * $leastWorthItem['base_total'])) {
|
||||
$newBaseSubTotal = 0;
|
||||
if ($realQty <= $disc_quantity) {
|
||||
$newBaseSubTotal = $cart->grand_total - ($leastWorthItem['base_total'] * ($disc_amount * $disc_quantity)) / 100;
|
||||
} else {
|
||||
$newBaseSubTotal = $cart->grand_total - $disc_amount;
|
||||
$newBaseSubTotal = $cart->grand_total - ($leastWorthItem['base_total'] * $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;
|
||||
} else {
|
||||
$newBaseSubTotal = $cart->grand_total - $disc_amount;
|
||||
}
|
||||
} else {
|
||||
if ($disc_amount > $leastWorthItem['base_total']) {
|
||||
$newBaseSubTotal = 0;
|
||||
} else {
|
||||
$newBaseSubTotal = $cart->grand_total - $disc_amount;
|
||||
}
|
||||
}
|
||||
} else if ($action_type == config('pricerules.cart.validation.2')) {
|
||||
$newQuantity = $this->cartItem->find($leastWorthItem['id'])->quantity + $disc_amount;
|
||||
if ($realQty <= $disc_quantity) {
|
||||
$newQuantity = $this->cartItem->find($leastWorthItem['id'])->quantity + $disc_amount;
|
||||
} else {
|
||||
$newQuantity = $this->cartItem->find($leastWorthItem['id'])->quantity + $disc_quantity;
|
||||
}
|
||||
} else if ($action_type == config('pricerules.cart.validation.3')) {
|
||||
$newBaseSubTotal = $disc_amount;
|
||||
}
|
||||
|
||||
if ($action_type == config('pricerules.cart.validation.2')) {
|
||||
$cartRuleCart = $this->cartRuleCart->findWhere([
|
||||
'cart_id' => $cart->id,
|
||||
]);
|
||||
|
||||
if (count($cartRuleCart)) {
|
||||
$this->cartRuleCart->update([
|
||||
'cart_id' => $cart->id,
|
||||
'cart_rule_id' => $appliedRule->id
|
||||
], $cartRuleCart->first()->id);
|
||||
} else {
|
||||
$this->cartRuleCart->create([
|
||||
'cart_id' => $cart->id,
|
||||
'cart_rule_id' => $appliedRule->id
|
||||
]);
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'message' => trans('admin::app.promotion.status.coupon-applied'),
|
||||
'action' => $action_type,
|
||||
'amount_given' => false,
|
||||
'amount_payable' => $newQuantity,
|
||||
'amount' => null
|
||||
'amount' => null,
|
||||
'success' => true
|
||||
]);
|
||||
} else {
|
||||
$cartRuleCart = $this->cartRuleCart->findWhere([
|
||||
'cart_id' => $cart->id,
|
||||
]);
|
||||
|
||||
if (count($cartRuleCart)) {
|
||||
$this->cartRuleCart->update([
|
||||
'cart_id' => $cart->id,
|
||||
'cart_rule_id' => $appliedRule->id
|
||||
], $cartRuleCart->first()->id);
|
||||
} else {
|
||||
$this->cartRuleCart->create([
|
||||
'cart_id' => $cart->id,
|
||||
'cart_rule_id' => $appliedRule->id
|
||||
]);
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'message' => trans('admin::app.promotion.status.coupon-applied'),
|
||||
'action' => $action_type,
|
||||
'amount_given' => true,
|
||||
'amount_payable' => core()->currency($newBaseSubTotal),
|
||||
'amount' => core()->currency($cart->grand_total - $newBaseSubTotal)
|
||||
'amount_payable' => core()->currency($newBaseSubTotal + $cart->tax_total),
|
||||
'amount' => core()->currency($cart->grand_total - $newBaseSubTotal),
|
||||
'success' => true
|
||||
]);
|
||||
}
|
||||
} else {
|
||||
|
|
@ -584,7 +678,8 @@ class Discount
|
|||
'action' => $action_type,
|
||||
'amount_given' => null,
|
||||
'amount' => null,
|
||||
'least_value_item' => null
|
||||
'least_value_item' => null,
|
||||
'success' => false
|
||||
]);
|
||||
}
|
||||
} else {
|
||||
|
|
@ -593,7 +688,8 @@ class Discount
|
|||
'action' => null,
|
||||
'amount_given' => null,
|
||||
'amount' => null,
|
||||
'least_value_item' => null
|
||||
'least_value_item' => null,
|
||||
'success' => false
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,14 @@
|
|||
<?php
|
||||
|
||||
namespace Webkul\Discount\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Webkul\Discount\Contracts\CartRuleCart as CartRuleContract;
|
||||
|
||||
|
||||
class CartRuleCart extends Model implements CartRuleContract
|
||||
{
|
||||
protected $table = 'cart_rule_cart';
|
||||
|
||||
protected $guarded = ['created_at', 'updated_at'];
|
||||
}
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
<?php
|
||||
|
||||
namespace Webkul\Discount\Models;
|
||||
|
||||
use Konekt\Concord\Proxies\ModelProxy;
|
||||
|
||||
class CartRuleCartProxy extends ModelProxy
|
||||
{
|
||||
|
||||
}
|
||||
|
|
@ -17,6 +17,7 @@ class ModuleServiceProvider extends BaseModuleServiceProvider
|
|||
\Webkul\Discount\Models\CartRuleCoupons::class,
|
||||
\Webkul\Discount\Models\CartRuleLabels::class,
|
||||
\Webkul\Discount\Models\CartRuleCouponsUsage::class,
|
||||
\Webkul\Discount\Models\CartRuleCustomers::class
|
||||
\Webkul\Discount\Models\CartRuleCustomers::class,
|
||||
\Webkul\Discount\Models\CartRuleCart::class,
|
||||
];
|
||||
}
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
<?php
|
||||
|
||||
namespace Webkul\Discount\Repositories;
|
||||
|
||||
use Webkul\Core\Eloquent\Repository;
|
||||
|
||||
/**
|
||||
* Cart Rule Cart Reposotory
|
||||
*
|
||||
* @author Prashant Singh <prashant.singh852@webkul.com>
|
||||
* @copyright 2018 Webkul Software Pvt Ltd (http://www.webkul.com)
|
||||
*/
|
||||
class CartRuleCartRepository extends Repository
|
||||
{
|
||||
/**
|
||||
* Specify Model class name
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
function model()
|
||||
{
|
||||
return 'Webkul\Discount\Contracts\CartRuleCart';
|
||||
}
|
||||
}
|
||||
|
|
@ -70,8 +70,6 @@ class OnepageController extends Controller
|
|||
{
|
||||
$data = request()->all();
|
||||
|
||||
// dd($data);
|
||||
|
||||
$data['billing']['address1'] = implode(PHP_EOL, array_filter($data['billing']['address1']));
|
||||
$data['shipping']['address1'] = implode(PHP_EOL, array_filter($data['shipping']['address1']));
|
||||
|
||||
|
|
|
|||
|
|
@ -433,7 +433,13 @@ return [
|
|||
'contact' => 'Contact',
|
||||
'place-order' => 'Place Order',
|
||||
'new-address' => 'Add New Address',
|
||||
'save_as_address' => 'Save as Address'
|
||||
'save_as_address' => 'Save as Address',
|
||||
'apply-coupon' => 'Apply Coupon',
|
||||
'amt-payable' => 'Amount Payable',
|
||||
'got' => 'Got',
|
||||
'free' => 'Free',
|
||||
'coupon-used' => 'Coupon Used',
|
||||
'applied' => 'Applied'
|
||||
],
|
||||
|
||||
'total' => [
|
||||
|
|
|
|||
|
|
@ -511,8 +511,8 @@
|
|||
}).then(function(response) {
|
||||
this_this.message = response.data.message;
|
||||
|
||||
this_this.discounted = true;
|
||||
this_this.discount.amount = response.data.amount_payable;
|
||||
this_this.discounted = response.data.success;
|
||||
this_this.discount.amount = response.data.amount_payable,
|
||||
this_this.discount.amount_given = response.data.amount;
|
||||
}).catch(function(error) {
|
||||
this_this.discounted = false;
|
||||
|
|
@ -526,7 +526,7 @@
|
|||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
});
|
||||
</script>
|
||||
|
||||
@endpush
|
||||
|
|
@ -35,7 +35,7 @@
|
|||
|
||||
@if (! request()->is('checkout/cart'))
|
||||
@if (isset($rule['rule']) && ! $rule['rule']->end_other_rules)
|
||||
<form class="coupon-form" method="post" @submit.prevent="onSubmit" v-if="discounted == false">
|
||||
<form class="coupon-form" method="post" @submit.prevent="onSubmit" v-if="!discounted">
|
||||
<div class="control-group mt-20">
|
||||
<input v-model="code" type="text" class="control" value="" name="code" placeholder="Enter Coupon Code" v-on:change="codeChange" style="width: 100%">
|
||||
|
||||
|
|
@ -43,27 +43,25 @@
|
|||
|
||||
<span class="coupon-message mt-5" style="display: block; margin-bottom: 5px;" v-if="message == 'Success' || message == 'success'">@{{ message }}</span>
|
||||
|
||||
<button class="btn btn-lg btn-black">Apply Coupon</button>
|
||||
<button class="btn btn-lg btn-black">{{ __('shop::app.checkout.onepage.apply-coupon') }}</button>
|
||||
</div>
|
||||
</form>
|
||||
@endif
|
||||
|
||||
@if($rule)
|
||||
<div class="discounted" v-if="! discounted">
|
||||
<div class="discounted" v-if="!discounted">
|
||||
<div class="mt-15 mb-10">
|
||||
{{ $rule['rule']->name }} applied
|
||||
{{ $rule['rule']->name }} {{ __('shop::app.checkout.onepage.applied') }}
|
||||
</div>
|
||||
|
||||
<span class="horizontal-rule"></span>
|
||||
<span class="payble-amount row mt-10">
|
||||
@if ($rule['impact']['amount_given'])
|
||||
<label style="float: left;">{{ __('shop::app.checkout.onepage.amt-payable') }}</label>
|
||||
|
||||
<span class="row mt-10">
|
||||
@if ($rule['amount_given'])
|
||||
<label style="float: left;">Amount Payable</label>
|
||||
|
||||
<label style="float: right;">{{ core()->currency($cart->tax_total + $rule['amount']) }}</label>
|
||||
<label style="float: right;">{{ core()->currency($cart->tax_total + $rule['impact']['amount']) }}</label>
|
||||
@else
|
||||
<label style="float: left;">Got</label>
|
||||
<label style="float: right;">{{ $rule['amount'] }} Free</label>
|
||||
<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>
|
||||
|
|
@ -72,7 +70,7 @@
|
|||
@if (! $rule['rule']->end_other_rules)
|
||||
<div class="discounted" v-if="discounted">
|
||||
<div class="mt-15 mb-10">
|
||||
<b>Coupon used</b>
|
||||
<b>{{ __('shop::app.checkout.onepage.coupon-used') }}</b>
|
||||
</div>
|
||||
|
||||
<span class="row mb-10">
|
||||
|
|
@ -80,10 +78,8 @@
|
|||
<label style="float: right;">@{{ discount.amount_given }}</label>
|
||||
</span>
|
||||
|
||||
<span class="horizontal-rule"></span>
|
||||
|
||||
<span class="row mt-10">
|
||||
<label style="float: left;">Amount Payable</label>
|
||||
<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>
|
||||
|
|
|
|||
Loading…
Reference in New Issue