Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Обновление моделей товаров, импорт из таблиц MODX, доработка админки
- Loading branch information
Showing
20 changed files
with
657 additions
and
107 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?php | ||
|
||
use App\Models\File; | ||
use App\Models\Product; | ||
use Phinx\Seed\AbstractSeed; | ||
use Slim\Psr7\UploadedFile; | ||
use Vesp\Services\Eloquent; | ||
|
||
class ProductFiles extends AbstractSeed | ||
{ | ||
|
||
public function getDependencies(): array | ||
{ | ||
return ['Categories', 'Products']; | ||
} | ||
|
||
public function run(): void | ||
{ | ||
$pdo = (new Eloquent())->getDatabaseManager()->getPdo(); | ||
$stmt = $pdo->prepare( | ||
'SELECT * FROM `modx_ms2_product_files` WHERE `product_id` = :remote_id AND `parent` = 0' | ||
); | ||
|
||
/** @var Product $product */ | ||
foreach (Product::query()->cursor() as $product) { | ||
$stmt->execute([':remote_id' => $product->remote_id]); | ||
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) { | ||
// Check if File already uploaded | ||
if ($product->productFiles()->where('remote_id', $row['id'])->count()) { | ||
continue; | ||
} | ||
|
||
// Upload new | ||
$filename = tempnam(getenv('UPLOAD_DIR'), 'img_'); | ||
file_put_contents($filename, file_get_contents('https://i.pravatar.cc/500')); | ||
$data = new UploadedFile($filename, $row['name'] ?? basename($filename), mime_content_type($filename)); | ||
$file = new File(); | ||
$file->uploadFile($data); | ||
$product->productFiles()->insert([ | ||
'product_id' => $product->id, | ||
'file_id' => $file->id, | ||
'rank' => $row['rank'], | ||
'remote_id' => $row['id'], | ||
]); | ||
unlink($filename); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
|
||
use App\Models\Product; | ||
use App\Models\ProductLink; | ||
use Phinx\Seed\AbstractSeed; | ||
use Vesp\Services\Eloquent; | ||
|
||
class ProductLinks extends AbstractSeed | ||
{ | ||
public function getDependencies(): array | ||
{ | ||
return ['Products']; | ||
} | ||
|
||
public function run(): void | ||
{ | ||
$pdo = (new Eloquent())->getDatabaseManager()->getPdo(); | ||
$stmt = $pdo->query("SELECT * FROM `modx_ms2_product_links`"); | ||
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) { | ||
/** @var Product $product */ | ||
$product = Product::query()->where('remote_id', $row['master'])->first(); | ||
/** @var Product $link */ | ||
$link = Product::query()->where('remote_id', $row['slave'])->first(); | ||
if ($product && $link) { | ||
ProductLink::query()->updateOrInsert(['product_id' => $product->id, 'link_id' => $link->id]); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.