diff --git a/packages/Webkul/Admin/src/Resources/lang/en/app.php b/packages/Webkul/Admin/src/Resources/lang/en/app.php
index 0b7f96a2d..924d459df 100755
--- a/packages/Webkul/Admin/src/Resources/lang/en/app.php
+++ b/packages/Webkul/Admin/src/Resources/lang/en/app.php
@@ -801,7 +801,8 @@ return [
'apply-percent' => 'Apply as percentage',
'apply-fixed' => 'Apply as fixed amount',
'adjust-to-percent' => 'Adjust to percentage',
- 'adjust-to-value' => 'Adjust to discount value'
+ 'adjust-to-value' => 'Adjust to discount value',
+ 'condition-missing' => 'Please check conditons, some values might be missing'
],
'cart' => [
'buy-atleast' => 'Buy Atleast (N)',
diff --git a/packages/Webkul/Admin/src/Resources/views/layouts/master.blade.php b/packages/Webkul/Admin/src/Resources/views/layouts/master.blade.php
index 4ec5052f2..a64de8787 100755
--- a/packages/Webkul/Admin/src/Resources/views/layouts/master.blade.php
+++ b/packages/Webkul/Admin/src/Resources/views/layouts/master.blade.php
@@ -62,7 +62,7 @@
@elseif ($error = session('error'))
window.flashMessages = [{'type': 'alert-error', 'message': "{{ $error }}" }];
@elseif ($info = session('info'))
- window.flashMessages = [{'type': 'alert-error', 'message': "{{ $info }}" }];
+ window.flashMessages = [{'type': 'alert-info', 'message': "{{ $info }}" }];
@endif
window.serverErrors = [];
diff --git a/packages/Webkul/Admin/src/Resources/views/promotions/catalog-rule/create.blade.php b/packages/Webkul/Admin/src/Resources/views/promotions/catalog-rule/create.blade.php
index 811d5a924..9350680ad 100644
--- a/packages/Webkul/Admin/src/Resources/views/promotions/catalog-rule/create.blade.php
+++ b/packages/Webkul/Admin/src/Resources/views/promotions/catalog-rule/create.blade.php
@@ -6,283 +6,251 @@
@section('content')
@push('scripts')
@@ -297,8 +265,10 @@
apply: null,
apply_amt: false,
apply_prct: false,
+ applied_config: @json($criteria[3]),
attributes_list: [],
attrs_input: @json($criteria[0]),
+ attrs_options: @json($criteria[2]),
attr_object: {
attribute: null,
condition: null,
@@ -331,6 +301,7 @@
},
mounted () {
+ console.log(this.attrs_options);
},
methods: {
@@ -370,25 +341,19 @@
var this_this = this;
if (this.attrs_input[event.target.selectedIndex - 1].type == 'select' || this.attrs_input[event.target.selectedIndex - 1].type == 'multiselect') {
- axios.post('{{ route('admin.catalog-rule.options') }}', {
- 'attribute' : this.attrs_input[event.target.selectedIndex - 1].attribute
- })
- .then(function (response) {
- console.log(response);
+ console.log(this.attrs_input[event.target.selectedIndex - 1].name);
- this.attributes_list[index].value = null;
- })
- .catch(function (error) {
- console.log(error);
- });
+ this.attributes_list[index].options = this.attrs_options[this.attrs_input[event.target.selectedIndex - 1].name];
+
+ this.attributes_list[index].value = [];
}
},
detectApply() {
- if (this.apply == 1 || this.apply == 3) {
+ if (this.apply == 0 || this.apply == 2) {
this.apply_prct = true;
this.apply_amt = false;
- } else if (this.apply == 2 || this.apply == 4) {
+ } else if (this.apply == 1 || this.apply == 3) {
this.apply_prct = false;
this.apply_amt = true;
}
@@ -402,8 +367,38 @@
this.cats.splice(index, 1);
},
- beforeOnSubmit() {
+ onSubmit: function (e) {
+ for (index in this.attributes_list) {
+ if (this.attributes_list[index].condition == null || this.attributes_list[index].condition == "" || this.attributes_list[index].condition == undefined) {
+ window.flashMessages = [{'type': 'alert-error', 'message': "{{ __('admin::app.promotion.catalog.condition-missing') }}" }];
+
+ this.$root.addFlashMessages();
+
+ return false;
+ } else if (this.attributes_list[index].value == null || this.attributes_list[index].value == "" || this.attributes_list[index].value == undefined) {
+ window.flashMessages = [{'type': 'alert-error', 'message': "{{ __('admin::app.promotion.catalog.condition-missing') }}" }];
+
+ this.$root.addFlashMessages();
+
+ return false;
+ }
+ }
+
this.all_conditions = JSON.stringify(this.attributes_list);
+
+ this.$validator.validateAll().then(result => {
+ if (result) {
+ e.target.submit();
+ }
+ });
+ },
+
+ addFlashMessages() {
+ const flashes = this.$refs.flashes;
+
+ flashMessages.forEach(function(flash) {
+ flashes.addFlash(flash);
+ }, this);
}
}
});
diff --git a/packages/Webkul/Discount/src/Config/cart-attributes.php b/packages/Webkul/Discount/src/Config/cart-attributes.php
deleted file mode 100644
index 96bdbfbfc..000000000
--- a/packages/Webkul/Discount/src/Config/cart-attributes.php
+++ /dev/null
@@ -1,58 +0,0 @@
- [
- 0 => 'Apply as percentage',
- 1 => 'Apply as fixed amount',
- 2 => 'Adjust to percentage',
- 3 => 'Adjust to discount value'
- ],
-
- 'cart' => [
- 0 => [
- 'name' => 'Sub-total',
- 'type' => 'numeric'
- ],
- 1 => [
- 'name' => 'Total Items Quantity',
- 'type' => 'numeric'
- ],
- 2 => [
- 'name' => 'Total Weight',
- 'type' => 'numeric'
- ],
- 3 => [
- 'name' => 'Payment Method',
- 'type' => 'string'
- ],
- 4 => [
- 'name' => 'Shipping Postcode',
- 'type' => 'string'
- ],
- 5 => [
- 'name' => 'Shipping State',
- 'type' => 'string'
- ],
- 6 => [
- 'name' => 'Shipping Country',
- 'type' => 'string'
- ]
- ],
-
- 'conditions' => [
- 'numeric' => [
- 0 => 'Equals',
- 1 => 'Equals or greater',
- 2 => 'Equals or lesser',
- 3 => 'Greater than',
- 4 => 'Lesser than'
- ],
-
- 'text' => [
- 0 => 'is',
- 1 => 'is not',
- 2 => 'contains',
- 3 => 'does not contains'
- ],
- ]
-];
\ No newline at end of file
diff --git a/packages/Webkul/Discount/src/Config/rule-conditions.php b/packages/Webkul/Discount/src/Config/rule-conditions.php
new file mode 100644
index 000000000..22fd1af3a
--- /dev/null
+++ b/packages/Webkul/Discount/src/Config/rule-conditions.php
@@ -0,0 +1,105 @@
+ [
+ 'numeric' => [
+ 0 => 'Equals',
+ 1 => 'Equals or greater',
+ 2 => 'Equals or lesser',
+ 3 => 'Greater than',
+ 4 => 'Lesser than'
+ ],
+
+ 'text' => [
+ 0 => 'is',
+ 1 => 'is not',
+ 2 => 'contains',
+ 3 => 'does not contains'
+ ],
+
+ 'boolean' => [
+ 0 => 'True/Yes',
+ 1 => 'False/No',
+ ]
+ ],
+
+ 'catalog' => [
+ 'actions' => [
+ 0 => 'admin::app.promotion.catalog.apply-percent',
+ 1 => 'admin::app.promotion.catalog.apply-fixed',
+ 2 => 'admin::app.promotion.catalog.adjust-to-percent',
+ 3 => 'admin::app.promotion.catalog.adjust-to-value'
+ ],
+
+ 'attributes' => [
+ 0 => [
+ 'name' => 'Sub-total',
+ 'type' => 'numeric'
+ ],
+ 1 => [
+ 'name' => 'Total Items Quantity',
+ 'type' => 'numeric'
+ ],
+ 2 => [
+ 'name' => 'Total Weight',
+ 'type' => 'numeric'
+ ],
+ 3 => [
+ 'name' => 'Payment Method',
+ 'type' => 'string'
+ ],
+ 4 => [
+ 'name' => 'Shipping Postcode',
+ 'type' => 'string'
+ ],
+ 5 => [
+ 'name' => 'Shipping State',
+ 'type' => 'string'
+ ],
+ 6 => [
+ 'name' => 'Shipping Country',
+ 'type' => 'string'
+ ]
+ ]
+ ],
+
+ 'cart' => [
+ 'actions' => [
+ 0 => 'Apply as percentage',
+ 1 => 'Apply as fixed amount',
+ 2 => 'Adjust to percentage',
+ 3 => 'Adjust to discount value'
+ ],
+
+ 'attributes' => [
+ 0 => [
+ 'name' => 'Sub-total',
+ 'type' => 'numeric'
+ ],
+ 1 => [
+ 'name' => 'Total Items Quantity',
+ 'type' => 'numeric'
+ ],
+ 2 => [
+ 'name' => 'Total Weight',
+ 'type' => 'numeric'
+ ],
+ 3 => [
+ 'name' => 'Payment Method',
+ 'type' => 'string'
+ ],
+ 4 => [
+ 'name' => 'Shipping Postcode',
+ 'type' => 'string'
+ ],
+ 5 => [
+ 'name' => 'Shipping State',
+ 'type' => 'string'
+ ],
+ 6 => [
+ 'name' => 'Shipping Country',
+ 'type' => 'string'
+ ]
+ ]
+ ],
+];
\ No newline at end of file
diff --git a/packages/Webkul/Discount/src/Database/Migrations/2019_05_07_184255_create_catalog_rules_table.php b/packages/Webkul/Discount/src/Database/Migrations/2019_05_07_184255_create_catalog_rules_table.php
index b485a26a1..c4b9fd2f8 100644
--- a/packages/Webkul/Discount/src/Database/Migrations/2019_05_07_184255_create_catalog_rules_table.php
+++ b/packages/Webkul/Discount/src/Database/Migrations/2019_05_07_184255_create_catalog_rules_table.php
@@ -26,12 +26,14 @@ class CreateCatalogRulesTable extends Migration
$table->datetime('starts_from')->nullable();
$table->datetime('ends_till')->nullable();
$table->boolean('status')->default(1);
+ $table->integer('priority')->unsigned();
$table->json('conditions')->nullable();
$table->json('actions')->nullable();
$table->boolean('end_other_rules')->default(1);
$table->integer('sort_order')->unsigned()->default(0);
$table->string('action_type')->nullable();
- $table->decimal('discount_amount', 12, 4)->default(0.0000);
+ $table->decimal('dis_amt', 12, 4)->default(0.0000);
+ $table->decimal('dis_qty', 12, 4)->nullable();
$table->timestamps();
});
}
diff --git a/packages/Webkul/Discount/src/Database/Migrations/2019_05_07_184348_create_catalog_products_table.php b/packages/Webkul/Discount/src/Database/Migrations/2019_05_07_184348_create_catalog_rule_products_table.php
similarity index 88%
rename from packages/Webkul/Discount/src/Database/Migrations/2019_05_07_184348_create_catalog_products_table.php
rename to packages/Webkul/Discount/src/Database/Migrations/2019_05_07_184348_create_catalog_rule_products_table.php
index 21e086208..4a5ddbbed 100644
--- a/packages/Webkul/Discount/src/Database/Migrations/2019_05_07_184348_create_catalog_products_table.php
+++ b/packages/Webkul/Discount/src/Database/Migrations/2019_05_07_184348_create_catalog_rule_products_table.php
@@ -4,7 +4,7 @@ use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
-class CreateCatalogProductsTable extends Migration
+class CreateCatalogRuleProductsTable extends Migration
{
/**
* Run the migrations.
@@ -13,7 +13,7 @@ class CreateCatalogProductsTable extends Migration
*/
public function up()
{
- Schema::create('catalog_products', function (Blueprint $table) {
+ 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');
diff --git a/packages/Webkul/Discount/src/Database/Migrations/2019_05_13_024326_create_cart_rule_table.php b/packages/Webkul/Discount/src/Database/Migrations/2019_05_13_024326_create_cart_rule_table.php
index 0b72e240e..e165d033d 100644
--- a/packages/Webkul/Discount/src/Database/Migrations/2019_05_13_024326_create_cart_rule_table.php
+++ b/packages/Webkul/Discount/src/Database/Migrations/2019_05_13_024326_create_cart_rule_table.php
@@ -21,6 +21,7 @@ class CreateCartRuleTable extends Migration
$table->datetime('ends_till')->nullable();
$table->json('conditions')->nullable();
$table->json('actions')->nullable();
+ $table->integer('priority')->unsigned()->default(0);
$table->longtext('product_ids')->nullable();
$table->boolean('status')->default(1);
$table->boolean('end_other_rules')->default(1);
diff --git a/packages/Webkul/Discount/src/Http/Controllers/CartRuleController.php b/packages/Webkul/Discount/src/Http/Controllers/CartRuleController.php
index fcfadd196..249db6c1c 100644
--- a/packages/Webkul/Discount/src/Http/Controllers/CartRuleController.php
+++ b/packages/Webkul/Discount/src/Http/Controllers/CartRuleController.php
@@ -70,12 +70,7 @@ class CartRuleController extends Controller
$this->product = $product;
$this->CartRule = $cartRule;
$this->cart = $cart;
- $this->appliedConfig = [
- 0 => trans('admin::app.promotion.Cart.apply-percent'),
- 1 => trans('admin::app.promotion.Cart.apply-fixed'),
- 2 => trans('admin::app.promotion.Cart.adjust-to-percent'),
- 3 => trans('admin::app.promotion.Cart.adjust-to-value')
- ];
+ $this->appliedConfig = config('pricerules.catalog');
}
public function index()
@@ -85,7 +80,7 @@ class CartRuleController extends Controller
public function create()
{
- return view($this->_config['view'])->with('criteria', [config('pricerules'), $this->fetchOptionableAttributes(), $this->getStatesAndCountries()]);
+ return view($this->_config['view'])->with('criteria', [$this->appliedConfig, $this->fetchOptionableAttributes(), $this->getStatesAndCountries()]);
}
public function store()
diff --git a/packages/Webkul/Discount/src/Http/Controllers/CatalogRuleController.php b/packages/Webkul/Discount/src/Http/Controllers/CatalogRuleController.php
index e53d2b633..9fc8427ad 100644
--- a/packages/Webkul/Discount/src/Http/Controllers/CatalogRuleController.php
+++ b/packages/Webkul/Discount/src/Http/Controllers/CatalogRuleController.php
@@ -49,6 +49,11 @@ class CatalogRuleController extends Controller
*/
protected $appliedConfig;
+ /**
+ * Property for catalog rule application
+ */
+ protected $appliedConditions;
+
/**
* To hold the catalog repository instance
*/
@@ -62,6 +67,8 @@ class CatalogRuleController extends Controller
$this->category = $category;
$this->product = $product;
$this->catalogRule = $catalogRule;
+ $this->appliedConfig = config('pricerules.catalog');
+ $this->appliedConditions = config('pricerules.conditions');
}
public function index()
@@ -71,7 +78,7 @@ class CatalogRuleController extends Controller
public function create()
{
- return view($this->_config['view'])->with('criteria', [$this->attribute->getPartial(), $this->category->getPartial()]);
+ return view($this->_config['view'])->with('criteria', [$this->attribute->getPartial(), $this->category->getPartial(), $this->fetchOptionableAttributes(), $this->appliedConfig, $this->appliedConditions]);
}
public function store()
@@ -87,15 +94,28 @@ class CatalogRuleController extends Controller
'ends_till' => 'required|date',
'priority' => 'required|numeric',
'criteria' => 'required',
- 'apply' => 'required|numeric|min:1|max:4'
+ 'all_conditions' => 'required|array',
+ 'apply' => 'required|numeric|min:0|max:3'
]);
- dd(request()->all());
- $catalogRule = $this->catalogRule->create(request()->all());
+ $data = request()->all();
+ $data['status'] = 1;
+
+ dd($data);
+
+ $catalogRule = $this->catalogRule->create($data);
}
- public function fetchAttributeOptions()
+ public function fetchOptionableAttributes()
{
- return [request()->all()];
+ $attributesWithOptions = array();
+
+ foreach($this->attribute->all() as $attribute) {
+ if (($attribute->type == 'select' || $attribute->type == 'multiselect') && $attribute->code != 'tax_category_id') {
+ $attributesWithOptions[$attribute->admin_name] = $attribute->options->toArray();
+ }
+ }
+
+ return $attributesWithOptions;
}
}
\ No newline at end of file
diff --git a/packages/Webkul/Discount/src/Providers/DiscountServiceProvider.php b/packages/Webkul/Discount/src/Providers/DiscountServiceProvider.php
index a2e1bbec7..a51ba75b1 100644
--- a/packages/Webkul/Discount/src/Providers/DiscountServiceProvider.php
+++ b/packages/Webkul/Discount/src/Providers/DiscountServiceProvider.php
@@ -33,7 +33,7 @@ class DiscountServiceProvider extends ServiceProvider
protected function registerConfig()
{
$this->mergeConfigFrom(
- dirname(__DIR__) . '/Config/cart-attributes.php', 'pricerules'
+ dirname(__DIR__) . '/Config/rule-conditions.php', 'pricerules'
);
}
}
\ No newline at end of file