Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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 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
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/BulkProductRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ public function productRepositoryUpdateForVariants(array $data, $id, $attribute

$this->productInventoryRepository->saveInventories($data, $product);

$this->productImageRepository->uploadImages($data, $product);
// $this->productImageRepository->uploadImages($data, $product);
}

if (isset($data['channels'])) {
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
38 changes: 38 additions & 0 deletions src/Repositories/Products/ConfigurableProductRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,44 @@ public function createProduct($requestData, $imageZipName, $product)
$data['weight'] = (string)$csvData[$i]['super_attribute_weight'];
$data['status'] = (string)$csvData[$i]['status'];

//Variant Product Images
$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[$i]['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, $configSimpleproduct, $imageZipName);
} else if (isset($csvData[$i]['images'])) {
$this->productImageRepository->bulkuploadImages($data, $configSimpleproduct, $imageZipName = null);
}

if ( isset($data['super_attributes'])) {
foreach ($data['super_attributes'] as $attributeCode => $attributeOptions) {
$attribute = $this->attributeRepository->findOneByField('code', $attributeCode);
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>
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
categories_slug,name,description,short_description,sku,price,special_price,special_price_from,special_price_to,inventory_sources,inventories,weight,meta_title,meta_keywords,meta_description,color,size,url_key,tax_category_id,new,featured,visible_individually,status,cost,width,height,depth,type,attribute_family_name,images,guest_checkout
root,temp1,temp1,shortdesc,updatedSKU,100,80,2019-05-02,2020-05-20,default,123,12,Test Title,Test Keyword,Test Description,Red,M,erwer,,1,1,1,1,10,34,34,234,simple,Default,"banner.jpeg,bg.jpg,download.jpeg",1
root,temp1sdvc,fdh,temp1,temp21,200,80,2019-05-02,2020-05-20,default,124,12,Test Title,Test Keyword,Test Description,Green,M,dsfvg,,1,1,1,1,10,34,34,234,simple,Default,"download (1).jpeg,download (2).jpeg,men-jacket.jpg",1
root,hurray,temp1,temp1,,300,80,2019-05-02,2020-05-20,default,125,12,Test Title,Test Keyword,Test Description,Yellow,M,rthg,,1,1,1,1,10,34,34,234,simple,Default,"w-jeans.jpeg,w-shirt.jpeg,download (2).jpeg",1
root,hurray,temp1,temp1,temphurray,300,80,2019-05-02,2020-05-20,default,125,12,Test Title,Test Keyword,Test Description,Yellow,M,rthg,,1,1,1,1,10,34,34,234,simple,Default,"w-jeans.jpeg,w-shirt.jpeg,download (2).jpeg",1
root,cbv,temp1,temp1,temp41,400,80,2019-05-02,2020-05-20,default,126,12,Test Title,Test Keyword,Test Description,Black,M,temp3,,1,1,1,1,10,34,34,234,simple,Default,"bg.jpg,men-jacket.jpg,w-shirt.jpeg",1
Binary file not shown.