Catalog rule create form implemented

This commit is contained in:
Prashant Singh 2019-08-08 11:38:23 +05:30
parent 6d41d37c3b
commit 55ead412ce
8 changed files with 233 additions and 395 deletions

View File

@ -21,7 +21,7 @@ class CatalogRuleDataGrid extends DataGrid
{
$queryBuilder = DB::table('catalog_rules')
->select('id')
->addSelect('id', 'name', 'starts_from', 'ends_till', 'priority', 'status', 'end_other_rules', 'action_type');
->addSelect('id', 'name', 'starts_from', 'ends_till', 'status', 'end_other_rules', 'action_code');
$this->setQueryBuilder($queryBuilder);
}
@ -64,15 +64,6 @@ class CatalogRuleDataGrid 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'),
@ -104,19 +95,12 @@ class CatalogRuleDataGrid extends DataGrid
]);
$this->addColumn([
'index' => 'action_type',
'index' => 'action_code',
'label' => 'Action Type',
'type' => 'string',
'searchable' => false,
'sortable' => true,
'filterable' => true,
'wrapper' => function ($value) {
foreach(config('pricerules.catalog.actions') as $key => $action) {
if ($value->action_type == $key) {
return trans($action);
}
}
}
'filterable' => true
]);
}

View File

@ -110,14 +110,6 @@
<span class="control-error" v-if="errors.has('ends_till')">@{{ errors.first('ends_till') }}</span>
</div>
</datetime>
<div class="control-group" :class="[errors.has('priority') ? 'has-error' : '']">
<label for="priority" class="required">{{ __('admin::app.promotion.general-info.priority') }}</label>
<input type="number" class="control" step="1" name="priority" v-model="priority" v-validate="'required|numeric|min_value:1'" value="{{ old('priority') }}" data-vv-as="&quot;{{ __('admin::app.promotion.general-info.priority') }}&quot;">
<span class="control-error" v-if="errors.has('priority')">@{{ errors.first('priority') }}</span>
</div>
</div>
</accordian>
@ -125,6 +117,7 @@
<div slot="body">
<input type="hidden" name="all_conditions" v-model="all_conditions">
<!-- Categories selection input block -->
<div class="control-group" :class="[errors.has('category_values') ? 'has-error' : '']">
<label class="mb-10" for="categories">{{ __('admin::app.promotion.select-category') }}</label>
@ -135,6 +128,7 @@
<br/>
<!-- Product attributes conditions block -->
<div class="control-container mt-20" v-for="(condition, index) in attribute_values" :key="index">
<select class="control" v-model="attribute_values[index].attribute" style="margin-right: 15px; width: 30%;" v-on:change="enableAttributeCondition($event, index)">
<option disabled="disabled">{{ __('admin::app.promotion.select-attribute', ['attribute' => 'Option']) }}</option>
@ -223,9 +217,8 @@
customer_groups: [],
ends_till: null,
starts_from: null,
priority: 0,
per_customer: 0,
status: null,
status: 1,
use_coupon: null,
auto_generation: false,
usage_limit: 0,
@ -236,11 +229,7 @@
apply_prct: false,
apply_to_shipping: 0,
disc_amount: null,
disc_threshold: null,
disc_quantity: null,
end_other_rules: 0,
coupon_type: null,
free_shipping: 0,
all_conditions: [],
@ -249,28 +238,12 @@
'attributes' : null
},
code: null,
suffix: null,
prefix: null,
dedicated_label: true,
label: {
global: null,
@foreach(core()->getAllChannels() as $channel)
@foreach($channel->locales as $locale)
{{ trim($channel->code) }} : {
{{ trim($locale->code) }}: ''
},
@endforeach
@endforeach
},
criteria: 'cart',
actions: @json($catalog_rule[0]).actions,
category_options: @json($catalog_rule[1]),
category_values: [],
conditions: @json($catalog_rule[0]).conditions,
attribute_values: [],
attr_object: {
attribute: null,
@ -283,7 +256,6 @@
},
mounted () {
console.log(this.applied_config);
},
methods: {
@ -338,7 +310,13 @@
addAttributeCondition() {
this.attribute_values.push(this.attr_object);
console.log('working');
this.attr_object = {
attribute: null,
condition: null,
value: [],
options: []
};
},
enableCondition(event, index) {
@ -396,11 +374,21 @@
this.all_attributes.attributes = this.attribute_values;
this.all_attributes = JSON.stringify(this.all_attributes);
this.all_conditions = JSON.stringify(this.all_attributes);
} else {
this.all_attributes = null;
this.all_conditions = null;
}
// this.all_conditions = JSON.stringify(this.conditions_list);
// if (this.conditions_list.length != 0) {
// this.conditions_list.push({'criteria': this.match_criteria});
// this.all_conditions = JSON.stringify(this.conditions_list);
// }
// return false;
this.$validator.validateAll().then(result => {
if (result) {
e.target.submit();

View File

@ -1,7 +1,7 @@
@extends('admin::layouts.content')
@section('page_title')
{{ __('admin::app.promotion.edit-catalog-rule') }}
{{ __('admin::app.promotion.add-catalog-rule') }}
@stop
@section('content')
@ -12,7 +12,7 @@
@push('scripts')
<script type="text/x-template" id="catalog-rule-form-template">
<div>
<form method="POST" action="{{ route('admin.catalog-rule.update', $catalog_rule[5]->id) }}" @submit.prevent="onSubmit">
<form method="POST" action="{{ route('admin.catalog-rule.store') }}" @submit.prevent="onSubmit">
@csrf
<div class="page-header">
@ -20,13 +20,13 @@
<h1>
<i class="icon angle-left-icon back-link" onclick="history.length > 1 ? history.go(-1) : window.location = '{{ url('/admin/dashboard') }}';"></i>
{{ __('admin::app.promotion.edit-catalog-rule') }}
{{ __('admin::app.promotion.add-catalog-rule') }}
</h1>
</div>
<div class="page-action fixed-action">
<button type="submit" class="btn btn-lg btn-primary">
{{ __('admin::app.promotion.edit-btn-title') }}
{{ __('admin::app.promotion.save-btn-title') }}
</button>
</div>
</div>
@ -35,7 +35,7 @@
<div class="form-container">
@csrf()
<accordian :active="true" title="Information">
<accordian :active="true" title="{{ __('admin::app.promotion.information') }}">
<div slot="body">
<div class="control-group" :class="[errors.has('name') ? 'has-error' : '']">
<label for="name" class="required">{{ __('admin::app.promotion.general-info.name') }}</label>
@ -76,38 +76,26 @@
@endforeach
</select>
<span class="control-error" v-if="errors.has('channels[]')">@{{ errors.first('channels[]') }}</span>
<span class="control-error" v-if="errors.has('channels[]')">@{{ errors.first('status') }}</span>
</div>
<div class="control-group" :class="[errors.has('status') ? 'has-error' : '']">
<label for="status" class="required">{{ __('admin::app.promotion.general-info.status') }}</label>
<select type="text" class="control" name="status" v-model="status" v-validate="'required'" data-vv-as="&quot;{{ __('admin::app.promotion.general-info.status') }}&quot;">
<option disabled="disabled">Select status</option>
<option value="1">Yes</option>
<option value="0">No</option>
<option disabled="disabled">{{ __('admin::app.promotion.select-attribute', ['attribute' => 'Option']) }}</option>
<option value="1">{{ __('admin::app.promotion.yes') }}</option>
<option value="0">{{ __('admin::app.promotion.no') }}</option>
</select>
<span class="control-error" v-if="errors.has('status')">@{{ errors.first('status') }}</span>
</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.end_other_rules') }}</label>
<select type="text" class="control" name="end_other_rules" v-model="end_other_rules" v-validate="'required'" data-vv-as="&quot;{{ __('admin::app.promotion.general-info.end_other_rules') }}&quot;">
<option disabled="disabled">Select option</option>
<option value="1">Yes</option>
<option value="0">No</option>
</select>
<span class="control-error" v-if="errors.has('end_other_rules')">@{{ errors.first('end_other_rules') }}</span>
</div>
<datetime :name="starts_from">
<div class="control-group" :class="[errors.has('starts_from') ? 'has-error' : '']">
<label for="starts_from" class="required">{{ __('admin::app.promotion.general-info.starts-from') }}</label>
<input type="text" class="control" v-model="starts_from" name="starts_from" v-validate="'required'" data-vv-as="&quot;{{ __('admin::app.promotion.general-info.starts-from') }}&quot;">
<input type="text" class="control" v-model="starts_from" name="starts_from" data-vv-as="&quot;{{ __('admin::app.promotion.general-info.starts-from') }}&quot;">
<span class="control-error" v-if="errors.has('starts_from')">@{{ errors.first('starts_from') }}</span>
</div>
@ -117,7 +105,7 @@
<div class="control-group" :class="[errors.has('ends_till') ? 'has-error' : '']">
<label for="ends_till" class="required">{{ __('admin::app.promotion.general-info.ends-till') }}</label>
<input type="text" class="control" v-model="ends_till" name="ends_till" v-validate="'required'" data-vv-as="&quot;{{ __('admin::app.promotion.general-info.ends-till') }}&quot;">
<input type="text" class="control" v-model="ends_till" name="ends_till" data-vv-as="&quot;{{ __('admin::app.promotion.general-info.ends-till') }}&quot;">
<span class="control-error" v-if="errors.has('ends_till')">@{{ errors.first('ends_till') }}</span>
</div>
@ -133,196 +121,86 @@
</div>
</accordian>
<accordian :active="true" title="Conditions">
<accordian :active="false" title="{{ __('admin::app.promotion.conditions') }}">
<div slot="body">
<div class="add-condition">
<div class="control-group" :class="[errors.has('criteria') ? 'has-error' : '']">
<label for="criteria" class="required">{{ __('admin::app.promotion.general-info.add-condition') }}</label>
<input type="hidden" name="all_conditions" v-model="all_conditions">
<select type="text" class="control" name="criteria" v-model="criteria" v-validate="'required'" value="" data-vv-as="&quot;{{ __('admin::app.promotion.general-info.cust-groups') }}&quot;">
<option value="attribute">Attribute</option>
<option value="category">Category</option>
<option value="attribute_family">Attribute Family</option>
<!-- Categories selection input block -->
<div class="control-group" :class="[errors.has('category_values') ? 'has-error' : '']">
<label class="mb-10" for="categories">{{ __('admin::app.promotion.select-category') }}</label>
<multiselect v-model="category_values" :close-on-select="false" :options="category_options" :searchable="false" :custom-label="categoryLabel" :show-labels="true" placeholder="Select Categories" track-by="slug" :multiple="true"></multiselect>
</div>
<label class="mb-10" for="attributes">{{ __('admin::app.promotion.select-attribute', ['attribute' => 'Attribute']) }}</label>
<br/>
<!-- Product attributes conditions block -->
<div class="control-container mt-20" v-for="(condition, index) in attribute_values" :key="index">
<select class="control" v-model="attribute_values[index].attribute" style="margin-right: 15px; width: 30%;" v-on:change="enableAttributeCondition($event, index)">
<option disabled="disabled">{{ __('admin::app.promotion.select-attribute', ['attribute' => 'Option']) }}</option>
<option v-for="(attr_ip, index1) in attribute_input" :value="attr_ip.code" :key="index1">@{{ attr_ip.name }}</option>
</select>
<select class="control" v-model="attribute_values[index].condition" style="margin-right: 15px;">
<option v-for="(condition, index) in conditions.string" :value="index" :key="index">@{{ condition }}</option>
</select>
<div v-show='attribute_values[index].type == "select" || attribute_values[index].type == "multiselect"' style="display: flex;">
<select class="control" v-model="attribute_values[index].value" style="margin-right: 15px; height: 100px" :multiple="true">
<option :disabled="true">
{{ __('ui::form.select-attribute', ['attribute' => 'Values']) }}
</option>
<option v-for="(label, index2) in attribute_values[index].options" :value="index2" :key="index2">@{{ label.admin_name }}</option>
</select>
<span class="control-error" v-if="errors.has('criteria')">@{{ errors.first('criteria') }}</span>
{{-- <multiselect v-model="attribute_values[index].value" :close-on-select="false" :options="attribute_values[index].options" :searchable="false" :track-by="admin_name" :custom-label="attributeListLabel" :multiple="true" ></multiselect> --}}
</div>
<span class="btn btn-primary btn-lg" v-on:click="addCondition">Add Condition</span>
</div>
<div class="condition-set" v-if="conditions_list.length">
<!-- Attribute -->
<div v-for="(condition, index) in conditions_list" :key="index">
<div class="control-container mt-20" v-if='conditions_list[index].criteria == "attribute"'>
<div class="title-bar">
{{-- <span>Group </span>
<input type="checkbox" v-model="condition_groups" v-on:click="groupSelected(index)" /> --}}
<span>Attribute is </span>
<span class="icon cross-icon" v-on:click="removeAttr(index)"></span>
</div>
<div class="control-group mt-10" :key="index">
<select class="control" name="attributes[]" v-model="conditions_list[index].attribute" v-validate="'required'" title="You Can Make Multiple Selections Here" style="margin-right: 15px;" v-on:change="enableCondition($event, index)">
<option disabled="disabled">Select attribute</option>
<option v-for="(attr_ip, i) in attrs_input" :value="attr_ip.code">@{{ attr_ip.name }}</option>
</select>
<div v-if='conditions_list[index].type == "text" || conditions_list[index].type == "textarea"'>
<select class="control" name="attributes[]" v-model="conditions_list[index].condition" v-validate="'required'" style="margin-right: 15px;">
@foreach($catalog_rule[4]['text'] as $key => $value)
<option value="{{ $key }}">{{ __($value) }}</option>
@endforeach
</select>
<input type="text" class="control" name="attributes[]" v-model="conditions_list[index].value" placeholder="Enter Value">
</div>
<div v-if='conditions_list[index].type == "price"'>
<select class="control" name="attributes[]" v-model="conditions_list[index].condition" v-validate="'required'" style="margin-right: 15px;">
@foreach($catalog_rule[4]['numeric'] as $key => $value)
<option value="{{ $key }}">{{ __($value) }}</option>
@endforeach
</select>
<input type="number" step="0.1000" class="control" name="attributes[]" v-model="conditions_list[index].value" placeholder="Enter Value">
</div>
<div v-else-if='conditions_list[index].type == "boolean"'>
<select class="control" name="attributes[]" v-model="conditions_list[index].condition" v-validate="'required'" style="margin-right: 15px;">
<option selected="selected">is</option>
</select>
<select class="control" name="attributes[]" v-model="conditions_list[index].value">
@foreach($catalog_rule[4]['boolean'] as $key => $value)
<option value="{{ $key }}">{{ __($value) }}</option>
@endforeach
</select>
</div>
<div v-else-if='conditions_list[index].type == "date"'>
<select class="control" name="attributes[]" v-model="conditions_list[index].condition" v-validate="'required'" style="margin-right: 15px;">
@foreach($catalog_rule[4]['numeric'] as $key => $value)
<option value="{{ $key }}">{{ __($value) }}</option>
@endforeach
</select>
<date>
<input type="text" class="control" v-model="conditions_list[index].value" name="attributes[]" v-validate="'required'" value="Enter Value">
</date>
</div>
<div v-else-if='conditions_list[index].type == "datetime"'>
<select class="control" name="attributes[]" v-model="conditions_list[index].condition" v-validate="'required'" style="margin-right: 15px;">
@foreach($catalog_rule[4]['numeric'] as $key => $value)
<option value="{{ $key }}">{{ __($value) }}</option>
@endforeach
</select>
<datetime>
<input type="text" class="control" v-model="conditions_list[index].value" name="attributes[]" v-validate="'required'" value="Enter Value">
</datetime>
</div>
<div v-else-if='conditions_list[index].type == "select" || conditions_list[index].type == "multiselect"'>
<select class="control" name="attributes[]" v-model="conditions_list[index].condition" v-validate="'required'" style="margin-right: 15px;">
@foreach($catalog_rule[4]['text'] as $key => $value)
<option value="{{ $key }}">{{ __($value) }}</option>
@endforeach
</select>
<select class="control" v-model="conditions_list[index].value" name="attributes[]" v-validate="'required'" multiple>
<option v-for="option in conditions_list[index].options" :value="option.id">@{{ option.admin_name }}</option>
</select>
</div>
</div>
</div>
<div class="control-container mt-20" v-if='conditions_list[index].criteria == "category"'>
<div class="title-bar">
<span>Category </span>
{{-- <span>Group </span>
<input type="checkbox" v-model="condition_groups" v-on:click="groupSelected(index)" /> --}}
<span class="icon cross-icon" v-on:click="removeAttr(index)"></span>
</div>
<div class="control-group mt-10" :key="index">
<input type="hidden" class="control" name="attributes[]" v-model="conditions_list[index].category" v-validate="'required'" style="margin-right: 15px;" v-on:change="enableCondition($event, index)">
<select class="control" name="attributes[]" v-model="conditions_list[index].condition" v-validate="'required'" style="margin-right: 15px;">
@foreach($catalog_rule[4]['text'] as $key => $value)
<option value="{{ $key }}">{{ __($value) }}</option>
@endforeach
</select>
<select class="control" name="attributes[]" v-model="conditions_list[index].value" placeholder="Enter Value" multiple>
<option v-for="(category, index) in categories" :value="category.id">@{{ category.name }}</option>
</select>
</div>
</div>
<div class="control-container mt-20" v-if='conditions_list[index].criteria == "attribute_family"'>
<div class="title-bar">
<span>Attribute Family </span>
{{-- <span>Group </span>
<input type="checkbox" v-model="condition_groups" v-on:click="groupSelected(index)" /> --}}
<span class="icon cross-icon" v-on:click="removeAttr(index)"></span>
</div>
<div class="control-group mt-10" :key="index">
<input type="hidden" class="control" name="attributes[]" v-model="conditions_list[index].family" v-validate="'required'" style="margin-right: 15px;" v-on:change="enableCondition($event, index)">
<select class="control" name="attributes[]" v-model="conditions_list[index].condition" v-validate="'required'" style="margin-right: 15px;">
@foreach($catalog_rule[4]['boolean'] as $key => $value)
<option value="{{ $key }}">{{ __($value) }}</option>
@endforeach
</select>
<select class="control" name="attributes[]" v-model="conditions_list[index].value" placeholder="Enter Value">
<option v-for="(attr_family, index) in attr_families" :value="attr_family.id">@{{ attr_family.name }}</option>
</select>
</div>
</div>
<div v-show='attribute_values[index].type == "text" || attribute_values[index].type == "textarea" || attribute_values[index].type == "price" || attribute_values[index].type == "textarea"' style="display: flex">
<input class="control" v-model="attribute_values[index].value" type="text" placeholder="{{ __('ui::form.enter-attribute', ['attribute' => 'Text']) }}">
</div>
<input type="hidden" name="all_conditions[]" v-model="all_conditions">
<span class="icon trash-icon" v-on:click="removeAttr(index)"></span>
</div>
<span class="btn btn-primary btn-lg mt-20" v-on:click="addAttributeCondition">Add Attribute Condition</span>
</div>
</accordian>
<accordian :active="true" title="Actions">
<accordian :active="false" title="{{ __('admin::app.promotion.actions') }}">
<div slot="body">
<div class="control-group" :class="[errors.has('apply') ? 'has-error' : '']">
<label for="apply" class="required">Apply</label>
<div class="control-group" :class="[errors.has('action_type') ? 'has-error' : '']">
<label for="action_type" class="required">{{ __('admin::app.promotion.general-info.apply') }}</label>
<select class="control" name="apply" v-model="apply" v-validate="'required'" value="{{ old('apply') }}" data-vv-as="&quot;Apply As&quot;" v-on:change="detectApply">
@foreach($catalog_rule[3]['actions'] as $key => $value)
<option value="{{ $key }}">{{ __($value) }}</option>
@endforeach
<select class="control" name="action_type" v-model="action_type" v-validate="'required'" value="{{ old('action_type') }}" data-vv-as="&quot;{{ __('admin::app.promotion.general-info.apply') }}&quot;" v-on:change="detectApply">
<option v-for="(action, index) in actions" :value="index">@{{ action }}</option>
</select>
<span class="control-error" v-if="errors.has('apply')">@{{ errors.first('apply') }}</span>
<span class="control-error" v-if="errors.has('action_type')">@{{ errors.first('action_type') }}</span>
</div>
<div class="control-group" :class="[errors.has('disc_amount') ? 'has-error' : '']" v-if="apply_amt">
<div class="control-group" :class="[errors.has('disc_amount') ? 'has-error' : '']">
<label for="disc_amount" class="required">{{ __('admin::app.promotion.general-info.disc_amt') }}</label>
<input type="number" step="1.0000" class="control" name="disc_amount" v-model="disc_amount" v-validate="'required|decimal|min_value:0.0001'" value="{{ old('disc_amount') }}" data-vv-as="&quot;{{ __('admin::app.promotion.general-info.disc_amt') }}&quot;">
<input type="number" step="0.5000" class="control" name="disc_amount" v-model="disc_amount" v-validate="'required|min_value:0.0001'" value="{{ old('disc_amount') }}" data-vv-as="&quot;{{ __('admin::app.promotion.general-info.disc_amt') }}&quot;">
<span class="control-error" v-if="errors.has('disc_amount')">@{{ errors.first('disc_amount') }}</span>
</div>
<div class="control-group" :class="[errors.has('disc_percent') ? 'has-error' : '']" v-if="apply_prct">
<label for="disc_percent" class="required">{{ __('admin::app.promotion.general-info.disc_percent') }}</label>
<div class="control-group" :class="[errors.has('end_other_rules') ? 'has-error' : '']">
<label for="end_other_rules" class="required">{{ __('admin::app.promotion.general-info.end-other-rules') }}</label>
<input type="number" step="0.5000" class="control" name="disc_percent" v-model="disc_percent" v-validate="'required|decimal|min_value:0.0001'" value="{{ old('disc_percent') }}" data-vv-as="&quot;{{ __('admin::app.promotion.general-info.disc_percent') }}&quot;">
<select type="text" class="control" name="end_other_rules" v-model="end_other_rules" v-validate="'required'" data-vv-as="&quot;{{ __('admin::app.promotion.general-info.end-other-rules') }}&quot;">
<option disabled="disabled">{{ __('admin::app.promotion.select-attribute', ['attribute' => 'Option']) }}</option>
<option value="1">{{ __('admin::app.promotion.yes') }}</option>
<option value="0">{{ __('admin::app.promotion.no') }}</option>
</select>
<span class="control-error" v-if="errors.has('disc_percent')">@{{ errors.first('disc_percent') }}</span>
<span class="control-error" v-if="errors.has('end_other_rules')">@{{ errors.first('end_other_rules') }}</span>
</div>
</div>
</accordian>
@ -340,143 +218,80 @@
data () {
return {
all_conditions: [],
name: 'null',
description: 'null',
conditions_list: [],
channels: [],
customer_groups: [],
ends_till: null,
starts_from: null,
status: 1,
action_type: null,
apply: null,
apply_amt: false,
apply_prct: false,
applied_config: @json($catalog_rule[3]),
conditions_list: [],
attr_families: @json($catalog_rule[8]),
attrs_input: @json($catalog_rule[0]),
attrs_options: @json($catalog_rule[2]),
global_condition: {
all_conditions: false,
all_condition: true
disc_amount: null,
end_other_rules: 0,
all_conditions: [],
all_attributes: {
'categories' : null,
'attributes' : null
},
criteria: 'cart',
actions: @json($catalog_rule[0]).actions,
category_options: @json($catalog_rule[1]),
category_values: [],
conditions: @json($catalog_rule[0]).conditions,
attribute_values: [],
attr_object: {
criteria: 'attribute',
attribute: null,
condition: null,
type: null,
value: null
value: [],
options: []
},
cat_object: {
criteria: 'category',
category: 'category',
condition: null,
value: []
},
fam_object: {
criteria: 'attribute_family',
family: 'attribute_family',
condition: null,
value: null
},
categories: @json($catalog_rule[1]),
cats: [],
cats_count: 0,
channels: [],
conditions: [],
criteria: null,
customer_groups: [],
description: null,
disc_amount: 0.0,
disc_percent: 0.0,
ends_till: null,
end_other_rules: null,
name: null,
priority: 0,
starts_from: null,
status: null,
attribute_input: @json($catalog_rule[3])
}
},
mounted () {
all = @json($catalog_rule[5]);
this.name = all.name;
this.description = all.description;
this.apply = all.action_type;
this.end_other_rules = all.end_other_rules;
this.criteria = 'attribute';
channels = @json($catalog_rule[6]);
for (i in channels) {
this.channels.push(channels[i].channel_id);
}
customer_groups = @json($catalog_rule[7]);
for (i in customer_groups) {
this.customer_groups.push(customer_groups[i].customer_group_id);
}
this.conditions_list = JSON.parse(JSON.parse(all.conditions)[0]);
this.status = @json($catalog_rule[5]).status;
this.starts_from = @json($catalog_rule[5]).starts_from;
this.ends_till = @json($catalog_rule[5]).ends_till;
this.priority = @json($catalog_rule[5]).priority;
if (this.apply == 0 || this.apply == 2) {
this.apply_prct = true;
this.disc_percent = @json($catalog_rule[5]).disc_percent;
} else if (this.apply == 1 || this.apply == 3) {
this.apply_amt = true;
this.disc_amount = @json($catalog_rule[5]).disc_amount;
}
},
methods: {
addCondition () {
if (this.criteria == 'attribute' || this.criteria == 'attribute_family' || this.criteria == 'category') {
this.condition_on = this.criteria;
} else {
alert('please try again');
return false;
}
if (this.condition_on == 'attribute') {
this.conditions_list.push(this.attr_object);
this.attr_object = {
criteria: this.condition_on,
attribute: null,
condition: null,
value: null,
type: null,
options: null
};
} else if (this.condition_on == 'category') {
this.conditions_list.push(this.cat_object);
this.cat_object = {
criteria: this.condition_on,
category: 'category',
condition: null,
value: []
};
} else if (this.condition_on == 'attribute_family') {
this.conditions_list.push(this.fam_object);
this.fam_object = {
criteria: this.condition_on,
family: 'attribute_family',
condition: null,
value: null
};
}
categoryLabel (option) {
return option.name + ' [ ' + option.slug + ' ]';
},
enableCondition(event, index) {
this.conditions_list[index].type = this.attrs_input[event.target.selectedIndex - 1].type;
attributeListLabel(option) {
return option.label;
},
var this_this = this;
addAttributeCondition() {
this.attribute_values.push(this.attr_object);
if (this.attrs_input[event.target.selectedIndex - 1].type == 'select' || this.attrs_input[event.target.selectedIndex - 1].type == 'multiselect') {
this.conditions_list[index].options = this.attrs_options[this.attrs_input[event.target.selectedIndex - 1].name];
this.attr_object = {
attribute: null,
condition: null,
value: [],
options: []
};
},
this.conditions_list[index].value = [];
enableAttributeCondition (event, index) {
selectedIndex = event.target.selectedIndex - 1;
for(i in this.attribute_input) {
if (i == selectedIndex) {
if (this.attribute_input[i].has_options == true) {
this.attribute_values[index].options = this.attribute_input[i].options;
}
this.attribute_values[index].type = this.attribute_input[i].type;
}
}
},
@ -494,38 +309,46 @@
this.conditions_list.splice(index, 1);
},
removeCat(index) {
this.cats.splice(index, 1);
},
onSubmit: function (e) {
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.length > 0) {
this.all_attributes.categories = this.category_values;
}
this.all_attributes.attributes = this.attribute_values;
this.all_conditions = JSON.stringify(this.all_attributes);
} else {
this.all_conditions = null;
}
// this.all_conditions = JSON.stringify(this.conditions_list);
// if (this.conditions_list.length != 0) {
// this.conditions_list.push({'criteria': this.match_criteria});
// this.all_conditions = JSON.stringify(this.conditions_list);
// }
// return false;
this.$validator.validateAll().then(result => {
if (result) {
e.target.submit();
}
});
},
for (index in this.conditions_list) {
if (this.conditions_list[index].condition == null || this.conditions_list[index].condition == "" || this.conditions_list[index].condition == undefined) {
window.flashMessages = [{'type': 'alert-error', 'message': "{{ __('admin::app.promotion.catalog.condition-missing') }}" }];
this.$root.addFlashMessages();
return false;
} else if (this.conditions_list[index].value == null || this.conditions_list[index].value == "" || this.conditions_list[index].value == undefined) {
window.flashMessages = [{'type': 'alert-error', 'message': "{{ __('admin::app.promotion.catalog.condition-missing') }}" }];
this.$root.addFlashMessages();
return false;
}
}
if (this.conditions_list.length == 0) {
window.flashMessages = [{'type': 'alert-error', 'message': "{{ __('admin::app.promotion.catalog.condition-missing') }}" }];
this.$root.addFlashMessages();
return false;
}
this.all_conditions = JSON.stringify(this.conditions_list);
genericGroupCondition() {
this.generic_condition = false;
},
addFlashMessages() {

View File

@ -20,7 +20,7 @@ class CreateCatalogRulesTable extends Migration
$table->datetime('starts_from')->nullable();
$table->datetime('ends_till')->nullable();
$table->boolean('status')->default(0);
$table->json('conditons')->nullable();
$table->json('conditions')->nullable();
$table->json('actions')->nullable();
$table->boolean('end_other_rules')->default(0);
$table->string('action_code')->nullable();

View File

@ -99,24 +99,41 @@ class CatalogRuleController extends Controller
public function create()
{
return view($this->_config['view'])->with('catalog_rule', [$this->appliedConfig, $this->category->getPartial(), $this->getStatesAndCountries(), $this->attribute->getPartial()]);;
// dd($this->appliedConfig);
return view($this->_config['view'])->with('catalog_rule', [$this->appliedConfig, $this->category->getPartial(), $this->getStatesAndCountries(), $this->attribute->getPartial()]);
}
public function store()
{
// $data = request()->all();
// $validated = \Validator::Make($data, [
// 'name' => 'required|string',
// 'description' => 'string',
// 'customer_groups' => 'required',
// 'channels' => 'required',
// 'status' => 'required|boolean',
// 'end_other_rules' => 'required|boolean',
// 'priority' => 'required|numeric',
// 'all_conditions' => 'present',
// 'disc_amount' => 'sometimes',
// 'disc_percent' => 'sometimes',
// ]);
// if ($validated->fails()) {
// dd('failed', $validated->errors());
// } else {
// dd('passed');
// }
$this->validate(request(), [
'name' => 'required|string',
'description' => 'string',
'customer_groups' => 'required',
'channels' => 'required',
'starts_from' => 'required|date',
'ends_till' => 'required|date',
'status' => 'required|boolean',
'end_other_rules' => 'required|boolean',
'priority' => 'required|numeric',
'criteria' => 'required',
'all_conditions' => 'required|array',
'apply' => 'required|numeric|min:0|max:3',
'all_conditions' => 'present',
'disc_amount' => 'sometimes',
'disc_percent' => 'sometimes',
]);
@ -136,19 +153,22 @@ class CatalogRuleController extends Controller
unset($catalog_rule['all_conditions']);
if (isset($catalog_rule['disc_amount'])) {
$catalog_rule['action_type'] = $catalog_rule['apply'];
$catalog_rule['actions'] = [
'action_type' => $catalog_rule['apply'],
'action_code' => $catalog_rule['action_type'],
'disc_amount' => $catalog_rule['disc_amount']
];
} else if (isset($catalog_rule['disc_percent'])) {
$catalog_rule['action_type'] = $catalog_rule['apply'];
$catalog_rule['actions'] = [
'action_type' => $catalog_rule['apply'],
'action_code' => $catalog_rule['action_type'],
'disc_percent' => $catalog_rule['disc_percent'],
];
}
$catalog_rule['discount_amount'] = $catalog_rule['disc_amount'];
$catalog_rule['action_code'] = $catalog_rule['action_type'];
unset($catalog_rule['disc_amount']);
unset($catalog_rule['apply']);
unset($catalog_rule['attributes']);
unset($catalog_rule['_token']);

View File

@ -11,7 +11,7 @@ class CatalogRule extends Model implements CatalogRuleContract
{
protected $table = 'catalog_rules';
protected $guarded = ['created_at', 'updated_at'];
protected $fillable = ['name', 'description', 'starts_from', 'ends_till', 'status', 'conditions', 'actions', 'end_other_rules', 'action_code', 'discount_amount'];
public function channels()
{

View File

@ -0,0 +1,13 @@
<?php
namespace Webkul\Discount\Models;
use Illuminate\Database\Eloquent\Model;
use Webkul\Discount\Contracts\CatalogRuleProductsPrice as CatalogRuleProductPriceContract;
class CatalogRuleProductsPrice extends Model implements CatalogRuleProductContract
{
protected $table = 'catalog_rules_products_price';
protected $guarded = ['created_at', 'updated_at'];
}

View File

@ -0,0 +1,10 @@
<?php
namespace Webkul\Discount\Models;
use Konekt\Concord\Proxies\ModelProxy;
class CatalogRuleProductsPriceProxy extends ModelProxy
{
}