subscribtion category variants / system category variants

This commit is contained in:
2025-11-04 01:50:05 -08:00
parent 868f9dbcce
commit a471be8ff9
13 changed files with 254 additions and 12 deletions

View File

@@ -0,0 +1,25 @@
<?php
declare(strict_types=1);
use Migrations\BaseMigration;
class AddIsSystemToProductCategoryVariants extends BaseMigration
{
/**
* Change Method.
*
* More information on this method is available here:
* https://book.cakephp.org/migrations/4/en/migrations.html#the-change-method
* @return void
*/
public function change(): void
{
$table = $this->table('product_category_variants');
$table->addColumn('is_system_variant', 'boolean', [
'default' => false,
'limit' => 11,
'null' => false,
]);
$table->update();
}
}

View File

@@ -0,0 +1,55 @@
<?php
declare(strict_types=1);
namespace Seeds;
use Migrations\BaseSeed;
/**
* CreateSystemCategoryVariants seed.
*/
class CreateSystemCategoryVariantsSeed extends BaseSeed
{
/**
* Run Method.
*
* Write your database seeder using this method.
*
* More information on writing seeds is available here:
* https://book.cakephp.org/migrations/4/en/seeding.html
*
* @return void
*/
public function run(): void
{
$data = [
[
'id' => \Cake\Utility\Text::uuid(),
'name' => 'Subscription Length',
'product_category_id' => null,
'enabled' => true,
'is_system_variant' => true,
],
[
'id' => \Cake\Utility\Text::uuid(),
'name' => 'Subscription Length Units',
'product_category_id' => null,
'enabled' => true,
'is_system_variant' => true,
],
];
$table = $this->table('product_category_variants');
$toInsert = [];
foreach ($data as $singleRecordToInsert) {
$stmt = $this->query('SELECT * FROM product_category_variants WHERE name="' . $singleRecordToInsert['name'] . '" AND product_category_id IS NULL;'); // returns PDOStatement
$rows = $stmt->fetchAll(); // returns the result as an array
if ($rows) {
continue;
}
$toInsert[] = $singleRecordToInsert;
}
if ($toInsert) {
$table->insert($data)->save();
}
}
}