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

Added Image upload functionality for configurable product variants #84

Open
wants to merge 15 commits into
base: v1.3.3
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 13 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
11 changes: 10 additions & 1 deletion src/DataGrids/Admin/ProfileDataGrid.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ 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.created_at');
'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 Down Expand Up @@ -50,6 +50,15 @@ public function addColumns()
'filterable' => true
]);

$this->addColumn([
'index' => 'locale_code',
'label' => trans('bulkupload::app.admin.bulk-upload.data-flow-profile.data-grid.locale_code'),
'type' => 'string',
'searchable' => true,
'sortable' => true,
'filterable' => true
]);

$this->addColumn([
'index' => 'created_at',
'label' => trans('bulkupload::app.admin.bulk-upload.data-flow-profile.data-grid.created-at'),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class AlterBulkuploadDataFlowProfilesTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('bulkupload_data_flow_profiles', function(Blueprint $table) {
$table->string('locale_code');
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
//
}
}
5 changes: 4 additions & 1 deletion src/Http/Controllers/Admin/BulkUploadController.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,14 @@ public function store()
{
request()->validate([
'name' => 'required|unique:bulkupload_data_flow_profiles',
'attribute_family' => 'required'
'attribute_family' => 'required',
'locale_code' => 'required'
]);

$dataFlowProfileAdmin['name'] = request()->name;
$dataFlowProfileAdmin['attribute_family_id'] = request()->attribute_family;
$dataFlowProfileAdmin['locale_code'] = request()->locale_code;


$this->dataFlowProfileRepository->create($dataFlowProfileAdmin);

Expand Down
6 changes: 5 additions & 1 deletion src/Providers/BulkUploadServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ public function boot()
__DIR__ . '/../../publishable/assets' => public_path('themes/default/assets'),
], 'public');

$this->publishes([
__DIR__ . '/../Resources/views/admin/bulk-upload/layouts/nav-aside.blade.php' => resource_path('views/vendor/admin/layouts/nav-aside.blade.php'),
]);

view()->composer(['bulkupload::admin.bulk-upload.upload-files.index'], function ($view) {
$items = [];

Expand Down Expand Up @@ -58,7 +62,7 @@ protected function registerConfig()
$this->mergeConfigFrom(
dirname(__DIR__) . '/Config/system.php', 'core'
);

$this->mergeConfigFrom(
dirname(__DIR__) . '/Config/admin-menu.php', 'menu.admin'
);
Expand Down
2 changes: 1 addition & 1 deletion src/Repositories/ProductImageRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public function bulkuploadImages($data, $product, $imageZipName)
{
if (isset($data['images'])) {
foreach($data['images'] as $key => $value) {
if (is_null($imageZipName)) {
if ( ! is_null($imageZipName)) {
$files = "imported-products/extracted-images/admin/".$data['dataFlowProfileRecordId'].'/'. $imageZipName['dirname'].'/'.basename($value);
} else {
$files = "imported-products/extracted-images/admin/".$data['dataFlowProfileRecordId'].'/'.basename($value);
Expand Down
4 changes: 3 additions & 1 deletion src/Repositories/Products/BookingProductRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,9 @@ public function store($csvData, $i, $dataFlowProfileRecord, $requestData, $image
$data['categories'] = $categoryID;

$data['channel'] = core()->getCurrentChannel()->code;
$data['locale'] = core()->getDefaultChannel()->default_locale->code;

$dataProfile = app('Webkul\Bulkupload\Repositories\DataFlowProfileRepository')->findOneByfield(['id' => $data['dataFlowProfileRecordId']]);
$data['locale'] = $dataProfile->locale_code;

//customerGroupPricing
if (isset($csvData['customer_group_prices']) && ! empty($csvData['customer_group_prices'])) {
Expand Down
4 changes: 3 additions & 1 deletion src/Repositories/Products/BundledProductRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,9 @@ public function store($csvData, $i, $dataFlowProfileRecord, $requestData, $image

$data['categories'] = $categoryID;
$data['channel'] = core()->getCurrentChannel()->code;
$data['locale'] = core()->getDefaultChannel()->default_locale->code;

$dataProfile = app('Webkul\Bulkupload\Repositories\DataFlowProfileRepository')->findOneByfield(['id' => $data['dataFlowProfileRecordId']]);
$data['locale'] = $dataProfile->locale_code;

//customerGroupPricing
if (isset($csvData['customer_group_prices']) && ! empty($csvData['customer_group_prices'])) {
Expand Down
37 changes: 37 additions & 0 deletions src/Repositories/Products/ConfigurableProductRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,43 @@ public function createProduct($requestData, $imageZipName, $product)
}
}

$individualProductimages = explode(',', $csvData[$i]['images']);

if (isset($imageZipName)) {
$images = Storage::disk('local')->files('public/imported-products/extracted-images/admin/'.$dataFlowProfileRecord->id.'/'.$imageZipName['dirname'].'/');

foreach ($images as $imageArraykey => $imagePath) {
$imageName = explode('/', $imagePath);

if (in_array(last($imageName), preg_replace('/[\'"]/', '',$individualProductimages))) {
$data['images'][$imageArraykey] = $imagePath;
}
}
} else if (isset($csvData['images'])) {
foreach ($individualProductimages as $imageArraykey => $imageURL)
{
if (filter_var(trim($imageURL), FILTER_VALIDATE_URL)) {
$imagePath = storage_path('app/public/ imported-products/extracted-images/admin/'. $dataFlowProfileRecord->id);

if (!file_exists($imagePath)) {
mkdir($imagePath, 0777, true);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why don't you use Storage::makeDirectory($imagePath);?

}

$imageFile = $imagePath.'/'.basename($imageURL) ;

file_put_contents($imageFile, file_get_contents (trim($imageURL)));

$data['images'][$imageArraykey] = $imageFile;
}
}
}

if (isset($imageZipName)) {
$this->productImageRepository->bulkuploadImages($data, $product, $imageZipName);
} else if (isset($csvData['images'])) {
$this->productImageRepository->bulkuploadImages($data, $product, $imageZipName = null);
}

$data['channel'] = core()->getCurrentChannel()->code;
$data['locale'] = core()->getDefaultChannel()->default_locale->code;
$data['dataFlowProfileRecordId'] = $dataFlowProfileRecord->id;
Expand Down
4 changes: 3 additions & 1 deletion src/Repositories/Products/DownloadableProductRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,9 @@ public function store($csvData, $i, $dataFlowProfileRecord, $requestData, $image

$data['categories'] = $categoryID;
$data['channel'] = core()->getCurrentChannel()->code;
$data['locale'] = core()->getDefaultChannel()->default_locale->code;

$dataProfile = app('Webkul\Bulkupload\Repositories\DataFlowProfileRepository')->findOneByfield(['id' => $data['dataFlowProfileRecordId']]);
$data['locale'] = $dataProfile->locale_code;

//customerGroupPricing
if (isset($csvData['customer_group_prices']) && ! empty($csvData['customer_group_prices'])) {
Expand Down
4 changes: 3 additions & 1 deletion src/Repositories/Products/GroupedProductRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,9 @@ public function store($csvData, $i, $dataFlowProfileRecord, $requestData, $image

$data['categories'] = $categoryID;
$data['channel'] = core()->getCurrentChannel()->code;
$data['locale'] = core()->getDefaultChannel()->default_locale->code;

$dataProfile = app('Webkul\Bulkupload\Repositories\DataFlowProfileRepository')->findOneByfield(['id' => $data['dataFlowProfileRecordId']]);
$data['locale'] = $dataProfile->locale_code;

//customerGroupPricing
if (isset($csvData['customer_group_prices']) && ! empty($csvData['customer_group_prices'])) {
Expand Down
5 changes: 4 additions & 1 deletion src/Repositories/Products/SimpleProductRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,10 @@ public function store($csvData, $i, $dataFlowProfileRecord, $requestData, $image

$data['categories'] = $categoryID;
$data['channel'] = core()->getCurrentChannel()->code;
$data['locale'] = core()->getDefaultChannel()->default_locale->code;

$dataProfile = app('Webkul\Bulkupload\Repositories\DataFlowProfileRepository')->findOneByfield(['id' => $data['dataFlowProfileRecordId']]);

$data['locale'] = $dataProfile->locale_code;

//customerGroupPricing
if (isset($csvData['customer_group_prices']) && ! empty($csvData['customer_group_prices'])) {
Expand Down
4 changes: 3 additions & 1 deletion src/Repositories/Products/VirtualProductRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,9 @@ public function store($csvData, $i, $dataFlowProfileRecord, $requestData, $image

$data['categories'] = $categoryID;
$data['channel'] = core()->getCurrentChannel()->code;
$data['locale'] = core()->getDefaultChannel()->default_locale->code;

$dataProfile = app('Webkul\Bulkupload\Repositories\DataFlowProfileRepository')->findOneByfield(['id' => $data['dataFlowProfileRecordId']]);
$data['locale'] = $dataProfile->locale_code;

//customerGroupPricing
if (isset($csvData['customer_group_prices']) && ! empty($csvData['customer_group_prices'])) {
Expand Down
3 changes: 2 additions & 1 deletion src/Resources/lang/en/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
'update-profile' => 'Update',

'data-grid' => [
'created-at' => 'Created At'
'created-at' => 'Created At',
'locale_code' => 'Locale code'
]
],

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,19 @@
<span class="control-error">{{ $errors->first('attribute_family') }}</span>
</div>

<div class="control-group" :class="[errors.has('locale_code') ? 'has-error' : '']">
<label for="locale_code" class="required">{{ __('admin::app.settings.channels.default-locale') }}</label>

<select v-validate="'required'" class="control" id="locale_code" name="locale_code" data-vv-as="&quot;{{ __('admin::app.settings.channels.default-locale') }}&quot;">
@foreach (core()->getAllLocales() as $localeModel)
<option value="{{ $localeModel->code }}">
{{ $localeModel->name }}
</option>
@endforeach
</select>
<span class="control-error" v-if="errors.has('locale_code')">@{{ errors.first('locale_code') }}</span>
</div>

<div class="page-action" style="display:flex; justify-content: space-between;">
<button type="submit" class="btn btn-lg btn-primary">
{{ __('bulkupload::app.admin.bulk-upload.upload-files.save') }}
Expand Down
41 changes: 41 additions & 0 deletions src/Resources/views/admin/bulk-upload/layouts/nav-aside.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<div class="aside-nav">

{{-- button for collapsing aside nav --}}
<nav-slide-button icon-class="accordian-left-icon"></nav-slide-button>

<ul>
@if (request()->route()->getName() != 'admin.configuration.index')
<?php $keys = explode('.', $menu->currentKey); ?>
@if(isset($keys) && strlen($keys[0]))
@foreach (\Illuminate\Support\Arr::get($menu->items, current($keys) . '.children') as $item)

@if (!core()->getConfigData('bulkupload.settings.general.status') && $item['key'] == 'catalog.bulkupload')
<?php continue; ?>
@endif

<li class="{{ $menu->getActive($item) }}">
<a href="{{ $item['url'] }}">
{{ trans($item['name']) }}

@if ($menu->getActive($item))
<i class="angle-right-icon"></i>
@endif
</a>
</li>
@endforeach
@endif
@else
@foreach ($config->items as $key => $item)
<li class="{{ $item['key'] == request()->route('slug') ? 'active' : '' }}">
<a href="{{ route('admin.configuration.index', $item['key']) }}">
{{ isset($item['name']) ? trans($item['name']) : '' }}

@if ($item['key'] == request()->route('slug'))
<i class="angle-right-icon"></i>
@endif
</a>
</li>
@endforeach
@endif
</ul>
</div>