Skip to content
This repository has been archived by the owner on Jan 9, 2025. It is now read-only.

Code Refactor and optimization of code. #90

Open
wants to merge 18 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion CHANGELOG for v1.3.x.md → CHANGELOG for v1.5.x.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
# CHANGELOG for v1.3.x
# CHANGELOG for v1.5.x


#### This changelog consists the bug & security fixes and new features being included in the releases listed below.

## **v1.5.1(30th of May 2023)** - _Release_

- [compatible] Compatible with bagisto v1.5.1.

## **v1.3.3(24th of Oct, 2021)** - _Release_

- [compatible] Compatible with bagisto v1.3.3.
Expand Down
37 changes: 7 additions & 30 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,36 +12,8 @@ It packs in lots of demanding features that allows your business to scale in no

## Requirements:

- **Bagisto**: v1.3.3

## Installation with composer:
- Run the following command
```
composer require bagisto/bagisto-bulk-upload
```

- Goto vendor/bagisto/bagisto-bulkupload and copy the storage folder and merge it into the root of your project.

- Goto config/concord.php file and add following line under 'modules'
```php
\Webkul\Bulkupload\Providers\ModuleServiceProvider::class
```

- Run these commands below to complete the setup
```
composer dump-autoload
```

```
php artisan migrate
php artisan storage:link
php artisan route:cache
php artisan config:cache
php artisan vendor:publish
```
-> Press 0 and then press enter to publish all assets and configurations.

## Installation without composer:
- **Bagisto**: v1.5.1
## Installation:

- Unzip the respective extension zip and then merge "packages" and "storage" folders into project root directory.
- Goto config/app.php file and add following line under 'providers'
Expand Down Expand Up @@ -86,4 +58,9 @@ php artisan vendor:publish
-> Press 0 and then press enter to publish all assets and configurations.
```


```
Move storage/app/public/download/sample-files into root/storage/app/public/download/
```

> That's it, now just execute the project on your specified domain.
File renamed without changes.
File renamed without changes.
File renamed without changes.
20 changes: 10 additions & 10 deletions package.json → packages/Webkul/Bulkupload/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@
"private": true,
"scripts": {
"dev": "npm run development",
"development": "cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
"watch": "cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --watch --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
"development": "cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --config=node_modules/laravel-mix/setup/webpack.config.js",
"watch": "cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --watch --progress --config=node_modules/laravel-mix/setup/webpack.config.js",
"watch-poll": "cross-env npm run watch -- --watch-poll --progress",
"hot": "cross-env NODE_ENV=development node_modules/webpack-dev-server/bin/webpack-dev-server.js --inline --hot --config=node_modules/laravel-mix/setup/webpack.config.js",
"prod": "npm run production",
"production": "cross-env NODE_ENV=production node_modules/webpack/bin/webpack.js --no-progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js"
"production": "cross-env NODE_ENV=production node_modules/webpack/bin/webpack.js --no-progress --config=node_modules/laravel-mix/setup/webpack.config.js"
},
"devDependencies": {
"axios": "^0.18",
"cross-env": "^5.1.4",
"laravel-mix": "^2.1",
"laravel-mix-merge-manifest": "^0.1.1",
"jquery": "^3.2",
"axios": "^1.4.0",
"cross-env": "^7.0.3",
"laravel-mix": "^6.0.49",
"laravel-mix-merge-manifest": "^2.1.0",
"sass": "^1.62.1",
"sass-loader": "^12.6.0",
"vue": "^2.1.10"
},
"dependencies": {}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,28 @@

namespace Webkul\Bulkupload\DataGrids\Admin;

use DB;
use Illuminate\Support\Facades\DB;
use Webkul\Ui\DataGrid\DataGrid;

/**
* Profile Datagrid class
*
*/
class ProfileDataGrid extends DataGrid
{
/**
* @var integer
* Index
*
* @var string
*/
protected $index = 'id';

/**
* Prepare the query builder
*
* @return void
*/
public function prepareQueryBuilder()
{
$queryBuilder = DB::table('bulkupload_data_flow_profiles')
->leftJoin('attribute_families', 'bulkupload_data_flow_profiles.attribute_family_id', '=', 'attribute_families.id')
->select('bulkupload_data_flow_profiles.id',
'bulkupload_data_flow_profiles.name as profile_name', 'attribute_families.name', 'bulkupload_data_flow_profiles.locale_code', 'bulkupload_data_flow_profiles.created_at');
->select('bulkupload_data_flow_profiles.id', 'bulkupload_data_flow_profiles.name as profile_name', 'attribute_families.name', 'bulkupload_data_flow_profiles.locale_code', 'bulkupload_data_flow_profiles.created_at');

$this->addFilter('created_at', 'bulkupload_data_flow_profiles.created_at');
$this->addFilter('profile_name', 'bulkupload_data_flow_profiles.name');
Expand All @@ -30,11 +32,16 @@ public function prepareQueryBuilder()
$this->setQueryBuilder($queryBuilder);
}

/**
* Add Column
*
* @return void
*/
public function addColumns()
{
$this->addColumn([
'index' => 'profile_name',
'label' => trans('bulkupload::app.admin.bulk-upload.data-flow-profile.name'),
'label' => __('bulkupload::app.admin.bulk-upload.data-flow-profile.name'),
'type' => 'string',
'searchable' => true,
'sortable' => true,
Expand All @@ -43,7 +50,7 @@ public function addColumns()

$this->addColumn([
'index' => 'name',
'label' => trans('admin::app.catalog.products.familiy'),
'label' => __('admin::app.catalog.products.family'),
'type' => 'string',
'searchable' => true,
'sortable' => true,
Expand All @@ -52,7 +59,7 @@ public function addColumns()

$this->addColumn([
'index' => 'locale_code',
'label' => trans('bulkupload::app.admin.bulk-upload.data-flow-profile.data-grid.locale_code'),
'label' => __('bulkupload::app.admin.bulk-upload.data-flow-profile.data-grid.locale_code'),
'type' => 'string',
'searchable' => true,
'sortable' => true,
Expand All @@ -61,37 +68,41 @@ public function addColumns()

$this->addColumn([
'index' => 'created_at',
'label' => trans('bulkupload::app.admin.bulk-upload.data-flow-profile.data-grid.created-at'),
'label' => __('bulkupload::app.admin.bulk-upload.data-flow-profile.data-grid.created-at'),
'type' => 'datetime',
'sortable' => true,
'searchable' => false,
'filterable' => true
]);
}

/**
* Prepare actions
*
* @return void
*/
public function prepareActions()
{
$this->addAction([
'type' => 'Edit',
'title' => trans('admin::app.datagrid.edit'),
'method' => 'GET',
'route' => 'bulkupload.admin.profile.edit',
'icon' => 'icon pencil-lg-icon',
'title' => ''

]);

$this->addAction([
'type' => trans('admin::app.datagrid.delete'),
'method' => 'POST',
'route' => 'bulkupload.admin.profile.delete',
'confirm_text' => trans('ui::app.datagrid.massaction.delete'),
'icon' => 'icon trash-icon',
'title' => ''
'title' => trans('admin::app.datagrid.delete'),
'method' => 'POST',
'route' => 'bulkupload.admin.profile.delete',
'icon' => 'icon trash-icon',
]);

$this->enableAction = true;
}

/**
* Prepare mass actions
*
* @return void
*/
public function prepareMassActions()
{
$this->addMassAction([
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ public function up()
*/
public function down()
{
//
Schema::table('bulkupload_data_flow_profiles', function(Blueprint $table) {
$table->dropColumn('locale_code');
});
}
}
131 changes: 131 additions & 0 deletions packages/Webkul/Bulkupload/src/Helpers/ImportProduct.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
<?php

namespace Webkul\Bulkupload\Helpers;

use Webkul\Bulkupload\Repositories\{ImportProductRepository, DataFlowProfileRepository};

class ImportProduct
{
/**
* Create a new controller instance.
*
* @param \Webkul\Bulkupload\Repositories\ImportProductRepository $importProductRepository
* @param \Webkul\Bulkupload\Repositories\DataFlowProfileRepository $dataFlowProfileRepository
*
* @return void
*/
public function __construct(
protected ImportProductRepository $importProductRepository,
protected DataFlowProfileRepository $dataFlowProfileRepository
) {}

/**
* store import products for profile execution
*
* @return \Illuminate\Http\Response
*/
public function store()
{
$valid_extension = ['csv', 'xls', 'xlsx'];
$valid_image_extension = ['zip', 'rar'];

$imageDir = 'imported-products/admin/images';
$fileDir = 'imported-products/admin/files';
$linkFilesDir = 'imported-products/admin/link-files';
$linkSampleFilesDir = 'imported-products/admin/link-sample-files';
$sampleFileDir = 'imported-products/admin/sample-file';

if (request()->has('is_downloadable')) {
$product['is_downloadable'] = 1;

if (
request()->hasFile('link_files')
&& ! in_array(request()->file('link_files')->getClientOriginalExtension(), $valid_image_extension)
) {
$uploadedLinkFiles = request()->file('link_files')->storeAs($linkFilesDir, uniqid() . '.' . request()->file('link_files')->getClientOriginalExtension());

$product['upload_link_files'] = $uploadedLinkFiles;
} else {
session()->flash('error', __('bulkupload::app.admin.bulk-upload.messages.file-format-error'));

return redirect()->route('admin.bulk-upload.index');
}

if (request()->input('is_link_have_sample')) {
$product['is_links_have_samples'] = 1;

if (in_array(request()->file('link_sample_files')->getClientOriginalExtension(), $valid_image_extension)) {
$uploadedLinkSampleFiles = request()->file('link_sample_files')->storeAs($linkSampleFilesDir, uniqid().'.'.request()->file('link_sample_files')->getClientOriginalExtension());

$product['upload_link_sample_files'] = $uploadedLinkSampleFiles;
} else {
session()->flash('error', __('bulkupload::app.admin.bulk-upload.messages.file-format-error'));

return redirect()->route('admin.bulk-upload.index');
}
}

if (request()->input('is_sample')) {
$product['is_samples_available'] = 1;

if (in_array(request()->file('sample_file')->getClientOriginalExtension(), $valid_image_extension)) {
$uploadedSampleFiles = request()->file('sample_file')->storeAs($sampleFileDir, uniqid().'.'.request()->file('sample_file')->getClientOriginalExtension());

$product['upload_sample_files'] = $uploadedSampleFiles;
} else {
session()->flash('error', __('bulkupload::app.admin.bulk-upload.messages.file-format-error'));

return redirect()->route('admin.bulk-upload.index');
}
}
}

$product['data_flow_profile_id'] = request()->input('data_flow_profile');
$product['attribute_family_id'] = request()->input('attribute_family');

if (
request()->hasFile('image_path')
&& in_array(request()->file('image_path')->getClientOriginalExtension(), $valid_image_extension)
&& in_array(request()->file('file_path')->getClientOriginalExtension(), $valid_extension)
) {
$uploadedImage = request()->file('image_path')->storeAs($imageDir, uniqid().'.'.request()->file('image_path')->getClientOriginalExtension());

$product['image_path'] = $uploadedImage;

$uploadedFile = request()->file('file_path')->storeAs($fileDir, uniqid() . '.' . request()->file('file_path')->getClientOriginalExtension());

$product['file_path'] = $uploadedFile;
} elseif (
! request()->hasFile('image_path')
&& in_array(request()->file('file_path')->getClientOriginalExtension(), $valid_extension)
) {
$product['image_path'] = '';

$uploadedFile = request()->file('file_path')->storeAs($fileDir, uniqid() . '.' . request()->file('file_path')->getClientOriginalExtension());

$product['file_path'] = $uploadedFile;
} else {
session()->flash('error', __('bulkupload::app.admin.bulk-upload.messages.file-format-error'));

return redirect()->route('admin.bulk-upload.index');
}

$importedProduct = $this->importProductRepository->findOneByField('data_flow_profile_id', request()->input('data_flow_profile'));

if ($importedProduct) {
$this->dataFlowProfileRepository->update(['run_status' => '0'], request()->input('data_flow_profile'));

$this->importProductRepository->update($product, $importedProduct->id);

session()->flash('success', __('bulkupload::app.admin.bulk-upload.messages.update-profile'));

return redirect()->route('admin.bulk-upload.index');
}

$this->importProductRepository->create($product);

session()->flash('success', __('bulkupload::app.admin.bulk-upload.messages.profile-saved'));

return redirect()->route('admin.bulk-upload.index');
}
}
Loading