PDO::ERRMODE_EXCEPTION, PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC] ); const TABLE = 'tx_vitec_domain_model_product'; const CATEGORY_UID = 76; // "Aetria" - provisional, see header $products = [ ['title' => 'ArtioSign', 'slug' => 'artiosign'], ['title' => 'ArtioView', 'slug' => 'artioview'], ]; // The product table has NO sorting column (list order comes from the // category tree) - only the pid is taken from the existing records. $ref = $pdo->query('SELECT pid FROM ' . TABLE . ' WHERE deleted = 0 GROUP BY pid ORDER BY COUNT(*) DESC LIMIT 1')->fetch(); if (!$ref) { exit("No existing product records to take the pid from.\n"); } $pid = (int)$ref['pid']; $catName = $pdo->query('SELECT title FROM sys_category WHERE uid = ' . CATEGORY_UID . ' AND deleted = 0')->fetchColumn(); if ($catName === false) { exit("Category " . CATEGORY_UID . " not found - adjust CATEGORY_UID.\n"); } foreach ($products as $product) { $exists = $pdo->prepare('SELECT uid FROM ' . TABLE . ' WHERE slug = ? AND deleted = 0'); $exists->execute([$product['slug']]); if (($uid = $exists->fetchColumn()) !== false) { echo $product['title'] . ": exists already (uid $uid) - skipped.\n"; continue; } $insert = $pdo->prepare('INSERT INTO ' . TABLE . ' (pid, tstamp, crdate, hidden, title, slug, categories) VALUES (?, ?, ?, 1, ?, ?, 1)'); $insert->execute([$pid, time(), time(), $product['title'], $product['slug']]); $uid = (int)$pdo->lastInsertId(); $mm = $pdo->prepare('INSERT INTO sys_category_record_mm (uid_local, uid_foreign, tablenames, fieldname, sorting, sorting_foreign) VALUES (?, ?, ?, ?, 0, 1)'); $mm->execute([CATEGORY_UID, $uid, TABLE, 'categories']); echo $product['title'] . ": created uid $uid (pid $pid, HIDDEN, category $catName).\n"; } echo "Done. Next: vendor/bin/typo3 cache:flush\n";