Catalog rule implementation in progress

This commit is contained in:
Prashant Singh 2019-08-12 06:56:21 +05:30
parent 06a4f1216b
commit da093662db
19 changed files with 562 additions and 158 deletions

View File

@ -136,7 +136,11 @@
<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;">
<select v-show='attribute_values[index].type == "select" || attribute_values[index].type == "multiselect"' class="control" v-model="attribute_values[index].condition" style="margin-right: 15px;">
<option v-for="(condition, index) in conditions.select" :value="index" :key="index">@{{ condition }}</option>
</select>
<select v-show='attribute_values[index].type == "text" || attribute_values[index].type == "textarea" || attribute_values[index].type == "price"' 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>
@ -159,7 +163,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>
@ -256,6 +260,7 @@
},
mounted () {
console.log(this.attribute_input);
},
methods: {
@ -336,6 +341,7 @@
for(i in this.attribute_input) {
if (i == selectedIndex) {
if (this.attribute_input[i].has_options == true) {
this.selectedIndex
this.attribute_values[index].options = this.attribute_input[i].options;
}
@ -355,7 +361,7 @@
},
removeAttr(index) {
this.conditions_list.splice(index, 1);
this.attribute_values.splice(index, 1);
},
removeCat(index) {

View File

@ -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.store') }}" @submit.prevent="onSubmit">
<form method="POST" action="{{ route('admin.catalog-rule.update', $catalog_rule[5]->id) }}" @submit.prevent="onSubmit">
@csrf
<div class="page-header">
@ -91,7 +91,11 @@
<span class="control-error" v-if="errors.has('status')">@{{ errors.first('status') }}</span>
</div>
<datetime :name="starts_from">
@php
$now = new \Carbon\Carbon();
@endphp
<date :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>
@ -99,9 +103,9 @@
<span class="control-error" v-if="errors.has('starts_from')">@{{ errors.first('starts_from') }}</span>
</div>
</datetime>
</date>
<datetime :name="starts_from">
<date :name="starts_from">
<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>
@ -109,7 +113,7 @@
<span class="control-error" v-if="errors.has('ends_till')">@{{ errors.first('ends_till') }}</span>
</div>
</datetime>
</date>
</div>
</accordian>
@ -136,7 +140,11 @@
<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;">
<select v-show='attribute_values[index].type == "select" || attribute_values[index].type == "multiselect"' class="control" v-model="attribute_values[index].condition" style="margin-right: 15px;">
<option v-for="(condition, index) in conditions.select" :value="index" :key="index">@{{ condition }}</option>
</select>
<select v-show='attribute_values[index].type == "text" || attribute_values[index].type == "textarea" || attribute_values[index].type == "price"' 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>
@ -159,7 +167,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>
@ -235,7 +243,7 @@
category_options: @json($catalog_rule[1]),
category_values: [],
conditions: @json($catalog_rule[5]).conditions,
conditions: @json($catalog_rule[3]).conditions,
attribute_values: [],
attr_object: {
attribute: null,
@ -243,11 +251,12 @@
value: [],
options: []
},
attribute_input: @json($catalog_rule[3])
attribute_input: @json($catalog_rule[0])
}
},
mounted () {
console.log(this.conditions)
channels = @json($catalog_rule[5]->channels);
this.channels = [];
@ -292,6 +301,18 @@
},
methods: {
created() {
VeeValidate.Validator.extend('is_time', {
getMessage: field => `The format must be HH:MM:SS`,
validate: (value) => new Promise(resolve => {
let regex = new RegExp("([0-1][0-9]|2[0-3]):([0-5][0-9]):([0-5][0-9])");
resolve({
valid: value && regex.test(value)
});
})
});
},
categoryLabel (option) {
return option.name + ' [ ' + option.slug + ' ]';
},
@ -321,6 +342,8 @@
}
this.attribute_values[index].type = this.attribute_input[i].type;
debugger
}
}
},
@ -336,7 +359,7 @@
},
removeAttr(index) {
this.conditions_list.splice(index, 1);
this.attribute_values.splice(index, 1);
},
removeCat(index) {

View File

@ -13,7 +13,7 @@ use Hash;
/**
* Customer controlller for the customer basically for the tasks of customers which will be done after customer authentication.
*
* @author Prashant Singh <prashant.singh852@webkul.com>
* @author Prashant Singh <prashant.singh852@webkul.com>
* @copyright 2018 Webkul Software Pvt Ltd (http://www.webkul.com)
*/
class CustomerController extends Controller

View File

@ -133,10 +133,22 @@ return [
'string' => [
'=' => 'Equals',
// '>=' => 'Greater or equals',
// '<=' => 'Lesser or equals',
// '>' => 'Greater than',
// '<' => 'Lesser than',
'>=' => 'Greater or equals',
'<=' => 'Lesser or equals',
'>' => 'Greater than',
'<' => 'Lesser than',
'{}' => 'Contains',
'!{}' => 'Does not contains'
],
'select' => [
'=' => 'Equals',
'{}' => 'Contains',
'!{}' => 'Does not contains'
],
'multiselect' => [
'=' => 'Equals',
'{}' => 'Contains',
'!{}' => 'Does not contains'
],

View File

@ -1,6 +1,6 @@
<?php
namespace Webkul\Discount\Helpers;
namespace Webkul\Discount\Helpers\Cart;
use Webkul\Discount\Repositories\CartRuleRepository as CartRule;
use Webkul\Attribute\Repositories\AttributeRepository as Attribute;
@ -8,7 +8,6 @@ use Webkul\Attribute\Repositories\AttributeOptionRepository as AttributeOption;
use Webkul\Category\Repositories\CategoryRepository as Category;
use Webkul\Product\Repositories\ProductRepository as Product;
use Webkul\Product\Models\ProductAttributeValue as ProductAttributeValue;
use DB;
class ConvertXToProductId
{
@ -284,13 +283,9 @@ class ConvertXToProductId
$qb->where('product_categories.category_id', $categoryId);
}
if (is_null(request()->input('status'))) {
$qb->where('product_flat.status', 1);
}
$qb->where('product_flat.status', 1);
if (is_null(request()->input('visible_individually'))) {
$qb->where('product_flat.visible_individually', 1);
}
$qb->where('product_flat.visible_individually', 1);
$queryBuilder = $qb->leftJoin('product_flat as flat_variants', function($qb) use($channel, $locale) {
$qb->on('product_flat.id', '=', 'flat_variants.parent_id');

View File

@ -1,10 +1,8 @@
<?php
namespace Webkul\Discount\Helpers;
namespace Webkul\Discount\Helpers\Cart;
use Webkul\Discount\Helpers\Discount;
use Carbon\Carbon;
use Cart;
class CouponAbleRule extends Discount

View File

@ -1,6 +1,6 @@
<?php
namespace Webkul\Discount\Helpers;
namespace Webkul\Discount\Helpers\Cart;
use Webkul\Discount\Repositories\CartRuleRepository as CartRule;
use Webkul\Checkout\Repositories\CartItemRepository as CartItem;
@ -283,30 +283,6 @@ abstract class Discount
return $maxImpact;
}
/**
* To find oldest rule
*
* @param Collection $rules
*
* @return Collection $rule
*/
public function findOldestRule($rules)
{
$leastId = 0;
if ($rules->count()) {
$leastId = $rules->min('id');
foreach ($rules as $rule) {
if ($rule->id == $leastId) {
return $rule;
}
}
} else {
return collect();
}
}
/**
* To calculate the impact of the rule
*
@ -350,6 +326,23 @@ abstract class Discount
$channelBased = false;
// time based constraints
if ($rule->starts_from != null && $rule->ends_till == null) {
if (Carbon::parse($rule->starts_from) < now()) {
$timeBased = true;
}
} else if ($rule->starts_from == null && $rule->ends_till != null) {
if (Carbon::parse($rule->ends_till) > now()) {
$timeBased = true;
}
} else if ($rule->starts_from != null && $rule->ends_till != null) {
if (Carbon::parse($rule->starts_from) < now() && now() < Carbon::parse($rule->ends_till)) {
$timeBased = true;
}
} else {
$timeBased = true;
}
// channel based constraints
foreach ($rule->channels as $channel) {
if ($channel->channel_id == core()->getCurrentChannel()->id) {
@ -407,7 +400,7 @@ abstract class Discount
}
}
if ($channelBased && $customerGroupBased && $conditionsBased) {
if ($channelBased && $customerGroupBased && $timeBased && $conditionsBased) {
if ($rule->uses_attribute_conditions == 1 && $partialMatch) {
return true;
} else if ($rule->uses_attribute_conditions == 0) {

View File

@ -1,10 +1,8 @@
<?php
namespace Webkul\Discount\Helpers;
namespace Webkul\Discount\Helpers\Cart;
use Webkul\Discount\Helpers\Discount;
use Webkul\Discount\Repositories\CartRuleCartRepository as CartRuleCart;
use Cart;
class NonCouponAbleRule extends Discount
{

View File

@ -1,6 +1,6 @@
<?php
namespace Webkul\Discount\Helpers;
namespace Webkul\Discount\Helpers\Cart;
use Webkul\Discount\Helpers\Discount;
use Webkul\Discount\Repositories\CartRuleCartRepository as CartRuleCart;

View File

@ -0,0 +1,68 @@
<?php
namespace Webkul\Discount\Helpers\Catalog;
use Webkul\Discount\Repositories\CatalogRuleRepository as CatalogRule;
use Webkul\Discount\Helpers\Catalog\Sale;
class Apply extends Sale
{
/**
* To hold the catalog rule repository instance
*/
protected $catalogRule;
/**
* To maintain the list of deceased rules and remove their records if present
*/
protected $activeRules;
/**
* To maintain the list of deceased rules and remove their records if present
*/
protected $deceased;
/**
* To hold the rule classes
*/
protected $rules;
/**
* @param CatalogRule $catalogRule
*/
public function __construct(CatalogRule $catalogRule)
{
$this->catalogRule = $catalogRule;
$this->active = collect();
$this->deceased = collect();
$this->rules = config('discount-rules.catalog');
}
/**
* To apply the new catalog rules and sync previous rules changes,
*/
public function apply()
{
$rules = $this->catalogRule->all();
foreach ($rules as $rule) {
$validated = $this->checkApplicability($rule);
if ($validated) {
$this->active->push($rule->id);
// Job execution for active rules
$products = $this->getProductIds($rule);
$this->setSalePrice($products);
} else {
$this->deceased->push($rule->id);
// Job execution for deceased rules
}
}
}
}

View File

@ -0,0 +1,272 @@
<?php
namespace Webkul\Discount\Helpers\Catalog;
use Webkul\Discount\Repositories\CatalogRuleRepository as CatalogRule;
use Webkul\Attribute\Repositories\AttributeRepository as Attribute;
use Webkul\Attribute\Repositories\AttributeOptionRepository as AttributeOption;
use Webkul\Category\Repositories\CategoryRepository as Category;
use Webkul\Product\Repositories\ProductRepository as Product;
use Webkul\Product\Models\ProductAttributeValue as ProductAttributeValue;
class ConvertXToProductId
{
/**
* CategoryRepository instance
*/
protected $category;
/**
* AttributeRepository instance
*/
protected $attribute;
/**
* ProductRepository instance
*/
protected $product;
/**
* AttributeOptionRepository instance
*/
protected $attributeOption;
/**
* CatalogRuleRepository instance
*/
protected $catalogRule;
/**
* ProductAttributeValueRepository instance
*/
protected $pav;
/**
* Condition symbols for matching the criteria with attributes selected
*/
protected $symbols;
public function __construct(
Category $category,
Attribute $attribute,
Product $product,
AttributeOption $attributeOption,
CatalogRule $catalogRule,
ProductAttributeValue $pav
) {
$this->category = $category;
$this->attribute = $attribute;
$this->product = $product;
$this->attributeOption = $attributeOption;
$this->catalogRule = $catalogRule;
$this->pav = $pav;
$this->conditionSymbols = config('pricerules.cart.conditions.symbols');
}
public function convertX($attribute_conditions)
{
$attributeConditions = json_decode($attribute_conditions);
$categoryValues = $attributeConditions->categories;
$attributeValues = $attributeConditions->attributes;
if (!isset($categoryValues) && !isset($attributeValues)) {
return false;
}
$categoryResult = collect();
if (isset($categoryValues) && count($categoryValues)) {
$categoryResult = $this->convertFromCategories($categoryValues);
}
$attributeResult = collect();
if (isset($attributeValues) && count($attributeValues)) {
$attributeResult = $this->convertFromAttributes($attributeValues);
}
// now call the function that will find all the unique product ids
$productIDs = $this->findAllUniqueIds($attributeResult, $categoryResult);
return $productIDs;
}
/**
* This method will return product id from the attribute and attribute option params
*
* @return array
*/
public function convertFromAttributes($attributeOptions)
{
$products = collect();
foreach ($attributeOptions as $attributeOption) {
$selectedOptions = $attributeOption->value;
if ($attributeOption->type == 'select' || $attributeOption->type == 'multiselect') {
$attribute = $this->attribute->findWhere([
'code' => $attributeOption->attribute
]);
$attributeOptions = $attribute->first()->options;
$selectedAttributeOptions = collect();
foreach ($attributeOptions as $attributeOption) {
foreach ($selectedOptions as $key => $value) {
if ($attributeOption->id == $value) {
$selectedAttributeOptions->push($attributeOption);
}
}
}
foreach ($selectedAttributeOptions as $selectedAttributeOption) {
$typeColumn = $this->pav::$attributeTypeFields[$attribute->first()->type];
$pavResults = $this->pav->where(
"{$typeColumn}",
$selectedAttributeOption->id
)->get();
foreach ($pavResults as $pavResult) {
if ($pavResult->product->type == 'simple')
$products->push($pavResult->product);
}
}
} else {
$attribute = $this->attribute->findWhere([
'code' => $attributeOption->attribute
]);
$pavValues = $attribute->first();
$selectedAttributeValues = collect();
if ($attributeOption->attribute == 'sku') {
$testValue = $attributeOption->value;
$testCondition = $attributeOption->condition;
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 ($foundProducts as $foundProduct) {
$products->push($foundProduct);
}
}
}
return $products;
}
/**
* This method will return product id from the attribute and attribute option params
*
* @param Collection $categories
*
* @return array
*/
public function convertFromCategories($categories)
{
$products = collect();
foreach ($categories as $category) {
$data = $this->getAll($category->id);
if ($data->count()) {
$products->push($data);
unset($data);
}
}
return $products->flatten()->all();
}
/**
* This method will remove the duplicates from the array and merge all the items into single array
*
* @param array
*
* @return array
*/
public function findAllUniqueIds(...$data)
{
$attributeResult = $data[0] ?? collect();
$categoryResult = $data[1] ?? collect();
// find matched attribute options product ids
$mergedCollection = $attributeResult->merge($categoryResult);
$productIDs = collect();
foreach ($mergedCollection as $merged) {
$productIDs->push($merged->id);
}
// find all the unique product ids
$productIDs = $productIDs->unique();
return $productIDs->flatten()->all();
}
/**
* To get all product ids lying in the criteria
*
* @param integer $categoryId
*
* @return Collection
*/
public function getAll($categoryId = null)
{
$results = app('Webkul\Product\Repositories\ProductFlatRepository')->scopeQuery(function ($query) use ($categoryId) {
$channel = request()->get('channel') ?: (core()->getCurrentChannelCode() ?: core()->getDefaultChannelCode());
$locale = request()->get('locale') ?: app()->getLocale();
$qb = $query->distinct()
->select('products.id')
->leftJoin('products', 'product_flat.product_id', '=', 'products.id')
->leftJoin('product_categories', 'products.id', '=', 'product_categories.product_id')
->where('products.type', '!=', 'configurable')
->whereNotNull('product_flat.url_key');
if ($categoryId) {
$qb->where('product_categories.category_id', $categoryId);
}
$qb->where('product_flat.status', 1);
$qb->where('product_flat.visible_individually', 1);
$queryBuilder = $qb->leftJoin('product_flat as flat_variants', function ($qb) use ($channel, $locale) {
$qb->on('product_flat.id', '=', 'flat_variants.parent_id');
});
return $qb->groupBy('product_flat.id');
})->get();
return $results;
}
}

View File

@ -0,0 +1,107 @@
<?php
namespace Webkul\Discount\Helpers\Catalog;
use Webkul\Discount\Repositories\CatalogRepository as CatalogRule;
use Webkul\Discount\Helpers\Catalog\ConvertXToProductId;
abstract class Sale
{
/**
* To hold the catalog rule repository instance
*/
protected $catalogRule;
/**
* ConvertXToProductId instance
*/
protected $convertX;
/**
* To hold the rule classes
*/
protected $rules;
/**
* @param CatalogRule $catalogRule
*/
public function __construct(CatalogRule $catalogRule, ConvertXToProductId $convertX)
{
$this->catalogRule = $catalogRule;
$this->convertX = $convertX;
$this->rules = config('discount-rules.catalog');
}
abstract function apply();
/**
* To validate rule
*
* @param CatalogRule $rule
*
* @return Boolean
*/
public function checkApplicability($rule)
{
$cart = \Cart::getCart();
$timeBased = false;
$status = false;
// time based constraints
if ($rule->starts_from != null && $rule->ends_till == null) {
if (Carbon::parse($rule->starts_from) < now()) {
$timeBased = true;
}
} else if ($rule->starts_from == null && $rule->ends_till != null) {
if (Carbon::parse($rule->ends_till) > now()) {
$timeBased = true;
}
} else if ($rule->starts_from != null && $rule->ends_till != null) {
if (Carbon::parse($rule->starts_from) < now() && now() < Carbon::parse($rule->ends_till)) {
$timeBased = true;
}
} else {
$timeBased = true;
}
if ($rule->status) {
$status = true;
}
if ($timeBased && $status) {
return true;
} else {
return false;
}
}
/**
* Function to maintain products and catalog rule
*/
public function getProductIds($rule)
{
$productIDs = $rule->conditions;
if ($rule->conditions) {
$conditions = $rule->conditions;
// $convertX = new ConvertXToProductId();
dd($this->convertX);
$productIDs = $this->convertX->convertX($rule->conditions);
} else {
// apply on all products
}
dd($productIDs);
}
/**
* Function to maintain products, catalog rule, price
*/
}

View File

@ -1,71 +0,0 @@
<?php
namespace Webkul\Discount\Helpers;
use Webkul\Product\Repositories\ProductRepository as Product;
use Webkul\Product\Repositories\ProductFlatRepository as ProductFlat;
use Webkul\Attribute\Repositories\AttributeRepository as Attribute;
use Webkul\Core\Repositories\LocaleRepository as Locale;
class FindProducts
{
/**
* To hold the product repository instance
*/
protected $product;
/**
* To hold the attribute repository instance
*/
protected $attribute;
public function __construct(Product $product, Attribute $attribute, ProductFlat $productFlat, Locale $locale)
{
$this->product = $product;
$this->attribute = $attribute;
$this->productFlat = $productFlat;
$this->locale = $locale;
}
public function findByConditions($conditions)
{
/**
* Empty collection instance to hold all the products that satisfy the conditions
*/
$products = array();
foreach ($conditions as $condition) {
$attribute = $this->attribute->findOneByField('code', $condition->attribute);
dump($attribute->type);
if ($condition->type == 'select' || $condition->type == 'multiselect') {
$values = $condition->value;
$attributeValues = array();
foreach ($condition->options as $option) {
foreach ($values as $value) {
if ($value == $option->id) {
array_push($attributeValues, $option);
}
}
}
$defaultChannelCode = core()->getDefaultChannel()->code;
$defaultLocaleCode = $this->locale->find(core()->getDefaultChannel()->default_locale_id)->code;
foreach ($attributeValues as $attributeValue) {
$productFound = $this->productFlat->findByField([$attribute->code => $attributeValue->id, 'locale' => $defaultLocaleCode, 'channel' => $defaultChannelCode]);
if ($productFound->count()) {
array_push($products, $productFound->toArray());
}
}
} else {
}
}
dd(array_flatten($products, 1));
}
}

View File

@ -5,7 +5,7 @@ namespace Webkul\Discount\Http\Controllers;
use Webkul\Discount\Repositories\CartRuleRepository as CartRule;
use Webkul\Category\Repositories\CategoryRepository as Category;
use Webkul\Attribute\Repositories\AttributeRepository as Attribute;
use Webkul\Discount\Helpers\ConvertXToProductId as ConvertX;
use Webkul\Discount\Helpers\Cart\ConvertXToProductId as ConvertX;
use Webkul\Discount\Repositories\CartRuleLabelsRepository as CartRuleLabels;
use Webkul\Discount\Repositories\CartRuleCouponsRepository as CartRuleCoupons;

View File

@ -12,7 +12,7 @@ use Webkul\Product\Repositories\ProductFlatRepository as Product;
use Webkul\Discount\Repositories\CatalogRuleRepository as CatalogRule;
use Webkul\Discount\Repositories\CatalogRuleChannelsRepository as CatalogRuleChannels;
use Webkul\Discount\Repositories\CatalogRuleCustomerGroupsRepository as CatalogRuleCustomerGroups;
use Webkul\Discount\Helpers\FindProducts;
use Webkul\Discount\Helpers\Catalog\Apply;
/**
* Catalog Rule controller
@ -68,28 +68,35 @@ class CatalogRuleController extends Controller
protected $catalogRuleCustomerGroups;
/**
* To hold the catalog repository instance
* To hold catalog repository instance
*/
protected $catalogRule;
/**
* Find products using conditions helper instance
* To hold Sale instance
*/
protected $findProducts;
protected $apply;
public function __construct(Attribute $attribute, AttributeFamily $attributeFamily, Category $category, Product $product, CatalogRule $catalogRule, CatalogRuleChannels $catalogRuleChannels, CatalogRuleCustomerGroups $catalogRuleCustomerGroups, FindProducts $findProducts)
{
public function __construct(
Attribute $attribute,
AttributeFamily $attributeFamily,
Category $category, Product $product,
CatalogRule $catalogRule,
CatalogRuleChannels $catalogRuleChannels,
CatalogRuleCustomerGroups $catalogRuleCustomerGroups,
Apply $sale
) {
$this->_config = request('_config');
$this->attribute = $attribute;
$this->attributeFamily = $attributeFamily;
$this->category = $category;
$this->product = $product;
$this->sale = $sale;
$this->catalogRule = $catalogRule;
$this->catalogRuleChannels = $catalogRuleChannels;
$this->catalogRuleCustomerGroups = $catalogRuleCustomerGroups;
$this->appliedConfig = config('pricerules.catalog');
$this->appliedConditions = config('pricerules.conditions');
$this->findProducts = $findProducts;
}
public function index()
@ -242,7 +249,7 @@ class CatalogRuleController extends Controller
// }
$this->validate(request(), [
'name' => 'required|stringunique:catalog_rule,name,'.$id,
'name' => 'required|string|unique:catalog_rules,name,' . $id,
'starts_from' => 'present|nullable|date',
'ends_till' => 'present|nullable|date',
'description' => 'string',
@ -280,15 +287,15 @@ class CatalogRuleController extends Controller
unset($catalog_rule['all_conditions']);
if (isset($catalog_rule['disc_amount'])) {
$catalog_rule['action_type'] = $catalog_rule['apply'];
$catalog_rule['action_code'] = $catalog_rule['action_type'];
$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['action_code'] = $catalog_rule['action_type'];
$catalog_rule['actions'] = [
'action_type' => $catalog_rule['apply'],
'action_code' => $catalog_rule['action'],
'disc_percent' => $catalog_rule['disc_percent'],
];
}
@ -319,12 +326,7 @@ class CatalogRuleController extends Controller
public function applyRules()
{
$catalogRules = $this->catalogRule->all();
$decoded = json_decode($catalogRules->first()->conditions);
$conditions = json_decode($decoded[0]);
$optionableAttributes = $this->fetchOptionableAttributes();
$results = $this->findProducts->findByConditions($conditions);
$this->sale->apply();
}
public function fetchOptionableAttributes()

View File

@ -3,8 +3,8 @@
namespace Webkul\Discount\Models;
use Illuminate\Database\Eloquent\Model;
use Webkul\Customer\Models\CustomerGroupProxy;
use Webkul\Discount\Contracts\CatalogRuleCustomerGroups as CatalogRuleCustomerGroupsContract;
use Webkul\Discount\Models\CatalogRuleProxy as CatalogRule;
class CatalogRuleCustomerGroups extends Model implements CatalogRuleCustomerGroupsContract
{
@ -12,8 +12,8 @@ class CatalogRuleCustomerGroups extends Model implements CatalogRuleCustomerGrou
protected $guarded = ['created_at', 'updated_at'];
public function catalog_rule()
public function customer_group()
{
return $this->belongsTo(CatalogRule::modelClass(), 'catalog_rule_id');
return $this->hasOne(CustomerGroupProxy::modelClass(), 'id', 'customer_group_id');
}
}

View File

@ -8,12 +8,9 @@ use Webkul\Shipping\Facades\Shipping;
use Webkul\Payment\Facades\Payment;
use Webkul\Checkout\Http\Requests\CustomerAddressForm;
use Webkul\Sales\Repositories\OrderRepository;
use Webkul\Discount\Helpers\CouponAbleRule as Coupon;
use Webkul\Discount\Helpers\NonCouponAbleRule as NonCoupon;
use Webkul\Discount\Helpers\ValidatesDiscount;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Auth;
use Webkul\Discount\Helpers\Cart\CouponAbleRule as Coupon;
use Webkul\Discount\Helpers\Cart\NonCouponAbleRule as NonCoupon;
use Webkul\Discount\Helpers\Cart\ValidatesDiscount;
/**
* Chekout controller for the customer and guest for placing order

View File

@ -21,6 +21,10 @@ export default {
};
},
created() {
},
mounted() {
var this_this = this;