customer group catalog fixed
This commit is contained in:
parent
e130e79121
commit
e79701b037
|
|
@ -0,0 +1,22 @@
|
|||
<?php
|
||||
|
||||
return [
|
||||
[
|
||||
'key' => 'customer.settings.documents',
|
||||
'name' => 'customerdocument::app.admin.customers.documents',
|
||||
'sort' => 4,
|
||||
'fields' => [
|
||||
[
|
||||
'name' => 'size',
|
||||
'title' => 'customerdocument::app.admin.customers.size',
|
||||
'type' => 'text',
|
||||
'validation' => 'decimal:2'
|
||||
], [
|
||||
'name' => 'allowed_extensions',
|
||||
'title' => 'customerdocument::app.admin.customers.allowed-types',
|
||||
'type' => 'text',
|
||||
'validation' => 'required'
|
||||
]
|
||||
],
|
||||
]
|
||||
];
|
||||
|
|
@ -7,6 +7,7 @@ use Illuminate\Http\Response;
|
|||
use Webkul\CustomerDocument\Repositories\CustomerDocumentRepository;
|
||||
use Webkul\CustomerDocument\Http\Controllers\Controller;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Validator;
|
||||
|
||||
/**
|
||||
* Document controlller
|
||||
|
|
@ -61,35 +62,55 @@ class DocumentController extends Controller
|
|||
*/
|
||||
public function upload()
|
||||
{
|
||||
$valid_extension = ['xlsx', 'csv', 'xls', 'ods', 'png', 'jpeg', 'zip'];
|
||||
$availableMimes = core()->getConfigData('customer.settings.documents.allowed_extensions');
|
||||
$maxSize = core()->getConfigData('customer.settings.documents.size');
|
||||
|
||||
if (! in_array(request()->file('file')->getClientOriginalExtension(), $valid_extension)) {
|
||||
session()->flash('error', trans('customerdocument::app.admin.customers.upload-error'));
|
||||
if ($maxSize == null) {
|
||||
$maxSize = 5 * 1024;
|
||||
} else {
|
||||
$maxSize = $maxSize * 1024;
|
||||
}
|
||||
|
||||
$maxSize = 10;
|
||||
|
||||
$customerId = request()->input('customer_id');
|
||||
|
||||
if (strlen($availableMimes)) {
|
||||
$validator = Validator::make(request()->input(), [
|
||||
'file' => 'required|file|mimes:'.$availableMimes.'|size:'.$maxSize
|
||||
]);
|
||||
} else {
|
||||
$validator = Validator::make(request()->input(), [
|
||||
'file' => 'required|file|size:'.$maxSize
|
||||
]);
|
||||
}
|
||||
|
||||
if ($validator->fails()) {
|
||||
session()->flash('error', $validator->errors());
|
||||
return redirect()->back();
|
||||
}
|
||||
|
||||
try {
|
||||
$data = request()->all();
|
||||
|
||||
if (request()->hasFile('file')) {
|
||||
$dir = 'customer';
|
||||
$document['path'] = request()->file('file')->store($dir);
|
||||
}
|
||||
|
||||
$document['customer_id'] = $data['customer_id'];
|
||||
$document['name'] = $data['name'];
|
||||
$document['description'] = $data['description'];
|
||||
|
||||
$this->customerDocument->create($document);
|
||||
|
||||
session()->flash('success', trans('customerdocument::app.admin.customers.upload-success'));
|
||||
|
||||
return redirect()->back();
|
||||
} else {
|
||||
try {
|
||||
$data = request()->all();
|
||||
} catch (\Exception $e) {
|
||||
session()->flash('error', $e);
|
||||
|
||||
if (request()->hasFile('file')) {
|
||||
$dir = 'customer';
|
||||
$document['path'] = request()->file('file')->store($dir);
|
||||
}
|
||||
|
||||
$document['customer_id'] = $data['customer_id'];
|
||||
$document['name'] = $data['name'];
|
||||
$document['description'] = $data['description'];
|
||||
|
||||
$this->customerDocument->create($document);
|
||||
|
||||
session()->flash('success', trans('customerdocument::app.admin.customers.upload-success'));
|
||||
|
||||
return redirect()->back();
|
||||
} catch (\Exception $e) {
|
||||
session()->flash('error', $e);
|
||||
|
||||
return redirect()->back();
|
||||
}
|
||||
return redirect()->back();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -49,5 +49,9 @@ class CustomerDocumentServiceProvider extends ServiceProvider
|
|||
$this->mergeConfigFrom(
|
||||
dirname(__DIR__) . '/Config/menu.php', 'menu.customer'
|
||||
);
|
||||
|
||||
$this->mergeConfigFrom(
|
||||
dirname(__DIR__) . '/Config/system.php', 'core'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
@ -15,7 +15,10 @@ return [
|
|||
'allowed-type' => 'Allowed Type :',
|
||||
'file-type' => 'csv, xls, xlsx, ods, png, jpeg, zip.',
|
||||
'upload-error' => 'The file must be a file of type: csv, xls, xlsx, ods, png, jpeg, zip.',
|
||||
'description' => 'Description'
|
||||
'description' => 'Description',
|
||||
'size' => 'Max Size Allowed (MegaBytes)',
|
||||
'allowed-types' => 'Allowed Types (Use comma to separate multiple formats)',
|
||||
'any-type' => 'All file types are allowed'
|
||||
],
|
||||
],
|
||||
];
|
||||
|
|
@ -65,16 +65,34 @@ $documents = $customerDocumentRepository->findWhere(['customer_id' => $customer-
|
|||
|
||||
<div class="control-group" :class="[errors.has('description') ? 'has-error' : '']">
|
||||
<label for="description">{{ __('customerdocument::app.admin.customers.description') }}</label>
|
||||
|
||||
<textarea class="control" id="description" name="description" data-vv-as=""{{ __('customerdocument::app.admin.customers.description') }}"" value="{{ old('description') }}"/
|
||||
></textarea>
|
||||
|
||||
<span class="control-error" v-if="errors.has('description')">@{{ errors.first('description') }}</span>
|
||||
</div>
|
||||
|
||||
<div class="control-group" :class="[errors.has('file') ? 'has-error' : '']">
|
||||
<label for="file" class="required">{{ __('customerdocument::app.admin.customers.file') }}</label>
|
||||
<label for="file" class="required">{{ __
|
||||
('customerdocument::app.admin.customers.file') }}</label>
|
||||
|
||||
<input v-validate="'required'" type="file" class="control" id="file" name="file" data-vv-as=""{{ __('customerdocument::app.admin.customers.file') }}"" value="{{ old('file') }}" style="padding-top: 5px">
|
||||
|
||||
@php
|
||||
$allowedTypes = core()->getConfigData('customer.settings.documents.allowed_extensions');
|
||||
@endphp
|
||||
|
||||
<span>{{ __('customerdocument::app.admin.customers.allowed-type') }}</span>
|
||||
<span><b>{{ __('customerdocument::app.admin.customers.file-type') }}</b></span>
|
||||
<span>
|
||||
<b>
|
||||
@if ($allowedTypes != null)
|
||||
{{ $allowedTypes }}
|
||||
@else
|
||||
{{ __('customerdocument::app.admin.customers.any-type') }}
|
||||
@endif
|
||||
|
||||
</b>
|
||||
</span>
|
||||
<span class="control-error" v-if="errors.has('file')">@{{ errors.first('file') }}</span>
|
||||
</div>
|
||||
|
||||
|
|
|
|||
|
|
@ -46,37 +46,37 @@ class CategoryRepository extends BaseCategoryRepository
|
|||
$customer = auth()->guard(request()->has('token') ? 'api' : 'customer')->user();
|
||||
|
||||
$categoryIds = [];
|
||||
$categoryShowId = [];
|
||||
$showCategories = [];
|
||||
$parentCategoryIds = [];
|
||||
|
||||
if (! $customer) {
|
||||
$categoryIds = app('Webkul\CustomerGroupCatalog\Repositories\CustomerGroupRepository')->findOneByField('code', 'guest')->categories()->pluck('id');
|
||||
} else {
|
||||
if ($customer->group) {
|
||||
$categoryIds = app('Webkul\CustomerGroupCatalog\Repositories\CustomerGroupRepository')->find($customer->group->id)->categories()->get();
|
||||
$categories = app('Webkul\CustomerGroupCatalog\Repositories\CustomerGroupRepository')->find($customer->group->id)->categories()->get();
|
||||
|
||||
$parentIds = app('Webkul\CustomerGroupCatalog\Repositories\CustomerGroupRepository')->find($customer->group->id)->categories()->pluck('parent_id')->toArray();
|
||||
$categoryIds = app('Webkul\CustomerGroupCatalog\Repositories\CustomerGroupRepository')->find($customer->group->id)->categories()->pluck('id')->toArray();
|
||||
|
||||
if (in_array(NULL, $parentIds)) {
|
||||
foreach ($categoryIds as $categoryId) {
|
||||
foreach ($parentIds as $parentId) {
|
||||
if ($categoryId->parent_id == $parentId) {
|
||||
$categoryShowId[] = $categoryId->id;
|
||||
}
|
||||
foreach ($categories as $category) {
|
||||
$parentCategoryIds[] = $category->id;
|
||||
$parentCategory = $this->getParentCategory($category->parent_id);
|
||||
|
||||
$result = array_merge($parentCategoryIds, $parentCategory);
|
||||
$count = 0;
|
||||
foreach($result as $cat) {
|
||||
if (in_array($cat, $categoryIds)) {
|
||||
$count++;
|
||||
}
|
||||
}
|
||||
|
||||
if (count($categoryShowId) > 0) {
|
||||
$categoryIds = array_unique($categoryShowId);
|
||||
} else {
|
||||
$categoryIds = [];
|
||||
if (count($result) == $count) {
|
||||
$showCategories[] = $category->id;
|
||||
}
|
||||
} else {
|
||||
$categoryIds = [];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (count($categoryIds)) {
|
||||
if (count($showCategories)) {
|
||||
$categories[$id] = $id
|
||||
? $this->model::orderBy('position', 'ASC')->where('status', 1)->whereIn('id', $categoryIds)->descendantsOf($id)->toTree()
|
||||
: $this->model::orderBy('position', 'ASC')->where('status', 1)->whereIn('id', $categoryIds)->get()->toTree();
|
||||
|
|
@ -90,4 +90,22 @@ class CategoryRepository extends BaseCategoryRepository
|
|||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* get parent category
|
||||
*
|
||||
* @param integer $id
|
||||
* @return array
|
||||
*/
|
||||
public function getParentCategory($parentId) {
|
||||
$parentCategories = [];
|
||||
$parentCategory = $this->getModel()->where('id', $parentId)->first();
|
||||
|
||||
if ($parentCategory->parent_id != null) {
|
||||
$parentCategories[] = $parentCategory->id;
|
||||
$this->getParentCategory($parentCategory->parent_id);
|
||||
}
|
||||
|
||||
return $parentCategories;
|
||||
}
|
||||
}
|
||||
|
|
@ -4,7 +4,7 @@ return [
|
|||
'customers' => [
|
||||
'groups' => [
|
||||
'general' => 'General',
|
||||
'linked-product-categories' => 'Linked Products and Categories',
|
||||
'linked-product-categories' => 'Linked Categories',
|
||||
'categories' => 'Categories',
|
||||
'products' => 'Products',
|
||||
'search-hint' => 'Start typing name',
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@
|
|||
<div class="page-title">
|
||||
<h1>
|
||||
<i class="icon angle-left-icon back-link" onclick="history.length > 1 ? history.go(-1) : window.location = '{{ url('/admin/dashboard') }}';"></i>
|
||||
|
||||
|
||||
{{ __('admin::app.customers.groups.add-title') }}
|
||||
</h1>
|
||||
</div>
|
||||
|
|
@ -31,6 +31,12 @@
|
|||
<accordian :title="'{{ __('customergroupcatalog::app.customers.groups.general') }}'" :active="true">
|
||||
<div slot="body">
|
||||
|
||||
<div class="control-group" :class="[errors.has('code') ? 'has-error' : '']">
|
||||
<label for="code" class="required">{{ __('admin::app.customers.groups.code') }}</label>
|
||||
<input v-validate="'required'" class="control" id="code" name="code" data-vv-as=""{{ __('admin::app.customers.groups.code') }}"" v-code/>
|
||||
<span class="control-error" v-if="errors.has('code')">@{{ errors.first('code') }}</span>
|
||||
</div>
|
||||
|
||||
<div class="control-group" :class="[errors.has('name') ? 'has-error' : '']">
|
||||
<label for="name" class="required">
|
||||
{{ __('admin::app.customers.groups.name') }}
|
||||
|
|
@ -74,7 +80,7 @@
|
|||
</li>
|
||||
|
||||
<li v-if='! searched_results[key].length && search_terms[key].length && ! is_searching[key]'>
|
||||
{{ __('admin::app.catalog.products.no-result-found') }}
|
||||
{{ __('customergroupcatalog::app.customers.groups.no-result-found') }}
|
||||
</li>
|
||||
|
||||
<li v-if="is_searching[key] && search_terms[key].length">
|
||||
|
|
@ -116,7 +122,7 @@
|
|||
|
||||
saved_results: {
|
||||
products: [],
|
||||
|
||||
|
||||
categories: [],
|
||||
},
|
||||
|
||||
|
|
@ -142,7 +148,7 @@
|
|||
'products': "{{ __('customergroupcatalog::app.customers.groups.products') }}",
|
||||
|
||||
'categories': "{{ __('customergroupcatalog::app.customers.groups.categories') }}",
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
|
|
@ -185,7 +191,7 @@
|
|||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
this.$http.get ("{{ route('admin.customer_group_catalog.search.catalog') }}", {params: {query: this.search_terms[key], type: key}})
|
||||
.then (function(response) {
|
||||
for (var key1 in this_this.saved_results[key]) {
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@
|
|||
<div class="page-title">
|
||||
<h1>
|
||||
<i class="icon angle-left-icon back-link" onclick="history.length > 1 ? history.go(-1) : window.location = '{{ url('/admin/dashboard') }}';"></i>
|
||||
|
||||
|
||||
{{ __('admin::app.customers.groups.edit-title') }}
|
||||
</h1>
|
||||
</div>
|
||||
|
|
@ -34,6 +34,13 @@
|
|||
<accordian :title="'{{ __('customergroupcatalog::app.customers.groups.general') }}'" :active="true">
|
||||
<div slot="body">
|
||||
|
||||
<div class="control-group" :class="[errors.has('code') ? 'has-error' : '']">
|
||||
<label for="code" class="required">{{ __('admin::app.customers.groups.code') }}</label>
|
||||
<input type="text" v-validate="'required'" class="control" id="code" name="code" data-vv-as=""{{ __('admin::app.customers.groups.code') }}"" value="{{ $group->code }}" disabled="disabled"/>
|
||||
<input type="hidden" name="code" value="{{ $group->code }}"/>
|
||||
<span class="control-error" v-if="errors.has('code')">@{{ errors.first('code') }}</span>
|
||||
</div>
|
||||
|
||||
<div class="control-group" :class="[errors.has('name') ? 'has-error' : '']">
|
||||
<label for="name" class="required">
|
||||
{{ __('admin::app.customers.groups.name') }}
|
||||
|
|
@ -43,7 +50,7 @@
|
|||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
</accordian>
|
||||
|
||||
<accordian :title="'{{ __('customergroupcatalog::app.customers.groups.linked-product-categories') }}'">
|
||||
|
|
@ -76,7 +83,7 @@
|
|||
</li>
|
||||
|
||||
<li v-if='! searched_results[key].length && search_terms[key].length && ! is_searching[key]'>
|
||||
{{ __('admin::app.catalog.products.no-result-found') }}
|
||||
{{ __('customergroupcatalog::app.customers.groups.no-result-found') }}
|
||||
</li>
|
||||
|
||||
<li v-if="is_searching[key] && search_terms[key].length">
|
||||
|
|
@ -116,13 +123,13 @@
|
|||
|
||||
saved_results: {
|
||||
products: [],
|
||||
|
||||
|
||||
categories: []
|
||||
},
|
||||
|
||||
linked_results: {
|
||||
products: @json(app('Webkul\CustomerGroupCatalog\Repositories\CustomerGroupRepository')->getProducts($group)),
|
||||
|
||||
|
||||
categories: @json(app('Webkul\CustomerGroupCatalog\Repositories\CustomerGroupRepository')->getCategories($group))
|
||||
},
|
||||
|
||||
|
|
@ -148,7 +155,7 @@
|
|||
products: "{{ __('customergroupcatalog::app.customers.groups.products') }}",
|
||||
|
||||
categories: "{{ __('customergroupcatalog::app.customers.groups.categories') }}"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
|
|
@ -201,7 +208,7 @@
|
|||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
this.$http.get ("{{ route('admin.customer_group_catalog.search.catalog') }}", {params: {query: this.search_terms[key], type: key}})
|
||||
.then (function(response) {
|
||||
for (var key1 in this_this.saved_results[key]) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue