diff --git a/packages/Webkul/CustomerDocument/src/Config/system.php b/packages/Webkul/CustomerDocument/src/Config/system.php new file mode 100644 index 000000000..883fef1b7 --- /dev/null +++ b/packages/Webkul/CustomerDocument/src/Config/system.php @@ -0,0 +1,22 @@ + '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' + ] + ], + ] +]; \ No newline at end of file diff --git a/packages/Webkul/CustomerDocument/src/Http/Controllers/DocumentController.php b/packages/Webkul/CustomerDocument/src/Http/Controllers/DocumentController.php index 6fc73a74e..12d0482ef 100644 --- a/packages/Webkul/CustomerDocument/src/Http/Controllers/DocumentController.php +++ b/packages/Webkul/CustomerDocument/src/Http/Controllers/DocumentController.php @@ -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(); } } diff --git a/packages/Webkul/CustomerDocument/src/Providers/CustomerDocumentServiceProvider.php b/packages/Webkul/CustomerDocument/src/Providers/CustomerDocumentServiceProvider.php index ed4566a3c..c2fe1a852 100644 --- a/packages/Webkul/CustomerDocument/src/Providers/CustomerDocumentServiceProvider.php +++ b/packages/Webkul/CustomerDocument/src/Providers/CustomerDocumentServiceProvider.php @@ -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' + ); } } \ No newline at end of file diff --git a/packages/Webkul/CustomerDocument/src/Resources/lang/en/app.php b/packages/Webkul/CustomerDocument/src/Resources/lang/en/app.php index 62b076968..73500a656 100644 --- a/packages/Webkul/CustomerDocument/src/Resources/lang/en/app.php +++ b/packages/Webkul/CustomerDocument/src/Resources/lang/en/app.php @@ -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' ], ], ]; \ No newline at end of file diff --git a/packages/Webkul/CustomerDocument/src/Resources/views/admin/customers/upload.blade.php b/packages/Webkul/CustomerDocument/src/Resources/views/admin/customers/upload.blade.php index 001f05989..9fa2c3150 100644 --- a/packages/Webkul/CustomerDocument/src/Resources/views/admin/customers/upload.blade.php +++ b/packages/Webkul/CustomerDocument/src/Resources/views/admin/customers/upload.blade.php @@ -65,16 +65,34 @@ $documents = $customerDocumentRepository->findWhere(['customer_id' => $customer-
+ + @{{ errors.first('description') }}
- + + + + @php + $allowedTypes = core()->getConfigData('customer.settings.documents.allowed_extensions'); + @endphp + {{ __('customerdocument::app.admin.customers.allowed-type') }} - {{ __('customerdocument::app.admin.customers.file-type') }} + + + @if ($allowedTypes != null) + {{ $allowedTypes }} + @else + {{ __('customerdocument::app.admin.customers.any-type') }} + @endif + + + @{{ errors.first('file') }}
diff --git a/packages/Webkul/CustomerGroupCatalog/src/Repositories/CategoryRepository.php b/packages/Webkul/CustomerGroupCatalog/src/Repositories/CategoryRepository.php index e65b49c3f..fb433dedd 100644 --- a/packages/Webkul/CustomerGroupCatalog/src/Repositories/CategoryRepository.php +++ b/packages/Webkul/CustomerGroupCatalog/src/Repositories/CategoryRepository.php @@ -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; + } } \ No newline at end of file diff --git a/packages/Webkul/CustomerGroupCatalog/src/Resources/lang/en/app.php b/packages/Webkul/CustomerGroupCatalog/src/Resources/lang/en/app.php index a48dab7e9..61a55e305 100644 --- a/packages/Webkul/CustomerGroupCatalog/src/Resources/lang/en/app.php +++ b/packages/Webkul/CustomerGroupCatalog/src/Resources/lang/en/app.php @@ -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', diff --git a/resources/views/vendor/admin/customers/groups/create.blade.php b/resources/views/vendor/admin/customers/groups/create.blade.php index 7b6624eb0..d8fde03ef 100644 --- a/resources/views/vendor/admin/customers/groups/create.blade.php +++ b/resources/views/vendor/admin/customers/groups/create.blade.php @@ -12,7 +12,7 @@

- + {{ __('admin::app.customers.groups.add-title') }}

@@ -31,6 +31,12 @@
+
+ + + @{{ errors.first('code') }} +
+