diff --git a/packages/Webkul/Admin/src/Resources/views/promotions/cart-rule/create.blade.php b/packages/Webkul/Admin/src/Resources/views/promotions/cart-rule/create.blade.php
index def9eaee2..3ec908d17 100644
--- a/packages/Webkul/Admin/src/Resources/views/promotions/cart-rule/create.blade.php
+++ b/packages/Webkul/Admin/src/Resources/views/promotions/cart-rule/create.blade.php
@@ -351,7 +351,7 @@
-
+
diff --git a/packages/Webkul/Admin/src/Resources/views/promotions/cart-rule/edit.blade.php b/packages/Webkul/Admin/src/Resources/views/promotions/cart-rule/edit.blade.php
index b9abf4378..8fe242947 100644
--- a/packages/Webkul/Admin/src/Resources/views/promotions/cart-rule/edit.blade.php
+++ b/packages/Webkul/Admin/src/Resources/views/promotions/cart-rule/edit.blade.php
@@ -320,13 +320,13 @@
-
+
@{{ errors.first('prefix') }}
-
+
@@ -338,7 +338,7 @@
-
+
@{{ errors.first('code') }}
@@ -359,16 +359,16 @@
-
+
-
+
@@ -396,7 +396,7 @@
-
Add Attribute Condition
+
{{ __('admin::app.promotion.add-attr-condition') }}
diff --git a/packages/Webkul/Discount/src/Config/rule-conditions.php b/packages/Webkul/Discount/src/Config/rule-conditions.php
index 5974af80a..84843d953 100644
--- a/packages/Webkul/Discount/src/Config/rule-conditions.php
+++ b/packages/Webkul/Discount/src/Config/rule-conditions.php
@@ -34,14 +34,15 @@ return [
'actions' => [
'percent_of_product' => 'Percentage of product',
'fixed_amount' => 'Apply as fixed amount',
- // 'buy_a_get_b' => 'Buy A get B'
+ 'adjust_to_percent' => 'Adjust whole cart to percent',
+ 'adjust_to_fixed_amount' => 'Adjust whole cart to fixed amount'
],
'validation' => [
0 => 'percent_of_product',
1 => 'fixed_amount',
- 2 => 'buy_a_get_b',
- // 3 => 'fixed_amount_cart'
+ 2 => 'adjust_to_percent',
+ 3 => 'adjust_to_fixed_amount'
],
'conditions' => [
@@ -66,6 +67,18 @@ return [
'boolean' => [
0 => 'True/Yes',
1 => 'False/No'
+ ],
+
+ 'symbols' => [
+ '=' => 'equals',
+ '>=' => 'greater_or_equals',
+ '<=' => 'lesser_or_equals',
+ '>' => 'greater_than',
+ '<' => 'lesser_than',
+ '{}' => 'contains',
+ '={}' => 'is_one_f',
+ '!={}' => 'is_not_one_of',
+ '!{}' => 'does_not_contains'
]
],
@@ -120,41 +133,54 @@ return [
'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'
+ 'percent_of_product' => 'Percentage of product',
+ 'fixed_amount' => 'Apply as fixed amount',
+ 'adjust_to_percent' => 'Adjust price to percentage',
+ 'adjust_to_fixed_amount' => 'Adjust price to given amount'
],
- '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'
- ]
+ 'validation' => [
+ 0 => 'percent_of_product',
+ 1 => 'fixed_amount',
+ 2 => 'buy_a_get_b',
+ 3 => 'fixed_amount_cart'
+ ],
+
+ 'conditions' => [
+ 'numeric' => [
+ '=' => 'Equals',
+ '>=' => 'Greater or equals',
+ '<=' => 'Lesser or equals',
+ '>' => 'Greater than',
+ '<' => 'Lesser than',
+ ],
+
+ 'string' => [
+ '=' => 'Equals',
+ // '>=' => 'Greater or equals',
+ // '<=' => 'Lesser or equals',
+ // '>' => 'Greater than',
+ // '<' => 'Lesser than',
+ '{}' => 'Contains',
+ '!{}' => 'Does not contains'
+ ],
+
+ 'boolean' => [
+ 0 => 'True/Yes',
+ 1 => 'False/No'
+ ],
+
+ 'symbols' => [
+ '=' => 'equals',
+ '>=' => 'greater_or_equals',
+ '<=' => 'lesser_or_equals',
+ '>' => 'greater_than',
+ '<' => 'lesser_than',
+ '{}' => 'contains',
+ '={}' => 'is_one_f',
+ '!={}' => 'is_not_one_of',
+ '!{}' => 'does_not_contains'
+ ]
]
- ],
+ ]
];
\ 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
deleted file mode 100644
index bf3c0f952..000000000
--- a/packages/Webkul/Discount/src/Database/Migrations/2019_05_07_184255_create_catalog_rules_table.php
+++ /dev/null
@@ -1,45 +0,0 @@
-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->timestamps();
- });
- }
-
- /**
- * Reverse the migrations.
- *
- * @return void
- */
- public function down()
- {
- Schema::dropIfExists('catalog_rules');
- }
-}
diff --git a/packages/Webkul/Discount/src/Database/Migrations/2019_05_07_184348_create_catalog_rule_products_table.php b/packages/Webkul/Discount/src/Database/Migrations/2019_05_07_184348_create_catalog_rule_products_table.php
deleted file mode 100644
index 522242778..000000000
--- a/packages/Webkul/Discount/src/Database/Migrations/2019_05_07_184348_create_catalog_rule_products_table.php
+++ /dev/null
@@ -1,42 +0,0 @@
-increments('id');
- $table->integer('catalog_rule_id')->unsigned()->unique();
- $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->integer('customer_group_id')->unsigned();
- $table->foreign('customer_group_id')->references('id')->on('customer_groups')->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');
- }
-}
\ No newline at end of file
diff --git a/packages/Webkul/Discount/src/Database/Migrations/2019_05_09_125143_create_catalog_rule_customer_groups_table.php b/packages/Webkul/Discount/src/Database/Migrations/2019_05_09_125143_create_catalog_rule_customer_groups_table.php
deleted file mode 100644
index ada1be1dc..000000000
--- a/packages/Webkul/Discount/src/Database/Migrations/2019_05_09_125143_create_catalog_rule_customer_groups_table.php
+++ /dev/null
@@ -1,35 +0,0 @@
-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');
- }
-}
\ No newline at end of file
diff --git a/packages/Webkul/Discount/src/Database/Migrations/2019_05_09_125201_create_catalog_rule_channels_table.php b/packages/Webkul/Discount/src/Database/Migrations/2019_05_09_125201_create_catalog_rule_channels_table.php
deleted file mode 100644
index f558e36be..000000000
--- a/packages/Webkul/Discount/src/Database/Migrations/2019_05_09_125201_create_catalog_rule_channels_table.php
+++ /dev/null
@@ -1,35 +0,0 @@
-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');
- }
-}
diff --git a/packages/Webkul/Discount/src/Database/Migrations/2019_05_13_024443_create_catalog_rule_products_price_table.php b/packages/Webkul/Discount/src/Database/Migrations/2019_05_13_024443_create_catalog_rule_products_price_table.php
deleted file mode 100644
index 0c051fdc8..000000000
--- a/packages/Webkul/Discount/src/Database/Migrations/2019_05_13_024443_create_catalog_rule_products_price_table.php
+++ /dev/null
@@ -1,36 +0,0 @@
-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');
- }
-}
diff --git a/packages/Webkul/Discount/src/Database/Migrations/2019_05_30_142521_create_catalog_rule_products_price.php b/packages/Webkul/Discount/src/Database/Migrations/2019_05_30_142521_create_catalog_rule_products_price.php
deleted file mode 100644
index 1f1616a88..000000000
--- a/packages/Webkul/Discount/src/Database/Migrations/2019_05_30_142521_create_catalog_rule_products_price.php
+++ /dev/null
@@ -1,28 +0,0 @@
-cartRule = $cartRule;
$this->pav = $pav;
+
+ $this->conditionSymbols = config('pricerules.cart.conditions.symbols');
}
public function convertX($ruleId, $attribute_conditions)
@@ -110,31 +117,27 @@ class ConvertXToProductId
$products = collect();
foreach ($attributeOptions as $attributeOption) {
- if ($attributeOption->attribute == 'sku' || $attributeOption->attribute == 'type') {
- continue;
- }
-
$selectedOptions = $attributeOption->value;
if ($attributeOption->type == 'select' || $attributeOption->type == 'multiselect') {
- $pav = $this->attribute->findWhere([
+ $attribute = $this->attribute->findWhere([
'code' => $attributeOption->attribute
]);
- $pavOptions = $pav->first()->options;
+ $attributeOptions = $attribute->first()->options;
$selectedAttributeOptions = collect();
- foreach ($pavOptions as $pavOption) {
+ foreach ($attributeOptions as $attributeOption) {
foreach ($selectedOptions as $key => $value) {
- if ($pavOption->id == $value) {
- $selectedAttributeOptions->push($pavOption);
+ if ($attributeOption->id == $value) {
+ $selectedAttributeOptions->push($attributeOption);
}
}
}
foreach($selectedAttributeOptions as $selectedAttributeOption) {
- $typeColumn = $this->pav::$attributeTypeFields[$pav->first()->type];
+ $typeColumn = $this->pav::$attributeTypeFields[$attribute->first()->type];
$pavResults = $this->pav->where(
"{$typeColumn}", $selectedAttributeOption->id
@@ -146,35 +149,39 @@ class ConvertXToProductId
}
}
} else {
- $pav = $this->attribute->findWhere([
+ $attribute = $this->attribute->findWhere([
'code' => $attributeOption->attribute
]);
- $pavValues = $pav->first();
+ $pavValues = $attribute->first();
- dd($pavValues);
+ $selectedAttributeValues = collect();
- // $selectedAttributeValues = collect();
+ if ($attributeOption->attribute == 'sku') {
+ $testValue = $attributeOption->value;
+ $testCondition = $attributeOption->condition;
- // foreach ($pavValues as $pavValue) {
- // foreach ($selectedValues as $key => $value) {
- // if ($pavValue->id == $value) {
- // $selectedAttributeValues->push($pavValue);
- // }
- // }
- // }
+ if ($testCondition == '{}') {
+ $foundProducts = $this->product->findWhere([
+ ['sku', 'like', '%'.$testValue.'%'],
+ ['type', '!=', 'configurable']
+ ])->flatten()->all();
+ } else if ($testCondition == '!{}') {
+ $foundProducts = $this->product->findWhere([
+ ['sku', 'not like', '%'.$testValue.'%'],
+ ['type', '!=', 'configurable']
+ ])->flatten()->all();
+ } else if ($testCondition == '=') {
+ $foundProducts = $this->product->findWhere([
+ ['sku', '=', '%'.$testValue.'%'],
+ ['type', '!=', 'configurable']
+ ])->flatten()->all();
+ }
+ }
- // foreach($selectedAttributeValues as $selectedAttributeValue) {
- // $typeColumn = $this->pav::$attributeTypeFields[$pav->first()->type];
-
- // $pavResults = $this->pav->where(
- // "{$typeColumn}", $selectedAttributeValue->id
- // )->get();
-
- // foreach ($pavResults as $pavResult) {
- // $products->push($pavResult->product);
- // }
- // }
+ foreach($foundProducts as $foundProduct) {
+ $products->push($foundProduct);
+ }
}
}
@@ -206,8 +213,8 @@ class ConvertXToProductId
*/
public function findAllUniqueIds(...$data)
{
- $attributeResult = $data[0];
- $categoryResult = $data[1];
+ $attributeResult = $data[0] ?? collect();
+ $categoryResult = $data[1] ?? collect();
// find matched attribute options product ids
$mergedCollection = $attributeResult->merge($categoryResult);