restore composer.json, add mysqli extension
This commit is contained in:
95
app/Jobs/Dashboard/Product/Child.php
Executable file
95
app/Jobs/Dashboard/Product/Child.php
Executable file
@@ -0,0 +1,95 @@
|
||||
<?php
|
||||
|
||||
namespace App\Jobs\Dashboard\Product;
|
||||
|
||||
use App\Models\Product;
|
||||
use App\Models\Screen;
|
||||
use Carbon\Carbon;
|
||||
use App\Api\ImageResize;
|
||||
use App\Http\Requests\Dashboard\Product\Store as StoreRequest;
|
||||
use Illuminate\Support\Facades\Date;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
|
||||
class Child
|
||||
{
|
||||
protected $request;
|
||||
protected $image;
|
||||
protected $product;
|
||||
protected $size;
|
||||
|
||||
/**
|
||||
* Child constructor.
|
||||
* @param StoreRequest $request
|
||||
* @param Product $product
|
||||
*/
|
||||
public function __construct(StoreRequest $request, Product $product)
|
||||
{
|
||||
$this->request = $request;
|
||||
$this->product = $product;
|
||||
$this->image = new ImageResize();
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the job.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
foreach ($this->request->colors as $color) {
|
||||
$color_id = $color['color_id'] == "null" ? null : $color['color_id'];
|
||||
$sizes = !empty($color['sizes']) ? $color['sizes'] : null;
|
||||
|
||||
$child = Product::create([
|
||||
'color_id' => $color_id,
|
||||
'sizes' => $sizes,
|
||||
'article_number' => $color['article_number'],
|
||||
'child_id' => $this->product->id,
|
||||
'published' => $this->product->published,
|
||||
'available' => true
|
||||
]);
|
||||
|
||||
if (!empty($color['screens'])) {
|
||||
foreach ($color['screens'] as $screen) {
|
||||
$folder = Carbon::now()->format('Y/m/d');
|
||||
|
||||
$path = $screen['image']->store($screen['image']);
|
||||
|
||||
$thumbPath = $this->storeImageToS3($screen['image']);
|
||||
|
||||
Screen::create([
|
||||
'path' => $path,
|
||||
'path_thumb' => $thumbPath,
|
||||
'name' => basename($path),
|
||||
'product_id' => $child->id,
|
||||
'size' => $this->size
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function storeImageToS3($image): string
|
||||
{
|
||||
$path = '';
|
||||
// first store temp file and resize it, then upload to s3
|
||||
// 1 - store temp file
|
||||
$tempPath = $image->store('temp', 'public');
|
||||
if ($tempPath) {
|
||||
$tempFilePath = storage_path('app/public/' . $tempPath);
|
||||
$image = new ImageResize();
|
||||
$path = $image->resize($tempPath, 322, 'screens');
|
||||
|
||||
$this->size = filesize(public_path($path));
|
||||
|
||||
// 2 - upload local $path to s3
|
||||
// Store the image on S3
|
||||
if (in_array(env('FILESYSTEM_DISK'), ['s3', 'minio'])) {
|
||||
Storage::disk('s3')->put($path, file_get_contents(public_path($path)));
|
||||
unlink($path);
|
||||
}
|
||||
}
|
||||
|
||||
return $path;
|
||||
}
|
||||
}
|
||||
100
app/Jobs/Dashboard/Product/ChildUpdate.php
Executable file
100
app/Jobs/Dashboard/Product/ChildUpdate.php
Executable file
@@ -0,0 +1,100 @@
|
||||
<?php
|
||||
|
||||
namespace App\Jobs\Dashboard\Product;
|
||||
|
||||
use App\Models\Product;
|
||||
use App\Models\Screen;
|
||||
use Carbon\Carbon;
|
||||
|
||||
use App\Api\ImageResize;
|
||||
use App\Http\Requests\Dashboard\Product\Update as UpdateRequest;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
|
||||
class ChildUpdate
|
||||
{
|
||||
|
||||
protected $product;
|
||||
protected $request;
|
||||
protected $image;
|
||||
|
||||
/**
|
||||
* ChildUpdate constructor.
|
||||
* @param UpdateRequest $request
|
||||
* @param Product $product
|
||||
*/
|
||||
public function __construct(UpdateRequest $request, Product $product)
|
||||
{
|
||||
$this->request = $request;
|
||||
$this->product = $product;
|
||||
$this->image = new ImageResize();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
if ($this->request->colors)
|
||||
foreach ($this->request->colors as $color) {
|
||||
|
||||
$id = $color['id'] == "null" ? null : $color['id'];
|
||||
$color_id = $color['color_id'] == "null" ? null : $color['color_id'];
|
||||
$sizes = !empty($color['sizes']) ? $color['sizes'] : null;
|
||||
|
||||
if ($id == null) {
|
||||
$child = Product::create([
|
||||
'color_id' => $color_id,
|
||||
'sizes' => $sizes,
|
||||
'article_number' => $color['article_number'],
|
||||
'child_id' => $this->product->id,
|
||||
//'published' => $this->product->published,
|
||||
//'available' => true
|
||||
]);
|
||||
|
||||
if (!empty($color['screens'])) {
|
||||
$this->uploadScreen($color['screens'], $child->id);
|
||||
}
|
||||
} else {
|
||||
$child = Product::find($id)->update([
|
||||
'color_id' => $color_id,
|
||||
'sizes' => $sizes,
|
||||
'article_number' => $color['article_number'],
|
||||
'child_id' => $this->product->id,
|
||||
//'published' => $this->product->published,
|
||||
//'available' => true
|
||||
]);
|
||||
|
||||
if (!empty($color['screens'])) {
|
||||
$this->uploadScreen($color['screens'], $id);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $screens
|
||||
* @param $child_id
|
||||
*/
|
||||
private function uploadScreen($screens, $child_id)
|
||||
{
|
||||
if (!empty($screens)) {
|
||||
foreach ($screens as $screen) {
|
||||
if ($screen['id'] == 'undefined' || $screen['id'] == 'null' || $screen['id'] = null) {
|
||||
$folder = Carbon::now()->format('Y/m/d');
|
||||
if ($screen['image']) {
|
||||
$path = $screen['image']->store("uploads/screens/{$folder}");
|
||||
$image = Screen::create([
|
||||
'path' => $path,
|
||||
'path_thumb' => "uploads/screens/thumbs/{$folder}/" . basename($path),
|
||||
'name' => basename($path),
|
||||
'product_id' => $child_id,
|
||||
'size' => Storage::size($path)
|
||||
]);
|
||||
|
||||
$this->image->resize($image->path, 322, 'screens');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
56
app/Jobs/Dashboard/Product/Deletes.php
Executable file
56
app/Jobs/Dashboard/Product/Deletes.php
Executable file
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
namespace App\Jobs\Dashboard\Product;
|
||||
|
||||
use App\Http\Requests\Dashboard\Product\Update as Request;
|
||||
use App\Models\Screen;
|
||||
use App\Models\Product;
|
||||
|
||||
class Deletes
|
||||
{
|
||||
|
||||
protected $request;
|
||||
|
||||
public function __construct(Request $request)
|
||||
{
|
||||
$this->request = $request;
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the job.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
if ($this->request->deletes) {
|
||||
|
||||
if (!empty($this->request->deletes['screens'])) {
|
||||
foreach ($this->request->deletes['screens'] as $screen) {
|
||||
$sc = Screen::where('id', $screen)->first();
|
||||
if (!empty($sc)) {
|
||||
if (is_file($sc->path)) {
|
||||
unlink($sc->path);
|
||||
}
|
||||
|
||||
if (is_file($sc->path_thumb)) {
|
||||
unlink($sc->path_thumb);
|
||||
}
|
||||
|
||||
$sc->delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($this->request->deletes['childrens'])) {
|
||||
foreach ($this->request->deletes['childrens'] as $children) {
|
||||
$child = Product::find($children);
|
||||
if (!empty($child)) {
|
||||
$child->delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
52
app/Jobs/Dashboard/Product/Screen.php
Executable file
52
app/Jobs/Dashboard/Product/Screen.php
Executable file
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
namespace App\Jobs\Dashboard\Product;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Support\Arr;
|
||||
use App\Models\Screen as Screens;
|
||||
use App\Api\ImageResize;
|
||||
|
||||
|
||||
class Screen
|
||||
{
|
||||
protected $request;
|
||||
protected $id;
|
||||
protected $img;
|
||||
|
||||
/**
|
||||
* Screen constructor.
|
||||
* @param $request
|
||||
* @param $id
|
||||
*/
|
||||
public function __construct($request, $id)
|
||||
{
|
||||
$this->request = $request;
|
||||
$this->id = $id;
|
||||
$this->img = new ImageResize();
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the job.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$folder = Carbon::now()->format('Y/m/d');
|
||||
//$folder = 'uploads/screens/'.date('Y', time()).'/'.Carbon::now()->format('m').'/'.Carbon::now()->format('d');
|
||||
|
||||
foreach ($this->request as $screen) {
|
||||
$path = $screen->store("uploads/screens/original/{$folder}");
|
||||
$thumb = $this->img->resize($path, 350, 'screens');
|
||||
|
||||
$screens = new Screens();
|
||||
$screens->name = basename($path);
|
||||
$screens->path = $path;
|
||||
$screens->path_thumb = $thumb;
|
||||
$screens->size = filesize($path);
|
||||
$screens->product_id = $this->id;
|
||||
$screens->save();
|
||||
}
|
||||
}
|
||||
}
|
||||
76
app/Jobs/Dashboard/Product/Store.php
Executable file
76
app/Jobs/Dashboard/Product/Store.php
Executable file
@@ -0,0 +1,76 @@
|
||||
<?php
|
||||
|
||||
namespace App\Jobs\Dashboard\Product;
|
||||
|
||||
use App\Models\Product;
|
||||
use Illuminate\Support\Arr;
|
||||
|
||||
use App\Http\Requests\Dashboard\Product\Store as Request;
|
||||
|
||||
class Store
|
||||
{
|
||||
protected $attr;
|
||||
|
||||
/**
|
||||
* Store constructor.
|
||||
* @param array $attr
|
||||
*/
|
||||
public function __construct(array $attr = [])
|
||||
{
|
||||
$this->attr = Arr::only($attr, ['measurement_id', 'power', 'name', 'poster', 'poster_thumb', 'body', 'price', 'price_discount', 'price_credit', 'currency', 'slug', 'published', 'brand_id', 'short_body', 'article_number', 'leader_of_sales', 'popular', 'count', 'available', 'descriptions', 'keywords', 'title_seo', 'is_ready_solution', 'data_sheet']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @return Store
|
||||
*/
|
||||
public static function fromRequest(Request $request)
|
||||
{
|
||||
return new static([
|
||||
'name' => $request->getName(),
|
||||
//'category_id' => $request->getCategoryID(),
|
||||
'brand_id' => $request->getBrandID(),
|
||||
'measurement_id' => $request->getMeasurementId(),
|
||||
|
||||
'currency' => $request->currency,
|
||||
|
||||
'price' => $request->getPrice(),
|
||||
'price_discount' => $request->getPriceDiscount(),
|
||||
// 'price_credit' => $request->getPriceCredit(),
|
||||
|
||||
'poster' => $request->getPoster(),
|
||||
'calc' => $request->getCalc(),
|
||||
'poster_thumb' => $request->getPosterThumb(),
|
||||
'is_ready_solution' => $request->is_ready_solution == false ? 0 : 1,
|
||||
'power' => $request->power,
|
||||
|
||||
'data_sheet' => $request->getDataSheet(),
|
||||
|
||||
'body' => $request->getBody(),
|
||||
'short_body' => $request->short_body,
|
||||
|
||||
'slug' => $request->getSlug(),
|
||||
'published' => $request->getPublished(),
|
||||
// 'popular' => $request->getPopular(),
|
||||
'leader_of_sales' => $request->getLeaderOfSales(),
|
||||
|
||||
'article_number' => $request->article_number,
|
||||
'count' => $request->count,
|
||||
'available' => $request->getAvailable(),
|
||||
'keywords' => $request->keywords,
|
||||
'descriptions' => $request->descriptions,
|
||||
'title_seo' => $request->title_seo,
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$product = Product::create($this->attr);
|
||||
|
||||
return $product;
|
||||
}
|
||||
}
|
||||
70
app/Jobs/Dashboard/Product/Update.php
Executable file
70
app/Jobs/Dashboard/Product/Update.php
Executable file
@@ -0,0 +1,70 @@
|
||||
<?php
|
||||
|
||||
namespace App\Jobs\Dashboard\Product;
|
||||
|
||||
use App\Http\Requests\Dashboard\Product\Update as Request;
|
||||
use App\Models\Product;
|
||||
|
||||
class Update
|
||||
{
|
||||
protected $attr;
|
||||
protected $request;
|
||||
protected $product;
|
||||
|
||||
/**
|
||||
* @param Product $product
|
||||
* @param Request $request
|
||||
*/
|
||||
public function __construct(Product $product, Request $request)
|
||||
{
|
||||
$this->product = $product;
|
||||
$this->request = $request;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Product
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$this->product->update([
|
||||
'name' => $this->request->getName(),
|
||||
'brand_id' => $this->request->getBrandID(),
|
||||
'measurement_id' => $this->request->getMeasurementId(),
|
||||
'currency' => $this->request->currency,
|
||||
'is_ready_solution' => $this->request->is_ready_solution == 'false' ? 0 : 1,
|
||||
'price' => $this->request->getPrice(),
|
||||
'price_discount' => $this->request->getPriceDiscount(),
|
||||
'poster' => $this->request->getPoster($this->product),
|
||||
'calc' => $this->request->getCalc($this->product),
|
||||
'poster_thumb' => $this->request->getPosterThumb($this->product),
|
||||
'data_sheet' => $this->request->getDataSheet($this->product),
|
||||
'body' => $this->request->getBody(),
|
||||
'short_body' => $this->request->short_body,
|
||||
'power' => !in_array($this->request->power, [null, 'null', 'NULL']) ? $this->request->power : null,
|
||||
'slug' => $this->request->getSlug(),
|
||||
'published' => $this->request->getPublished(),
|
||||
// 'popular' => $this->request->getPopular(),
|
||||
'leader_of_sales' => $this->request->getLeaderOfSales(),
|
||||
'article_number' => $this->request->article_number,
|
||||
'count' => $this->request->count,
|
||||
'available' => $this->request->getAvailable(),
|
||||
'keywords' => $this->request->keywords,
|
||||
'descriptions' => $this->request->descriptions,
|
||||
'title_seo' => $this->request->title_seo,
|
||||
]);
|
||||
|
||||
$this->syncCategories();
|
||||
}
|
||||
|
||||
private function syncCategories()
|
||||
{
|
||||
$cats = $this->product->categories()->get();
|
||||
|
||||
$cats = array_map(function ($cat) {
|
||||
return $cat['id'];
|
||||
}, $cats->toArray());
|
||||
|
||||
$this->product->categories()->detach($cats);
|
||||
$this->product->categories()->attach([$this->request->getCategoryID()]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user