issue #1160, filterable attribute & configuration updated for validation

This commit is contained in:
rahul shukla 2019-07-09 14:47:40 +05:30
parent 99fbb1b9d9
commit cc4dfcad76
3 changed files with 57 additions and 4 deletions

View File

@ -82,7 +82,7 @@
<div class="control-group {{ $field['type'] }}" @if ($field['type'] == 'multiselect') :class="[errors.has('{{ $firstField }}[{{ $secondField }}][{{ $thirdField }}][{{ $field['name'] }}][]') ? 'has-error' : '']" @else :class="[errors.has('{{ $firstField }}[{{ $secondField }}][{{ $thirdField }}][{{ $field['name'] }}]') ? 'has-error' : '']" @endif>
<label for="{{ $name }}" {{ !isset($field['validation']) || strpos('required', $field['validation']) === false ? '' : 'class=required' }}>
<label for="{{ $name }}" {{ !isset($field['validation']) || preg_match('/\brequired\b/', $field['validation']) == false ? '' : 'class=required' }}>
{{ trans($field['title']) }}

View File

@ -37,7 +37,7 @@ class ProductFlatRepository extends Repository
}
/**
* Maximum Price of Category Prodcut
* Maximum Price of Category Product
*
* @param int $categoryId
* return integer
@ -51,7 +51,7 @@ class ProductFlatRepository extends Repository
}
/**
* Maximum Price of Prodcut
* Maximum Price of Product
*
* return integer
*/
@ -59,4 +59,17 @@ class ProductFlatRepository extends Repository
{
return $this->model->max('price');
}
/**
* get Category Product
*
* return array
*/
public function getCategoryProduct($categoryId)
{
return $this->model
->leftJoin('product_categories', 'product_flat.product_id', 'product_categories.product_id')
->where('product_categories.category_id', $categoryId)
->get();
}
}

View File

@ -2,6 +2,46 @@
@inject ('productFlatRepository', 'Webkul\Product\Repositories\ProductFlatRepository')
@inject ('productAttributeValueRepository', 'Webkul\Product\Repositories\ProductAttributeValueRepository')
<?php
$filterAttributes = [];
if (isset($category)) {
$categoryProduct = $productFlatRepository->getCategoryProduct($category->id);
foreach ($categoryProduct as $product) {
$attributes = $productAttributeValueRepository->findByField('product_id', $product->product_id);
if ($product->product->type == 'configurable') {
foreach ($product->product->super_attributes as $super_attribute) {
$productAttribute[] = $super_attribute->id;
}
}
foreach ($attributes as $attribute) {
if ($attribute) {
$productAttribute[] = $attribute->attribute_id;
}
}
}
if (isset($productAttribute)) {
foreach ($attributeRepository->getFilterAttributes() as $filterAttribute) {
if (in_array($filterAttribute->id, array_unique($productAttribute))) {
$filterAttributes[] = $filterAttribute;
} else if ($filterAttribute ['code'] == 'price') {
$filterAttributes[] = $filterAttribute;
}
}
}
$filterAttributes = collect($filterAttributes);
} else {
$filterAttributes = $attributeRepository->getFilterAttributes();
}
?>
<div class="layered-filter-wrapper">
{!! view_render_event('bagisto.shop.products.list.layered-nagigation.before') !!}
@ -85,7 +125,7 @@
data: function() {
return {
attributes: @json($attributeRepository->getFilterAttributes()),
attributes: @json($filterAttributes),
appliedFilters: {}
}
},