Removed old migrations of catalog rule and removed a bug in convertXToProductId
This commit is contained in:
parent
a9994a3143
commit
bcdec8ec5a
|
|
@ -351,7 +351,7 @@
|
|||
<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') }}</label>
|
||||
<label class="mb-10" for="attributes">{{ __('admin::app.promotion.select-attribute', ['attribute' => 'Attribute']) }}</label>
|
||||
|
||||
<br/>
|
||||
|
||||
|
|
|
|||
|
|
@ -320,13 +320,13 @@
|
|||
<div class="control-group" :class="[errors.has('prefix') ? 'has-error' : '']">
|
||||
<label for="prefix" class="required">{{ __('admin::app.promotion.general-info.prefix') }}</label>
|
||||
|
||||
<input type="text" class="control" name="prefix" v-model="prefix" value="{{ old('prefix') }}" data-vv-as=""Prefix"">
|
||||
<input type="text" class="control" name="prefix" v-model="prefix" value="{{ old('prefix') }}" data-vv-as=""{{ __('admin::app.promotion.general-info.prefix') }}"">
|
||||
|
||||
<span class="control-error" v-if="errors.has('prefix')">@{{ errors.first('prefix') }}</span>
|
||||
</div>
|
||||
|
||||
<div class="control-group" :class="[errors.has('suffix') ? 'has-error' : '']"">
|
||||
<label for="suffix" class="required">Suffix</label>
|
||||
<label for="suffix" class="required">{{ __('admin::app.promotion.general-info.suffix') }}</label>
|
||||
|
||||
<input type="text" class="control" name="suffix" v-model="suffix" value="{{ old('suffix') }}" data-vv-as=""suffix"">
|
||||
|
||||
|
|
@ -338,7 +338,7 @@
|
|||
<div class="control-group" :class="[errors.has('code') ? 'has-error' : '']">
|
||||
<label for="code" class="required">{{ __('admin::app.promotion.general-info.code') }}</label>
|
||||
|
||||
<input type="text" class="control" name="code" v-model="code" v-validate="'required'" value="{{ old('code') }}" data-vv-as=""Code"">
|
||||
<input type="text" class="control" name="code" v-model="code" v-validate="'required'" value="{{ old('code') }}" data-vv-as=""{{ __('admin::app.promotion.general-info.code') }}"">
|
||||
|
||||
<span class="control-error" v-if="errors.has('code')">@{{ errors.first('code') }}</span>
|
||||
</div>
|
||||
|
|
@ -359,16 +359,16 @@
|
|||
<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>
|
||||
<multiselect v-model="category_values" :close-on-select="false" :options="category_options" :searchable="false" :custom-label="categoryLabel" :show-labels="true" placeholder="{{ __('admin::app.promotion.select-attribute', ['attribute' => 'Categories']) }}" track-by="slug" :multiple="true"></multiselect>
|
||||
</div>
|
||||
|
||||
<label class="mb-10" for="attributes">{{ __('admin::app.promotion.select-attribute') }}</label>
|
||||
<label class="mb-10" for="attributes">{{ __('admin::app.promotion.select-attribute', ['attribute' => 'Option']) }}</label>
|
||||
|
||||
<br/>
|
||||
|
||||
<div class="control-container mt-20" v-for="(condition, index) in attribute_values" :key="index">
|
||||
<select class="control" v-model="attribute_values[index].attribute" title="You Can Make Multiple Selections Here" style="margin-right: 15px; width: 30%;" v-on:change="enableAttributeCondition($event, index)">
|
||||
<option disabled="disabled">{{ __('admin::app.promotion.select-option') }}</option>
|
||||
<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>
|
||||
|
|
@ -396,7 +396,7 @@
|
|||
<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>
|
||||
<span class="btn btn-primary btn-lg mt-20" v-on:click="addAttributeCondition">{{ __('admin::app.promotion.add-attr-condition') }}</span>
|
||||
</div>
|
||||
</accordian>
|
||||
|
||||
|
|
|
|||
|
|
@ -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'
|
||||
]
|
||||
]
|
||||
],
|
||||
]
|
||||
];
|
||||
|
|
@ -1,45 +0,0 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class CreateCatalogRulesTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create('catalog_rules', function (Blueprint $table) {
|
||||
$table->increments('id');
|
||||
$table->string('name')->nullable();
|
||||
$table->string('description')->nullable();
|
||||
$table->boolean('is_guest')->default(0);
|
||||
$table->datetime('starts_from')->nullable();
|
||||
$table->datetime('ends_till')->nullable();
|
||||
$table->boolean('status')->default(0);
|
||||
$table->integer('priority')->unsigned()->default(0);
|
||||
$table->json('conditions')->nullable();
|
||||
$table->string('test_mode')->nullable();
|
||||
$table->json('actions')->nullable();
|
||||
$table->boolean('end_other_rules')->default(0);
|
||||
$table->integer('sort_order')->unsigned()->default(0);
|
||||
$table->string('action_type')->nullable();
|
||||
$table->decimal('disc_amount', 12, 4)->default(0);
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::dropIfExists('catalog_rules');
|
||||
}
|
||||
}
|
||||
|
|
@ -1,42 +0,0 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class CreateCatalogRuleProductsTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create('catalog_rule_products', function (Blueprint $table) {
|
||||
$table->increments('id');
|
||||
$table->integer('catalog_rule_id')->unsigned()->unique();
|
||||
$table->foreign('catalog_rule_id')->references('id')->on('catalog_rules')->onDelete('cascade');
|
||||
$table->integer('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');
|
||||
}
|
||||
}
|
||||
|
|
@ -1,35 +0,0 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class CreateCatalogRuleCustomerGroupsTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create('catalog_rule_customer_groups', function (Blueprint $table) {
|
||||
$table->increments('id');
|
||||
$table->integer('catalog_rule_id')->unsigned();
|
||||
$table->foreign('catalog_rule_id')->references('id')->on('catalog_rules')->onDelete('cascade');
|
||||
$table->integer('customer_group_id')->unsigned();
|
||||
$table->foreign('customer_group_id')->references('id')->on('customer_groups')->onDelete('cascade');
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::dropIfExists('catalog_rule_customer_groups');
|
||||
}
|
||||
}
|
||||
|
|
@ -1,35 +0,0 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class CreateCatalogRuleChannelsTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create('catalog_rule_channels', function (Blueprint $table) {
|
||||
$table->increments('id');
|
||||
$table->integer('catalog_rule_id')->unsigned();
|
||||
$table->foreign('catalog_rule_id')->references('id')->on('catalog_rules')->onDelete('cascade');
|
||||
$table->integer('channel_id')->unsigned();
|
||||
$table->foreign('channel_id')->references('id')->on('channels')->onDelete('cascade');
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::dropIfExists('catalog_rule_channels');
|
||||
}
|
||||
}
|
||||
|
|
@ -1,36 +0,0 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class CreateCatalogRuleProductsPriceTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create('catalog_rule_products_price', function (Blueprint $table) {
|
||||
$table->increments('id');
|
||||
$table->integer('cart_rule_product_id')->unsigned();
|
||||
$table->foreign('cart_rule_product_id')->references('id')->on('cart_rules')->onDelete('cascade');
|
||||
$table->datetime('starts_from')->nullable();
|
||||
$table->datetime('ends_till')->nullable();
|
||||
$table->decimal('price', 12, 4)->default(0.0000);
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::dropIfExists('cart_rule_products_price');
|
||||
}
|
||||
}
|
||||
|
|
@ -1,28 +0,0 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class CreateCatalogRuleProductsPrice extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
|
|
@ -42,6 +42,11 @@ class ConvertXToProductId
|
|||
*/
|
||||
protected $pav;
|
||||
|
||||
/**
|
||||
* Condition symbols for matching the criteria with attributes selected
|
||||
*/
|
||||
protected $symbols;
|
||||
|
||||
public function __construct(
|
||||
Category $category,
|
||||
Attribute $attribute,
|
||||
|
|
@ -62,6 +67,8 @@ class ConvertXToProductId
|
|||
$this->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);
|
||||
|
|
|
|||
Loading…
Reference in New Issue