13-05-2026 Waren Wirtschaft
This commit is contained in:
parent
9ce711d6b2
commit
ca3eb663fe
40 changed files with 1000 additions and 189 deletions
|
|
@ -11,6 +11,7 @@ use App\Models\ProductCategory;
|
|||
use App\Models\ProductImage;
|
||||
use App\Models\ProductIngredient;
|
||||
use App\Services\Slim;
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
|
||||
class ProductRepository extends BaseRepository
|
||||
{
|
||||
|
|
@ -345,7 +346,6 @@ class ProductRepository extends BaseRepository
|
|||
$this->model->wp_number = null;
|
||||
$this->model->save();
|
||||
|
||||
// categories
|
||||
foreach ($model->categories as $category) {
|
||||
ProductCategory::create([
|
||||
'product_id' => $this->model->id,
|
||||
|
|
@ -353,7 +353,6 @@ class ProductRepository extends BaseRepository
|
|||
]);
|
||||
}
|
||||
|
||||
// attributes
|
||||
foreach ($model->attributes as $attribute) {
|
||||
ProductAttribute::create([
|
||||
'product_id' => $this->model->id,
|
||||
|
|
@ -361,6 +360,15 @@ class ProductRepository extends BaseRepository
|
|||
'attribute_id' => $attribute->attribute_id,
|
||||
]);
|
||||
}
|
||||
|
||||
foreach ($model->attribute_variants as $variant) {
|
||||
ProductAttribute::create([
|
||||
'product_id' => $this->model->id,
|
||||
'type_id' => $variant->type_id,
|
||||
'attribute_id' => $variant->attribute_id,
|
||||
]);
|
||||
}
|
||||
|
||||
foreach ($model->p_ingredients()->orderByPivot('pos')->get() as $ing) {
|
||||
ProductIngredient::create([
|
||||
'product_id' => $this->model->id,
|
||||
|
|
@ -392,16 +400,38 @@ class ProductRepository extends BaseRepository
|
|||
}
|
||||
$this->model->packagings()->sync($packSync);
|
||||
|
||||
// images
|
||||
foreach ($model->images as $image) {
|
||||
foreach ($model->country_prices as $cp) {
|
||||
CountryPrice::create([
|
||||
'country_id' => $cp->country_id,
|
||||
'product_id' => $this->model->id,
|
||||
'c_price' => $cp->c_price,
|
||||
'c_tax' => $cp->c_tax,
|
||||
'c_price_old' => $cp->c_price_old,
|
||||
'c_currency' => $cp->c_currency,
|
||||
]);
|
||||
}
|
||||
|
||||
$this->copyImages($model->images, 'product');
|
||||
$this->copyImages($model->whitelabel_images, 'wllogo');
|
||||
|
||||
return $this->model;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Collection<int, ProductImage> $images
|
||||
*/
|
||||
protected function copyImages($images, string $type): void
|
||||
{
|
||||
foreach ($images as $image) {
|
||||
$name = Slim::sanitizeFileName($image->original_name);
|
||||
$name = uniqid().'_'.$name;
|
||||
|
||||
// copy
|
||||
$data = \Storage::disk('public')->copy(
|
||||
'images/product/'.$image->product_id.'/'.$image->filename,
|
||||
'images/product/'.$this->model->id.'/'.$name
|
||||
);
|
||||
$sourcePath = 'images/product/'.$image->product_id.'/'.$image->filename;
|
||||
$targetPath = 'images/product/'.$this->model->id.'/'.$name;
|
||||
|
||||
if (\Storage::disk('public')->exists($sourcePath)) {
|
||||
\Storage::disk('public')->copy($sourcePath, $targetPath);
|
||||
}
|
||||
|
||||
ProductImage::create([
|
||||
'product_id' => $this->model->id,
|
||||
|
|
@ -411,12 +441,11 @@ class ProductRepository extends BaseRepository
|
|||
'ext' => $image->ext,
|
||||
'mine' => $image->mine,
|
||||
'size' => $image->size,
|
||||
'pos' => $image->pos,
|
||||
'active' => $image->active ?? true,
|
||||
'attributes' => $image->attributes,
|
||||
|
||||
]);
|
||||
}
|
||||
|
||||
return $this->model;
|
||||
}
|
||||
|
||||
public function delete() {}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue