customer group catalog fixed

This commit is contained in:
Prashant Singh 2019-06-24 16:06:46 +05:30
parent e130e79121
commit e79701b037
9 changed files with 156 additions and 57 deletions

View File

@ -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'
]
],
]
];

View File

@ -7,6 +7,7 @@ use Illuminate\Http\Response;
use Webkul\CustomerDocument\Repositories\CustomerDocumentRepository; use Webkul\CustomerDocument\Repositories\CustomerDocumentRepository;
use Webkul\CustomerDocument\Http\Controllers\Controller; use Webkul\CustomerDocument\Http\Controllers\Controller;
use Illuminate\Support\Facades\Storage; use Illuminate\Support\Facades\Storage;
use Validator;
/** /**
* Document controlller * Document controlller
@ -61,35 +62,55 @@ class DocumentController extends Controller
*/ */
public function upload() 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)) { if ($maxSize == null) {
session()->flash('error', trans('customerdocument::app.admin.customers.upload-error')); $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(); return redirect()->back();
} else { } catch (\Exception $e) {
try { session()->flash('error', $e);
$data = request()->all();
if (request()->hasFile('file')) { return redirect()->back();
$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();
}
} }
} }

View File

@ -49,5 +49,9 @@ class CustomerDocumentServiceProvider extends ServiceProvider
$this->mergeConfigFrom( $this->mergeConfigFrom(
dirname(__DIR__) . '/Config/menu.php', 'menu.customer' dirname(__DIR__) . '/Config/menu.php', 'menu.customer'
); );
$this->mergeConfigFrom(
dirname(__DIR__) . '/Config/system.php', 'core'
);
} }
} }

View File

@ -15,7 +15,10 @@ return [
'allowed-type' => 'Allowed Type :', 'allowed-type' => 'Allowed Type :',
'file-type' => 'csv, xls, xlsx, ods, png, jpeg, zip.', '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.', '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'
], ],
], ],
]; ];

View File

@ -65,16 +65,34 @@ $documents = $customerDocumentRepository->findWhere(['customer_id' => $customer-
<div class="control-group" :class="[errors.has('description') ? 'has-error' : '']"> <div class="control-group" :class="[errors.has('description') ? 'has-error' : '']">
<label for="description">{{ __('customerdocument::app.admin.customers.description') }}</label> <label for="description">{{ __('customerdocument::app.admin.customers.description') }}</label>
<textarea class="control" id="description" name="description" data-vv-as="&quot;{{ __('customerdocument::app.admin.customers.description') }}&quot;" value="{{ old('description') }}"/ <textarea class="control" id="description" name="description" data-vv-as="&quot;{{ __('customerdocument::app.admin.customers.description') }}&quot;" value="{{ old('description') }}"/
></textarea> ></textarea>
<span class="control-error" v-if="errors.has('description')">@{{ errors.first('description') }}</span> <span class="control-error" v-if="errors.has('description')">@{{ errors.first('description') }}</span>
</div> </div>
<div class="control-group" :class="[errors.has('file') ? 'has-error' : '']"> <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="&quot;{{ __('customerdocument::app.admin.customers.file') }}&quot;" value="{{ old('file') }}" style="padding-top: 5px"> <input v-validate="'required'" type="file" class="control" id="file" name="file" data-vv-as="&quot;{{ __('customerdocument::app.admin.customers.file') }}&quot;" 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>{{ __('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> <span class="control-error" v-if="errors.has('file')">@{{ errors.first('file') }}</span>
</div> </div>

View File

@ -46,37 +46,37 @@ class CategoryRepository extends BaseCategoryRepository
$customer = auth()->guard(request()->has('token') ? 'api' : 'customer')->user(); $customer = auth()->guard(request()->has('token') ? 'api' : 'customer')->user();
$categoryIds = []; $categoryIds = [];
$categoryShowId = []; $showCategories = [];
$parentCategoryIds = [];
if (! $customer) { if (! $customer) {
$categoryIds = app('Webkul\CustomerGroupCatalog\Repositories\CustomerGroupRepository')->findOneByField('code', 'guest')->categories()->pluck('id'); $categoryIds = app('Webkul\CustomerGroupCatalog\Repositories\CustomerGroupRepository')->findOneByField('code', 'guest')->categories()->pluck('id');
} else { } else {
if ($customer->group) { 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 ($categories as $category) {
foreach ($categoryIds as $categoryId) { $parentCategoryIds[] = $category->id;
foreach ($parentIds as $parentId) { $parentCategory = $this->getParentCategory($category->parent_id);
if ($categoryId->parent_id == $parentId) {
$categoryShowId[] = $categoryId->id; $result = array_merge($parentCategoryIds, $parentCategory);
} $count = 0;
foreach($result as $cat) {
if (in_array($cat, $categoryIds)) {
$count++;
} }
} }
if (count($categoryShowId) > 0) { if (count($result) == $count) {
$categoryIds = array_unique($categoryShowId); $showCategories[] = $category->id;
} else {
$categoryIds = [];
} }
} else {
$categoryIds = [];
} }
} }
} }
if (count($categoryIds)) { if (count($showCategories)) {
$categories[$id] = $id $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)->descendantsOf($id)->toTree()
: $this->model::orderBy('position', 'ASC')->where('status', 1)->whereIn('id', $categoryIds)->get()->toTree(); : $this->model::orderBy('position', 'ASC')->where('status', 1)->whereIn('id', $categoryIds)->get()->toTree();
@ -90,4 +90,22 @@ class CategoryRepository extends BaseCategoryRepository
return []; 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;
}
} }

View File

@ -4,7 +4,7 @@ return [
'customers' => [ 'customers' => [
'groups' => [ 'groups' => [
'general' => 'General', 'general' => 'General',
'linked-product-categories' => 'Linked Products and Categories', 'linked-product-categories' => 'Linked Categories',
'categories' => 'Categories', 'categories' => 'Categories',
'products' => 'Products', 'products' => 'Products',
'search-hint' => 'Start typing name', 'search-hint' => 'Start typing name',

View File

@ -12,7 +12,7 @@
<div class="page-title"> <div class="page-title">
<h1> <h1>
<i class="icon angle-left-icon back-link" onclick="history.length > 1 ? history.go(-1) : window.location = '{{ url('/admin/dashboard') }}';"></i> <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') }} {{ __('admin::app.customers.groups.add-title') }}
</h1> </h1>
</div> </div>
@ -31,6 +31,12 @@
<accordian :title="'{{ __('customergroupcatalog::app.customers.groups.general') }}'" :active="true"> <accordian :title="'{{ __('customergroupcatalog::app.customers.groups.general') }}'" :active="true">
<div slot="body"> <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="&quot;{{ __('admin::app.customers.groups.code') }}&quot;" 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' : '']"> <div class="control-group" :class="[errors.has('name') ? 'has-error' : '']">
<label for="name" class="required"> <label for="name" class="required">
{{ __('admin::app.customers.groups.name') }} {{ __('admin::app.customers.groups.name') }}
@ -74,7 +80,7 @@
</li> </li>
<li v-if='! searched_results[key].length && search_terms[key].length && ! is_searching[key]'> <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>
<li v-if="is_searching[key] && search_terms[key].length"> <li v-if="is_searching[key] && search_terms[key].length">
@ -116,7 +122,7 @@
saved_results: { saved_results: {
products: [], products: [],
categories: [], categories: [],
}, },
@ -142,7 +148,7 @@
'products': "{{ __('customergroupcatalog::app.customers.groups.products') }}", 'products': "{{ __('customergroupcatalog::app.customers.groups.products') }}",
'categories': "{{ __('customergroupcatalog::app.customers.groups.categories') }}", 'categories': "{{ __('customergroupcatalog::app.customers.groups.categories') }}",
} }
} }
}, },
@ -185,7 +191,7 @@
return; return;
} }
this.$http.get ("{{ route('admin.customer_group_catalog.search.catalog') }}", {params: {query: this.search_terms[key], type: key}}) this.$http.get ("{{ route('admin.customer_group_catalog.search.catalog') }}", {params: {query: this.search_terms[key], type: key}})
.then (function(response) { .then (function(response) {
for (var key1 in this_this.saved_results[key]) { for (var key1 in this_this.saved_results[key]) {

View File

@ -12,7 +12,7 @@
<div class="page-title"> <div class="page-title">
<h1> <h1>
<i class="icon angle-left-icon back-link" onclick="history.length > 1 ? history.go(-1) : window.location = '{{ url('/admin/dashboard') }}';"></i> <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') }} {{ __('admin::app.customers.groups.edit-title') }}
</h1> </h1>
</div> </div>
@ -34,6 +34,13 @@
<accordian :title="'{{ __('customergroupcatalog::app.customers.groups.general') }}'" :active="true"> <accordian :title="'{{ __('customergroupcatalog::app.customers.groups.general') }}'" :active="true">
<div slot="body"> <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="&quot;{{ __('admin::app.customers.groups.code') }}&quot;" 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' : '']"> <div class="control-group" :class="[errors.has('name') ? 'has-error' : '']">
<label for="name" class="required"> <label for="name" class="required">
{{ __('admin::app.customers.groups.name') }} {{ __('admin::app.customers.groups.name') }}
@ -43,7 +50,7 @@
</div> </div>
</div> </div>
</accordian> </accordian>
<accordian :title="'{{ __('customergroupcatalog::app.customers.groups.linked-product-categories') }}'"> <accordian :title="'{{ __('customergroupcatalog::app.customers.groups.linked-product-categories') }}'">
@ -76,7 +83,7 @@
</li> </li>
<li v-if='! searched_results[key].length && search_terms[key].length && ! is_searching[key]'> <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>
<li v-if="is_searching[key] && search_terms[key].length"> <li v-if="is_searching[key] && search_terms[key].length">
@ -116,13 +123,13 @@
saved_results: { saved_results: {
products: [], products: [],
categories: [] categories: []
}, },
linked_results: { linked_results: {
products: @json(app('Webkul\CustomerGroupCatalog\Repositories\CustomerGroupRepository')->getProducts($group)), products: @json(app('Webkul\CustomerGroupCatalog\Repositories\CustomerGroupRepository')->getProducts($group)),
categories: @json(app('Webkul\CustomerGroupCatalog\Repositories\CustomerGroupRepository')->getCategories($group)) categories: @json(app('Webkul\CustomerGroupCatalog\Repositories\CustomerGroupRepository')->getCategories($group))
}, },
@ -148,7 +155,7 @@
products: "{{ __('customergroupcatalog::app.customers.groups.products') }}", products: "{{ __('customergroupcatalog::app.customers.groups.products') }}",
categories: "{{ __('customergroupcatalog::app.customers.groups.categories') }}" categories: "{{ __('customergroupcatalog::app.customers.groups.categories') }}"
} }
} }
}, },
@ -201,7 +208,7 @@
return; return;
} }
this.$http.get ("{{ route('admin.customer_group_catalog.search.catalog') }}", {params: {query: this.search_terms[key], type: key}}) this.$http.get ("{{ route('admin.customer_group_catalog.search.catalog') }}", {params: {query: this.search_terms[key], type: key}})
.then (function(response) { .then (function(response) {
for (var key1 in this_this.saved_results[key]) { for (var key1 in this_this.saved_results[key]) {