Merge branch 'master' of https://github.com/bagisto/bagisto into development
This commit is contained in:
commit
b5ef9526de
|
|
@ -64,7 +64,7 @@ Bagisto is using power of both of these frameworks and making best out of it out
|
|||
* **OS**: Ubuntu 16.04 LTS or higher / Windows 7 or Higher (WAMP / XAMP).
|
||||
* **SERVER**: Apache 2 or NGINX.
|
||||
* **RAM**: 3 GB or higher.
|
||||
* **PHP**: 7.2 or higher.
|
||||
* **PHP**: 7.1.3 or higher.
|
||||
* **Processor**: Clock Cycle 1 Ghz or higher.
|
||||
* **For MySQL users**: 5.7.23 or higher.
|
||||
* **For MariaDB users**: 10.2.7 or Higher.
|
||||
|
|
@ -141,7 +141,7 @@ Although, mailer environment variables are also required to be set up as **Bagis
|
|||
|
||||
##### On server:
|
||||
|
||||
Warning: Before going full on production mode we recommend you to install developer dependencies.
|
||||
Warning: Before going full on production mode we recommend you to uninstall developer dependencies.
|
||||
In order to do that, run the command below:
|
||||
|
||||
> composer install --no-dev
|
||||
|
|
|
|||
|
|
@ -16,9 +16,9 @@
|
|||
"ext-pdo": "*",
|
||||
"ext-pdo_mysql": "*",
|
||||
"ext-tokenizer": "*",
|
||||
"barryvdh/laravel-dompdf": "^0.8.0@dev",
|
||||
"barryvdh/laravel-dompdf": "0.8.3",
|
||||
"dimsav/laravel-translatable": "^9.0",
|
||||
"doctrine/dbal": "^2.9@dev",
|
||||
"doctrine/dbal": "2.9.2",
|
||||
"fideloper/proxy": "^4.0",
|
||||
"flynsarmy/db-blade-compiler": "*",
|
||||
"guzzlehttp/guzzle": "~6.0",
|
||||
|
|
@ -31,7 +31,7 @@
|
|||
"maatwebsite/excel": "3.1.11",
|
||||
"nwidart/laravel-modules": "^3.2",
|
||||
"prettus/l5-repository": "2.6.32",
|
||||
"tymon/jwt-auth": "dev-develop"
|
||||
"tymon/jwt-auth": "1.0.0-rc.4"
|
||||
},
|
||||
"require-dev": {
|
||||
"barryvdh/laravel-debugbar": "^3.1",
|
||||
|
|
@ -100,7 +100,8 @@
|
|||
"extra": {
|
||||
"laravel": {
|
||||
"dont-discover": [
|
||||
"barryvdh/laravel-debugbar"
|
||||
"barryvdh/laravel-debugbar",
|
||||
"laravel/dusk"
|
||||
]
|
||||
}
|
||||
},
|
||||
|
|
@ -122,4 +123,4 @@
|
|||
"optimize-autoloader": true
|
||||
},
|
||||
"minimum-stability": "dev"
|
||||
}
|
||||
}
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
|
|
@ -1,4 +1,4 @@
|
|||
{
|
||||
"/js/admin.js": "/js/admin.js?id=d4f31671591cde63824d",
|
||||
"/js/admin.js": "/js/admin.js?id=0afa8deaa3ea01b81abf",
|
||||
"/css/admin.css": "/css/admin.css?id=e9178754dd7096a8f7a0"
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ class CartRuleDataGrid extends DataGrid
|
|||
{
|
||||
$queryBuilder = DB::table('cart_rules')
|
||||
->select('id')
|
||||
->addSelect('id', 'name', 'starts_from', 'ends_till', 'priority', 'status', 'end_other_rules', 'action_type', 'disc_quantity', 'disc_threshold', 'use_coupon');
|
||||
->addSelect('id', 'name', 'status', 'end_other_rules', 'action_type', 'disc_amount', 'use_coupon');
|
||||
|
||||
$this->setQueryBuilder($queryBuilder);
|
||||
}
|
||||
|
|
@ -46,15 +46,6 @@ class CartRuleDataGrid extends DataGrid
|
|||
'filterable' => true
|
||||
]);
|
||||
|
||||
$this->addColumn([
|
||||
'index' => 'priority',
|
||||
'label' => trans('admin::app.datagrid.priority'),
|
||||
'type' => 'number',
|
||||
'searchable' => false,
|
||||
'sortable' => true,
|
||||
'filterable' => true,
|
||||
]);
|
||||
|
||||
$this->addColumn([
|
||||
'index' => 'status',
|
||||
'label' => trans('admin::app.datagrid.status'),
|
||||
|
|
@ -98,7 +89,7 @@ class CartRuleDataGrid extends DataGrid
|
|||
]);
|
||||
|
||||
$this->addColumn([
|
||||
'index' => 'disc_quantity',
|
||||
'index' => 'disc_amount',
|
||||
'label' => 'Quantity',
|
||||
'type' => 'number',
|
||||
'searchable' => false,
|
||||
|
|
@ -106,15 +97,6 @@ class CartRuleDataGrid extends DataGrid
|
|||
'filterable' => true
|
||||
]);
|
||||
|
||||
$this->addColumn([
|
||||
'index' => 'disc_threshold',
|
||||
'label' => 'Threshold',
|
||||
'type' => 'number',
|
||||
'searchable' => false,
|
||||
'sortable' => true,
|
||||
'filterable' => true
|
||||
]);
|
||||
|
||||
$this->addColumn([
|
||||
'index' => 'use_coupon',
|
||||
'label' => 'Use Coupon',
|
||||
|
|
|
|||
|
|
@ -686,12 +686,12 @@ return [
|
|||
'image' => 'Image',
|
||||
'content' => 'Content',
|
||||
'channels' => 'Channel',
|
||||
'created-success' => 'Slider Item Created Successfully',
|
||||
'created-fault' => 'Error In Creating Slider Item',
|
||||
'update-success' => 'Slider Item Successfully Updated',
|
||||
'update-fail' => 'Slider Cannot Be Updated',
|
||||
'delete-success' => 'Cannot Delete The Last Slider Item',
|
||||
'delete-fail' => 'Slider Item Successfully Deleted'
|
||||
'created-success' => 'Slider item created successfully',
|
||||
'created-fault' => 'Error in creating slider item',
|
||||
'update-success' => 'Slider item successfully updated',
|
||||
'update-fail' => 'Slider cannot be updated',
|
||||
'delete-success' => 'Cannot delete last llider item',
|
||||
'delete-fail' => 'Slider item successfully deleted'
|
||||
],
|
||||
|
||||
'tax-categories' => [
|
||||
|
|
@ -827,7 +827,7 @@ return [
|
|||
'zero-unlimited' => 'Zero denotes unlimited usage here',
|
||||
'catalog-rule' => 'Catalog Rules',
|
||||
'cart-rule' => 'Cart Rules',
|
||||
'add-catalog-rule' => 'Add Catalog Rule',
|
||||
'add-catalog-rule' => 'Add Rule',
|
||||
'add-cart-rule' => 'Add Cart Rule',
|
||||
'edit-cart-rule' => 'Edit Cart Rule',
|
||||
'edit-catalog-rule' => 'Edit Catalog Rule',
|
||||
|
|
@ -850,10 +850,11 @@ return [
|
|||
'yes' => 'Yes',
|
||||
'no' => 'No',
|
||||
'note' => 'Note',
|
||||
'apply' => 'Apply',
|
||||
'rule-name' => 'Enter Rule Name',
|
||||
'rule-desc' => 'Enter Rule Description',
|
||||
'convert-x-note' => 'If this section is left empty, then rule will get applied to all the products in the cart.',
|
||||
'declut' => 'Declutter Rules',
|
||||
'declut' => 'Declutter',
|
||||
'processing-done' => 'Rules processing done',
|
||||
'declut-success' => 'Catalog rules decluttering successful',
|
||||
'declut-failure' => 'Catalog rules decluttering failed',
|
||||
|
|
@ -914,7 +915,7 @@ return [
|
|||
'update-success' => 'Success! rule updated',
|
||||
'update-coupon-success' => 'Success! rule updated along with coupon',
|
||||
'update-failed' => 'Error! cannot update',
|
||||
'delete-success' => 'Sucess! rule deleted',
|
||||
'delete-success' => 'Success! rule deleted',
|
||||
'delete-failed' => 'Error! cannot delete',
|
||||
'coupon-applied' => 'Coupon used',
|
||||
'coupon-failed' => 'Coupon failed to apply',
|
||||
|
|
|
|||
|
|
@ -457,8 +457,8 @@
|
|||
match_criteria: 'all_are_true',
|
||||
|
||||
all_attributes: {
|
||||
'categories' : null,
|
||||
'attributes' : null
|
||||
'categories' : [],
|
||||
'attributes' : []
|
||||
},
|
||||
|
||||
code: null,
|
||||
|
|
@ -481,7 +481,6 @@
|
|||
conditions: @json($cart_rule[0]).conditions,
|
||||
cart_input: @json($cart_rule[0]).attributes,
|
||||
actions: @json($cart_rule[0]).actions,
|
||||
conditions_list:[],
|
||||
cart_object: {
|
||||
attribute: [],
|
||||
condition: [],
|
||||
|
|
@ -547,13 +546,7 @@
|
|||
},
|
||||
|
||||
detectApply() {
|
||||
if (this.apply == 'percent_of_product' || this.apply == 'buy_a_get_b') {
|
||||
this.apply_prct = true;
|
||||
this.apply_amt = false;
|
||||
} else if (this.apply == 'fixed_amount' || this.apply == 'fixed_amount_cart') {
|
||||
this.apply_prct = false;
|
||||
this.apply_amt = true;
|
||||
}
|
||||
return;
|
||||
},
|
||||
|
||||
enableCondition(event, index) {
|
||||
|
|
@ -597,26 +590,25 @@
|
|||
},
|
||||
|
||||
onSubmit: function (e) {
|
||||
if (this.attribute_values != null || this.category_values != null) {
|
||||
if (this.attribute_values.length != 0 || this.category_values.length != 0) {
|
||||
for (i in this.attribute_values) {
|
||||
delete this.attribute_values[i].options;
|
||||
}
|
||||
|
||||
if (this.category_values != null) {
|
||||
this.all_attributes.categories = this.category_values;
|
||||
}
|
||||
this.all_attributes.categories = this.category_values;
|
||||
|
||||
this.all_attributes.attributes = this.attribute_values;
|
||||
|
||||
this.all_attributes = JSON.stringify(this.all_attributes);
|
||||
} else {
|
||||
this.all_attributes = null;
|
||||
}
|
||||
|
||||
if (this.conditions_list.length != 0) {
|
||||
this.all_attributes = JSON.stringify(this.all_attributes);
|
||||
|
||||
if (this.conditions_list != null && this.conditions_list.length != 0) {
|
||||
this.conditions_list.push({'criteria': this.match_criteria});
|
||||
|
||||
this.all_conditions = JSON.stringify(this.conditions_list);
|
||||
|
||||
this.conditions_list.pop();
|
||||
}
|
||||
|
||||
this.$validator.validateAll().then(result => {
|
||||
|
|
|
|||
|
|
@ -228,7 +228,7 @@
|
|||
<option v-for="(condition, index) in conditions.numeric" :value="index" :key="index">@{{ condition }}</option>
|
||||
</select>
|
||||
|
||||
<input class="control" type="number" step="0.1000" name="cart_attributes[]" v-model="conditions_list[index].value" placeholder="{{ __('admin::app.promotion.enter-attribtue', ['attrbibute' => 'Value']) }}">
|
||||
<input class="control" type="number" step="0.1000" name="cart_attributes[]" v-model="conditions_list[index].value">
|
||||
</div>
|
||||
|
||||
<span class="icon trash-icon" v-on:click="removeCartAttr(index)"></span>
|
||||
|
|
@ -268,7 +268,7 @@
|
|||
</div> --}}
|
||||
|
||||
<div class="control-group" :class="[errors.has('disc_quantity') ? 'has-error' : '']">
|
||||
<label for="disc_amount" class="required">{{ __('admin::app.promotion.general-info.disc_qty') }}</label>
|
||||
<label for="disc_quantity" class="required">{{ __('admin::app.promotion.general-info.disc_qty') }}</label>
|
||||
|
||||
<input type="number" step="1" class="control" name="disc_quantity" v-model="disc_quantity" v-validate="'required|decimal|min_value:1'" value="{{ old('disc_quantity') }}" data-vv-as=""{{ __('admin::app.promotion.general-info.disc_qty') }}"">
|
||||
|
||||
|
|
@ -489,9 +489,10 @@
|
|||
country_and_states: @json($cart_rule[2]),
|
||||
|
||||
category_options: @json($cart_rule[1]),
|
||||
category_values: [],
|
||||
|
||||
category_values: [],
|
||||
attribute_values: [],
|
||||
|
||||
attr_object: {
|
||||
attribute: null,
|
||||
condition: null,
|
||||
|
|
@ -504,12 +505,11 @@
|
|||
|
||||
mounted () {
|
||||
data = @json($cart_rule[3]);
|
||||
|
||||
this.name = data.name;
|
||||
|
||||
this.description = data.description;
|
||||
|
||||
this.conditions_list = [];
|
||||
|
||||
this.channels = [];
|
||||
|
||||
for (i in data.channels) {
|
||||
|
|
@ -576,27 +576,28 @@
|
|||
|
||||
this.all_conditions = null;
|
||||
|
||||
if (data.conditions != null) {
|
||||
if (data.hasOwnProperty('conditions') && data.conditions != null) {
|
||||
this.conditions_list = JSON.parse(JSON.parse(data.conditions));
|
||||
|
||||
this.match_criteria = this.conditions_list.pop().criteria;
|
||||
}
|
||||
|
||||
if (JSON.parse(JSON.parse(data.actions).attribute_conditions)) {
|
||||
this.category_values = JSON.parse(JSON.parse(data.actions).attribute_conditions).categories;
|
||||
hasSubSelectionConditions = JSON.parse(data.actions).hasOwnProperty('attribute_conditions');
|
||||
|
||||
this.attribute_values = JSON.parse(JSON.parse(data.actions).attribute_conditions).attributes;
|
||||
if (hasSubSelectionConditions) {
|
||||
|
||||
if (this.category_values == null) {
|
||||
if (JSON.parse(data.actions).attribute_conditions.hasOwnProperty('categories')) {
|
||||
this.category_values = JSON.parse(data.actions).attribute_conditions.categories;
|
||||
} else {
|
||||
this.category_values = [];
|
||||
}
|
||||
|
||||
if (this.attribute_values == null) {
|
||||
if (JSON.parse(data.actions).attribute_conditions.hasOwnProperty('attributes')) {
|
||||
this.attribute_values = JSON.parse(data.actions).attribute_conditions.attributes;
|
||||
} else {
|
||||
this.attribute_values = [];
|
||||
}
|
||||
|
||||
console.log(this.category_values);
|
||||
|
||||
// creating options and has option param on the frontend
|
||||
for (i in this.attribute_values) {
|
||||
for (j in this.attribute_input) {
|
||||
|
|
@ -662,13 +663,7 @@
|
|||
},
|
||||
|
||||
detectApply() {
|
||||
if (this.apply == 'percent_of_product' || this.apply == 'buy_a_get_b') {
|
||||
this.apply_prct = true;
|
||||
this.apply_amt = false;
|
||||
} else if (this.apply == 'fixed_amount' || this.apply == 'fixed_amount_cart') {
|
||||
this.apply_prct = false;
|
||||
this.apply_amt = true;
|
||||
}
|
||||
return;
|
||||
},
|
||||
|
||||
enableCondition(event, index) {
|
||||
|
|
@ -716,7 +711,7 @@
|
|||
},
|
||||
|
||||
onSubmit: function (e) {
|
||||
if (this.attribute_values != null || this.category_values != null) {
|
||||
if (this.attribute_values.length != 0 || this.category_values.length != 0) {
|
||||
for (i in this.attribute_values) {
|
||||
delete this.attribute_values[i].options;
|
||||
}
|
||||
|
|
@ -730,7 +725,7 @@
|
|||
this.all_attributes = null;
|
||||
}
|
||||
|
||||
if (this.conditions_list != null) {
|
||||
if (this.conditions_list.length != 0) {
|
||||
this.conditions_list.push({'criteria': this.match_criteria});
|
||||
|
||||
this.all_conditions = JSON.stringify(this.conditions_list);
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@
|
|||
</a>
|
||||
|
||||
<a href="{{ route('admin.catalog-rule.apply') }}" class="btn btn-lg btn-primary">
|
||||
{{ __('Apply Rules') }}
|
||||
{{ __('admin::app.promotion.apply') }}
|
||||
</a>
|
||||
|
||||
<a href="{{ route('admin.catalog-rule.declut') }}" class="btn btn-lg btn-primary">
|
||||
|
|
|
|||
|
|
@ -5,4 +5,34 @@ namespace Webkul\Discount\Actions;
|
|||
abstract class Action
|
||||
{
|
||||
abstract public function calculate($rule);
|
||||
|
||||
public function getEligibleItems($rule)
|
||||
{
|
||||
$cart = \Cart::getCart();
|
||||
$items = $cart->items;
|
||||
|
||||
$matchedItems = collect();
|
||||
|
||||
$productIDs = $rule->product_ids;
|
||||
|
||||
$productIDs = explode(',', $productIDs);
|
||||
|
||||
$matchCriteria = $rule->uses_attribute_conditions ? $rule->product_ids : '*';
|
||||
|
||||
if ($matchCriteria == '*') {
|
||||
return $items;
|
||||
} else {
|
||||
$matchingIDs = explode(',', $matchCriteria);
|
||||
|
||||
foreach ($items as $item) {
|
||||
foreach ($matchingIDs as $matchingID) {
|
||||
if ($matchingID == $item->child ? $item->child->product_id : $item->product_id) {
|
||||
$matchedItems->push($item);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $matchedItems;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -8,122 +8,70 @@ class FixedAmount extends Action
|
|||
{
|
||||
public function calculate($rule)
|
||||
{
|
||||
$cart = \Cart::getCart();
|
||||
$items = $cart->items;
|
||||
|
||||
$impact = collect();
|
||||
|
||||
$totalDiscount = 0;
|
||||
|
||||
if ($rule->uses_attribute_conditions) {
|
||||
$productIDs = $rule->product_ids;
|
||||
$eligibleItems = $this->getEligibleItems($rule);
|
||||
|
||||
$productIDs = explode(',', $productIDs);
|
||||
$apply = function () use ($rule, $eligibleItems) {
|
||||
if ($rule->action_type == 'fixed_amount') {
|
||||
return true;
|
||||
} else {
|
||||
if ($rule->action_type == 'whole_cart_to_fixed' && $rule->uses_attribute_condition) {
|
||||
$matchIDs = explode(',', $rule->product_ids);
|
||||
|
||||
foreach ($productIDs as $productID) {
|
||||
foreach ($items as $item) {
|
||||
$itemPrice = $item->base_price;
|
||||
|
||||
if ($item->product->type == 'configurable') {
|
||||
$itemProductId = $item->child->product_id;
|
||||
} else {
|
||||
$itemProductId = $item->product_id;
|
||||
}
|
||||
|
||||
$itemQuantity = $item->quantity;
|
||||
|
||||
$discQuantity = $rule->disc_quantity;
|
||||
|
||||
if ($discQuantity > 1) {
|
||||
if ($itemQuantity >= $discQuantity) {
|
||||
if ($rule->disc_amount >= $itemPrice) {
|
||||
$discount = round($itemPrice * $discQuantity, 4);
|
||||
} else {
|
||||
$discount = $rule->disc_amount;
|
||||
}
|
||||
} else if ($itemQuantity < $discQuantity) {
|
||||
if ($rule->disc_amount >= $itemPrice) {
|
||||
$discount = round($itemPrice * $discQuantity, 4);
|
||||
} else {
|
||||
$discount = $rule->disc_amount;
|
||||
foreach ($matchIDs as $matchID) {
|
||||
foreach ($eligibleItems as $item) {
|
||||
if ($item->child ? $item->child->product_id : $item->product_id == $matchID) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if ($rule->disc_amount >= $itemPrice) {
|
||||
$discount = round($itemPrice * $discQuantity, 4);
|
||||
} else {
|
||||
$discount = $rule->disc_amount;
|
||||
}
|
||||
}
|
||||
|
||||
if ($itemProductId == $productID) {
|
||||
$totalDiscount = $totalDiscount + $discount;
|
||||
|
||||
$report = array();
|
||||
|
||||
$report['item_id'] = $item->id;
|
||||
$report['product_id'] = $item->child ? $item->child->product_id : $item->product_id;
|
||||
$report['discount'] = $discount;
|
||||
$report['formatted_discount'] = core()->currency($discount);
|
||||
|
||||
$impact->push($report);
|
||||
|
||||
unset($report);
|
||||
}
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
foreach ($items as $item) {
|
||||
};
|
||||
|
||||
if ($apply()) {
|
||||
if ($rule->action_type == 'whole_cart_to_fixed')
|
||||
{
|
||||
$eligibleItems = \Cart::getCart()->items;
|
||||
}
|
||||
|
||||
foreach ($eligibleItems as $item) {
|
||||
$itemPrice = $item->base_price;
|
||||
|
||||
$itemQuantity = $item->quantity;
|
||||
|
||||
$discQuantity = $rule->disc_quantity;
|
||||
|
||||
if ($discQuantity > 1) {
|
||||
if ($itemQuantity >= $discQuantity) {
|
||||
if ($rule->disc_amount >= $itemPrice) {
|
||||
$discount = round($itemPrice * $discQuantity, 4);
|
||||
} else {
|
||||
$discount = $rule->disc_amount;
|
||||
}
|
||||
} else if ($itemQuantity < $discQuantity) {
|
||||
if ($rule->disc_amount >= $itemPrice) {
|
||||
$discount = round($itemPrice * $discQuantity, 4);
|
||||
} else {
|
||||
$discount = $rule->disc_amount;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if ($rule->disc_amount >= $itemPrice) {
|
||||
$discount = round($itemPrice * $discQuantity, 4);
|
||||
} else {
|
||||
$discount = $rule->disc_amount;
|
||||
}
|
||||
}
|
||||
|
||||
$totalDiscount = $totalDiscount + $discount;
|
||||
$discQuantity = $itemQuantity <= $discQuantity ? $itemQuantity : $discQuantity;
|
||||
|
||||
$report = array();
|
||||
|
||||
$report['item_id'] = $item->id;
|
||||
$report['product_id'] = $item->child ? $item->child->product_id : $item->product_id;
|
||||
|
||||
if ($discount <= $itemPrice) {
|
||||
$report['discount'] = $discount;
|
||||
} else {
|
||||
$report['discount'] = $itemPrice;
|
||||
}
|
||||
$discount = round($rule->disc_amount, 4) * $discQuantity;
|
||||
|
||||
$discount = $discount <= $itemPrice * $discQuantity ? $discount : $itemPrice * $discQuantity;
|
||||
|
||||
$report['discount'] = $discount;
|
||||
|
||||
$report['formatted_discount'] = core()->currency($discount);
|
||||
|
||||
$impact->push($report);
|
||||
|
||||
$totalDiscount = $totalDiscount + $discount;
|
||||
|
||||
unset($report);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$impact->discount = $totalDiscount;
|
||||
$impact->formatted_discount = core()->currency($impact->discount);
|
||||
|
||||
|
|
|
|||
|
|
@ -6,143 +6,88 @@ use Webkul\Discount\Actions\Action;
|
|||
|
||||
class PercentOfProduct extends Action
|
||||
{
|
||||
/**
|
||||
* To calculate impact of cart rule's action of current items of cart instance
|
||||
*
|
||||
* @param CartRule $rule
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function calculate($rule)
|
||||
{
|
||||
$cart = \Cart::getCart();
|
||||
$items = $cart->items;
|
||||
|
||||
$impact = collect();
|
||||
|
||||
$totalDiscount = 0;
|
||||
|
||||
if ($rule->discount_amount >= 100) {
|
||||
$impact->discount = $cart->base_sub_total;
|
||||
$eligibleItems = $this->getEligibleItems($rule);
|
||||
|
||||
$impact->formatted_discount = core()->currency($impact->discount);
|
||||
}
|
||||
$apply = function () use($rule, $eligibleItems) {
|
||||
if ($rule->action_type == 'percent_of_product') {
|
||||
return true;
|
||||
} else {
|
||||
if ($rule->action_type == 'whole_cart_to_percent' && $rule->uses_attribute_condition) {
|
||||
$matchIDs = explode(',', $rule->product_ids);
|
||||
|
||||
if ($rule->uses_attribute_conditions) {
|
||||
$productIDs = $rule->product_ids;
|
||||
|
||||
$productIDs = explode(',', $productIDs);
|
||||
|
||||
// $matchCount = 0;
|
||||
|
||||
// foreach ($productIDs as $productID) {
|
||||
// foreach ($items as $item) {
|
||||
// if ($item->product_id == $productID) {
|
||||
// $matchCount++;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
foreach ($productIDs as $productID) {
|
||||
foreach ($items as $item) {
|
||||
$itemPrice = $item->base_price;
|
||||
|
||||
if ($item->product->type == 'configurable') {
|
||||
$itemProductId = $item->child->product_id;
|
||||
} else {
|
||||
$itemProductId = $item->product_id;
|
||||
}
|
||||
|
||||
$itemQuantity = $item->quantity;
|
||||
|
||||
$discQuantity = $rule->disc_quantity;
|
||||
|
||||
if ($discQuantity > 1) {
|
||||
if ($itemQuantity >= $discQuantity) {
|
||||
$discount = round(($itemPrice * $rule->disc_amount) / 100, 4) * $discQuantity;
|
||||
|
||||
if ($discount >= $itemPrice) {
|
||||
$discount = $itemPrice;
|
||||
}
|
||||
} else if ($itemQuantity < $discQuantity) {
|
||||
$discount = round(($itemPrice * $rule->disc_amount) / 100, 4) * $itemQuantity;
|
||||
|
||||
if ($discount >= $itemPrice) {
|
||||
$discount = $itemPrice;
|
||||
foreach ($matchIDs as $matchID) {
|
||||
foreach ($eligibleItems as $item) {
|
||||
if ($item->child ? $item->child->product_id : $item->product_id == $matchID) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$discount = round(($itemPrice * $rule->disc_amount) / 100, 4);
|
||||
|
||||
if ($discount >= $itemPrice) {
|
||||
$discount = $itemPrice;
|
||||
}
|
||||
}
|
||||
|
||||
if ($itemProductId == $productID) {
|
||||
$totalDiscount = $totalDiscount + $discount;
|
||||
|
||||
$report = array();
|
||||
|
||||
$report['item_id'] = $item->id;
|
||||
$report['product_id'] = $item->child ? $item->child->product_id : $item->product_id;
|
||||
$report['discount'] = $discount;
|
||||
$report['formatted_discount'] = core()->currency($discount);
|
||||
|
||||
$impact->push($report);
|
||||
|
||||
unset($report);
|
||||
}
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
foreach ($items as $item) {
|
||||
};
|
||||
|
||||
if ($apply()) {
|
||||
if ($rule->action_type == 'whole_cart_to_percent')
|
||||
{
|
||||
$eligibleItems = \Cart::getCart()->items;
|
||||
}
|
||||
|
||||
foreach ($eligibleItems as $item) {
|
||||
$itemPrice = $item->base_price;
|
||||
|
||||
$itemQuantity = $item->quantity;
|
||||
|
||||
$discQuantity = $rule->disc_quantity;
|
||||
|
||||
if ($discQuantity > 1) {
|
||||
if ($itemQuantity >= $discQuantity) {
|
||||
$discount = round(($itemPrice * $rule->disc_amount) / 100, 4) * $discQuantity;
|
||||
|
||||
if ($discount >= $itemPrice) {
|
||||
$discount = $itemPrice;
|
||||
}
|
||||
} else if ($itemQuantity < $discQuantity) {
|
||||
$discount = round(($itemPrice * $rule->disc_amount) / 100, 4) * $itemQuantity;
|
||||
|
||||
if ($discount >= $itemPrice) {
|
||||
$discount = $itemPrice;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$discount = round(($itemPrice * $rule->disc_amount) / 100, 4);
|
||||
|
||||
if ($discount >= $itemPrice) {
|
||||
$discount = $itemPrice;
|
||||
}
|
||||
}
|
||||
|
||||
$totalDiscount = $totalDiscount + $discount;
|
||||
$discQuantity = $itemQuantity <= $discQuantity ? $itemQuantity : $discQuantity;
|
||||
|
||||
$report = array();
|
||||
|
||||
$report['item_id'] = $item->id;
|
||||
$report['product_id'] = $item->child ? $item->child->product_id : $item->product_id;
|
||||
|
||||
if ($discount <= $itemPrice) {
|
||||
$report['discount'] = $discount;
|
||||
if ($rule->disc_amount > 100) {
|
||||
$discount_amount = 100;
|
||||
} else {
|
||||
$report['discount'] = $itemPrice;
|
||||
$discount_amount = 100;
|
||||
}
|
||||
|
||||
$discount = round(($itemPrice * $discount_amount) / 100, 4) * $discQuantity;
|
||||
|
||||
$discount = $discount <= $itemPrice * $discQuantity ? $discount : $itemPrice * $discQuantity;
|
||||
|
||||
$report['discount'] = $discount;
|
||||
|
||||
$report['formatted_discount'] = core()->currency($discount);
|
||||
|
||||
$impact->push($report);
|
||||
|
||||
$totalDiscount = $totalDiscount + $discount;
|
||||
|
||||
unset($report);
|
||||
}
|
||||
|
||||
$impact->discount = $totalDiscount;
|
||||
$impact->formatted_discount = core()->currency($impact->discount);
|
||||
|
||||
return $impact;
|
||||
}
|
||||
|
||||
|
||||
$impact->discount = $totalDiscount;
|
||||
$impact->formatted_discount = core()->currency($impact->discount);
|
||||
|
||||
return $impact;
|
||||
}
|
||||
}
|
||||
|
|
@ -2,86 +2,23 @@
|
|||
|
||||
namespace Webkul\Discount\Actions\Cart;
|
||||
|
||||
use Webkul\Discount\Actions\Action;
|
||||
use Webkul\Discount\Actions\Cart\FixedAmount;
|
||||
|
||||
class WholeCartToFixed extends Action
|
||||
class WholeCartToFixed
|
||||
{
|
||||
/**
|
||||
* To calculate impact of cart rule's action of current items of cart instance
|
||||
*
|
||||
* @param CartRule $rule
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function calculate($rule)
|
||||
{
|
||||
$cart = \Cart::getCart();
|
||||
$items = $cart->items;
|
||||
$actualInstance = new FixedAmount();
|
||||
|
||||
$impact = collect();
|
||||
$result = $actualInstance->calculate($rule);
|
||||
|
||||
$impact->discount = $rule->disc_amount;
|
||||
$impact->formatted_discount = core()->currency($impact->discount);
|
||||
|
||||
if ($rule->uses_attribute_conditions) {
|
||||
$productIDs = $rule->product_ids;
|
||||
|
||||
$productIDs = explode(',', $productIDs);
|
||||
|
||||
$matchCount = 0;
|
||||
|
||||
foreach ($productIDs as $productID) {
|
||||
foreach ($items as $item) {
|
||||
if ($item->product_id == $productID) {
|
||||
$matchCount++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($productIDs as $productID) {
|
||||
foreach ($items as $item) {
|
||||
$itemPrice = $item->base_price;
|
||||
|
||||
if ($item->product->type == 'configurable') {
|
||||
$itemProductId = $item->child->product_id;
|
||||
} else {
|
||||
$itemProductId = $item->product_id;
|
||||
}
|
||||
|
||||
$discount = round(($itemPrice * $impact->discount) / 100, 4);
|
||||
|
||||
if ($itemProductId == $productID) {
|
||||
$report = array();
|
||||
|
||||
$report['item_id'] = $item->id;
|
||||
$report['product_id'] = $item->product_id;
|
||||
$report['discount'] = $discount;
|
||||
$report['formatted_discount'] = core()->currency($discount);
|
||||
|
||||
$impact->push($report);
|
||||
|
||||
unset($report);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
foreach ($items as $item) {
|
||||
$itemPrice = $item->base_price;
|
||||
|
||||
if ($item->product->type == 'configurable') {
|
||||
$itemProductId = $item->child->product_id;
|
||||
} else {
|
||||
$itemProductId = $item->product_id;
|
||||
}
|
||||
|
||||
$discount = round(($itemPrice * $impact->discount) / 100, 4);
|
||||
|
||||
$report = array();
|
||||
|
||||
$report['item_id'] = $item->id;
|
||||
$report['product_id'] = $item->product_id;
|
||||
$report['discount'] = $discount;
|
||||
$report['formatted_discount'] = core()->currency($discount);
|
||||
|
||||
$impact->push($report);
|
||||
|
||||
unset($report);
|
||||
}
|
||||
}
|
||||
|
||||
return $impact;
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
|
@ -2,113 +2,23 @@
|
|||
|
||||
namespace Webkul\Discount\Actions\Cart;
|
||||
|
||||
use Webkul\Discount\Actions\Action;
|
||||
use Cart;
|
||||
use Webkul\Discount\Actions\Cart\PercentOfProduct;
|
||||
|
||||
class WholeCartToPercent extends Action
|
||||
class WholeCartToPercent
|
||||
{
|
||||
/**
|
||||
* To calculate impact of cart rule's action of current items of cart instance
|
||||
*
|
||||
* @param CartRule $rule
|
||||
* @param CartItem $items
|
||||
* @param Cart $cart
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function calculate($rule)
|
||||
{
|
||||
$cart = \Cart::getCart();
|
||||
$items = $cart->items;
|
||||
$actualInstance = new PercentOfProduct();
|
||||
|
||||
$impact = collect();
|
||||
$result = $actualInstance->calculate($rule);
|
||||
|
||||
$totalDiscount = 0;
|
||||
|
||||
if ($rule->uses_attribute_conditions) {
|
||||
$productIDs = $rule->product_ids;
|
||||
|
||||
$productIDs = explode(',', $productIDs);
|
||||
|
||||
$matchCount = 0;
|
||||
|
||||
foreach ($productIDs as $productID) {
|
||||
foreach ($items as $item) {
|
||||
if ($item->product_id == $productID) {
|
||||
$matchCount++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($matchCount > 0) {
|
||||
foreach ($productIDs as $productID) {
|
||||
foreach ($items as $item) {
|
||||
$itemPrice = $item->base_price;
|
||||
|
||||
$discount = round(($itemPrice * $rule->disc_amount) / 100, 4);
|
||||
|
||||
if ($discount >= $itemPrice) {
|
||||
$discount = $itemPrice;
|
||||
}
|
||||
|
||||
$totalDiscount = $totalDiscount + $discount;
|
||||
|
||||
if ($item->product_id == $productID) {
|
||||
$report = array();
|
||||
|
||||
$report['item_id'] = $item->id;
|
||||
$report['product_id'] = $item->child ? $item->child->product_id : $item->product_id;
|
||||
|
||||
if ($discount <= $itemPrice) {
|
||||
$report['discount'] = $discount;
|
||||
} else {
|
||||
$report['discount'] = $itemPrice;
|
||||
}
|
||||
|
||||
$report['formatted_discount'] = core()->currency(round($discount, 4));
|
||||
|
||||
$impact->push($report);
|
||||
|
||||
unset($report);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
foreach ($items as $item) {
|
||||
$itemPrice = $item->base_price;
|
||||
|
||||
$discount = round(($itemPrice * $rule->disc_amount) / 100, 4);
|
||||
|
||||
if ($discount > $itemPrice) {
|
||||
$discount = $itemPrice;
|
||||
}
|
||||
|
||||
$totalDiscount = $totalDiscount + $discount;
|
||||
|
||||
$report = array();
|
||||
|
||||
$report['item_id'] = $item->id;
|
||||
$report['product_id'] = $item->child ? $item->child->product_id : $item->product_id;
|
||||
|
||||
if ($discount <= $itemPrice) {
|
||||
$report['discount'] = $discount;
|
||||
} else {
|
||||
$report['discount'] = $itemPrice;
|
||||
}
|
||||
|
||||
$report['formatted_discount'] = core()->currency(round($discount, 4));
|
||||
|
||||
$impact->push($report);
|
||||
|
||||
unset($report);
|
||||
}
|
||||
}
|
||||
|
||||
$impact->discount = $totalDiscount;
|
||||
|
||||
$impact->fomatted_discount = core()->currency($impact->discount);
|
||||
|
||||
return $impact;
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
|
@ -5,7 +5,7 @@ return [
|
|||
'cart' => [
|
||||
'fixed_amount' => 'Webkul\Discount\Actions\Cart\FixedAmount',
|
||||
'percent_of_product' => 'Webkul\Discount\Actions\Cart\PercentOfProduct',
|
||||
// 'whole_cart_to_fixed' => 'aWebkul\Discount\Actions\Cart\WholeCartToFixed',
|
||||
'whole_cart_to_fixed' => 'Webkul\Discount\Actions\Cart\WholeCartToFixed',
|
||||
'whole_cart_to_percent' => 'Webkul\Discount\Actions\Cart\WholeCartToPercent'
|
||||
],
|
||||
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ return [
|
|||
'actions' => [
|
||||
'fixed_amount' => 'Apply as fixed amount',
|
||||
'percent_of_product' => 'Percentage of product',
|
||||
// 'whole_cart_to_fixed' => 'Adjust whole cart to fixed amount',
|
||||
'whole_cart_to_fixed' => 'Adjust whole cart to fixed amount',
|
||||
'whole_cart_to_percent' => 'Adjust whole cart to percent'
|
||||
],
|
||||
|
||||
|
|
|
|||
|
|
@ -58,16 +58,16 @@ abstract class Discount
|
|||
*/
|
||||
public function getApplicableRules($code = null)
|
||||
{
|
||||
$rules = collect();
|
||||
|
||||
if ($code != null) {
|
||||
$rules = $this->cartRule->findWhere([
|
||||
$eligibleRules = $this->cartRule->findWhere([
|
||||
'use_coupon' => 1,
|
||||
'status' => 1
|
||||
]);
|
||||
|
||||
foreach($rules as $rule) {
|
||||
foreach($eligibleRules as $rule) {
|
||||
if ($rule->coupons->code == $code) {
|
||||
$rules = collect();
|
||||
|
||||
$rules->push($rule);
|
||||
|
||||
break;
|
||||
|
|
@ -299,7 +299,7 @@ abstract class Discount
|
|||
|
||||
$this->updateCartItemAndCart($rule);
|
||||
|
||||
return;
|
||||
return $rule;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -175,34 +175,25 @@ class CartRuleController extends Controller
|
|||
// unset labels
|
||||
unset($data['label']);
|
||||
|
||||
// prepare json object from actions
|
||||
if (isset($data['disc_amount']) && $data['action_type'] == config('pricerules.cart.validations.2')) {
|
||||
$attribute_conditions = json_decode($attribute_conditions);
|
||||
|
||||
if (! isset($attribute_conditions) || ! (count($attribute_conditions->categories) || count($attribute_conditions->attributes))) {
|
||||
$data['uses_attribute_conditions'] = 0;
|
||||
|
||||
$data['actions'] = [
|
||||
'action_type' => $data['action_type'],
|
||||
'disc_amount' => $data['disc_amount'],
|
||||
'disc_threshold' => $data['disc_threshold']
|
||||
'disc_quantity' => $data['disc_quantity']
|
||||
];
|
||||
|
||||
$data['disc_quantity'] = $data['disc_amount'];
|
||||
} else {
|
||||
if (! isset($attribute_conditions) || $attribute_conditions == "[]" || $attribute_conditions == "") {
|
||||
$data['uses_attribute_conditions'] = 0;
|
||||
$data['uses_attribute_conditions'] = 1;
|
||||
|
||||
$data['actions'] = [
|
||||
'action_type' => $data['action_type'],
|
||||
'disc_amount' => $data['disc_amount'],
|
||||
'disc_quantity' => $data['disc_quantity']
|
||||
];
|
||||
} else {
|
||||
$data['uses_attribute_conditions'] = 1;
|
||||
|
||||
$data['actions'] = [
|
||||
'action_type' => $data['action_type'],
|
||||
'disc_amount' => $data['disc_amount'],
|
||||
'disc_quantity' => $data['disc_quantity'],
|
||||
'attribute_conditions' => $attribute_conditions
|
||||
];
|
||||
}
|
||||
$data['actions'] = [
|
||||
'action_type' => $data['action_type'],
|
||||
'disc_amount' => $data['disc_amount'],
|
||||
'disc_quantity' => $data['disc_quantity'],
|
||||
'attribute_conditions' => $attribute_conditions
|
||||
];
|
||||
}
|
||||
|
||||
// prepare json object from conditions
|
||||
|
|
@ -269,12 +260,11 @@ class CartRuleController extends Controller
|
|||
// $coupons['limit'] = $data['usage_limit'];
|
||||
// }
|
||||
|
||||
|
||||
// create a cart rule
|
||||
$ruleCreated = $this->cartRule->create($data);
|
||||
|
||||
// can execute convertX here after when the rule is updated
|
||||
if (isset($attribute_conditions) && $attribute_conditions != "[]" && $attribute_conditions != "") {
|
||||
if (isset($attribute_conditions) && $data['uses_attribute_conditions']) {
|
||||
$this->convertX->convertX($ruleCreated->id, $attribute_conditions);
|
||||
}
|
||||
|
||||
|
|
@ -413,34 +403,25 @@ class CartRuleController extends Controller
|
|||
unset($data['attributes']);
|
||||
|
||||
// prepare actions from data for json action
|
||||
if (isset($data['disc_amount']) && $data['action_type'] == config('pricerules.cart.validations.2')) {
|
||||
$attribute_conditions = json_decode($attribute_conditions);
|
||||
|
||||
if (! isset($attribute_conditions) || ! (count($attribute_conditions->categories) || count($attribute_conditions->attributes))) {
|
||||
$data['uses_attribute_conditions'] = 0;
|
||||
|
||||
$data['actions'] = [
|
||||
'action_type' => $data['action_type'],
|
||||
'disc_amount' => $data['disc_amount'],
|
||||
'disc_quantity' => $data['disc_quantity']
|
||||
];
|
||||
|
||||
$data['disc_quantity'] = $data['disc_amount'];
|
||||
} else {
|
||||
$attribute_conditions = json_decode($attribute_conditions);
|
||||
$data['uses_attribute_conditions'] = 1;
|
||||
|
||||
if (! (isset($attribute_conditions->categories) && count($attribute_conditions->categories)) && ! (isset($attribute_conditions->attributes) && count($attribute_conditions->attributes))) {
|
||||
$data['uses_attribute_conditions'] = 0;
|
||||
|
||||
$data['actions'] = [
|
||||
'action_type' => $data['action_type'],
|
||||
'disc_amount' => $data['disc_amount'],
|
||||
'disc_quantity' => $data['disc_quantity']
|
||||
];
|
||||
} else {
|
||||
$data['uses_attribute_conditions'] = 1;
|
||||
|
||||
$data['actions'] = [
|
||||
'action_type' => $data['action_type'],
|
||||
'disc_amount' => $data['disc_amount'],
|
||||
'disc_quantity' => $data['disc_quantity'],
|
||||
'attribute_conditions' => json_encode($attribute_conditions)
|
||||
];
|
||||
}
|
||||
$data['actions'] = [
|
||||
'action_type' => $data['action_type'],
|
||||
'disc_amount' => $data['disc_amount'],
|
||||
'disc_quantity' => $data['disc_quantity'],
|
||||
'attribute_conditions' => $attribute_conditions
|
||||
];
|
||||
}
|
||||
|
||||
// encode php array to json for actions
|
||||
|
|
@ -564,7 +545,7 @@ class CartRuleController extends Controller
|
|||
|
||||
return response()->json(['message' => true], 200);
|
||||
} else {
|
||||
session()->flash('success', trans('admin::app.promotion.status.delete-failed'));
|
||||
session()->flash('error', trans('admin::app.promotion.status.delete-failed'));
|
||||
|
||||
return response()->json(['message' => false], 400);
|
||||
}
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
|
|
@ -1,4 +1,4 @@
|
|||
{
|
||||
"/js/ui.js": "/js/ui.js?id=5b8c3afb6e5e82f33c7e",
|
||||
"/js/ui.js": "/js/ui.js?id=4790fa62f6dc92d60020",
|
||||
"/css/ui.css": "/css/ui.css?id=240433c0894f0bd57181"
|
||||
}
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ $data = array();
|
|||
|
||||
// reading env content
|
||||
$data = file($envFile);
|
||||
$databaseArray = ['DB_HOST', 'DB_DATABASE', 'DB_USERNAME', 'DB_PASSWORD', 'DB_CONNECTION'];
|
||||
$databaseArray = ['DB_HOST', 'DB_DATABASE', 'DB_USERNAME', 'DB_PASSWORD', 'DB_CONNECTION', 'DB_PORT'];
|
||||
$key = $value = [];
|
||||
|
||||
if ($data) {
|
||||
|
|
@ -67,10 +67,11 @@ $data = array();
|
|||
$password = $databaseData['DB_PASSWORD'];
|
||||
$dbname = $databaseData['DB_DATABASE'];
|
||||
$connection = $databaseData['DB_CONNECTION'];
|
||||
$port = $databaseData['DB_PORT'];
|
||||
|
||||
if ($connection == 'mysql' ) {
|
||||
// Create connection
|
||||
@$conn = new mysqli($servername, $username, $password, $dbname);
|
||||
@$conn = new mysqli($servername, $username, $password, $dbname, (int)$port);
|
||||
|
||||
// check connection
|
||||
if ($conn->connect_error) {
|
||||
|
|
|
|||
|
|
@ -117,8 +117,8 @@ $data = array();
|
|||
// checking database connection(mysql only)
|
||||
if ($_POST["database_connection"] == 'mysql') {
|
||||
// Create connection
|
||||
@$conn = new mysqli($_POST["host_name"], $_POST["user_name"], $_POST["user_password"], $_POST["database_name"]);
|
||||
|
||||
@$conn = new mysqli($_POST["host_name"], $_POST["user_name"], $_POST["user_password"], $_POST["database_name"], $_POST['port_name']);
|
||||
|
||||
// check connection
|
||||
if ($conn->connect_error) {
|
||||
$errors['database_error'] = $conn->connect_error;
|
||||
|
|
|
|||
Loading…
Reference in New Issue