I hacked this together a few years back to auto generate CEON product URIs - it's crude but it's worked well for me, and it's free. Simply copy one of the admin pages and drop the code in, run as needed to update product URIs.
It lists all the categories on the site. Click the category name to auto populate the product URIs into the database.
Notes:
- It uses the old mysql function because I haven't kept up to date on coding practices
- Filebase it works with for me is CEON 4.4.1
- The site I have it on is running ZC 1.5.1
- You do need the category slug to be generated before generating the product URIs - just navigate to the regular zencart "edit categories" page and edit then save each category
Code:
<?php // display categories to select from
$categories = mysql_query("SELECT * FROM zen_categories LEFT JOIN zen_categories_description ON zen_categories.categories_id = zen_categories_description.categories_id WHERE zen_categories.categories_status='1'");
echo "<p>Click on a category to update it's products: <br/>";
while ($showthiscat = mysql_fetch_assoc($categories)){
echo "<a href='update-ceon-uri.php?updatecategory={$showthiscat['categories_id']}'>{$showthiscat['categories_name']}</a>, \n";
}
echo "</p>\n<hr/>\n";
?>
<?php
$replacechars = array("(",")","'","\"","$","%","&"); // specify all characters to be eliminated
// update all products in category
$updateuris = mysql_query("SELECT * FROM zen_products WHERE master_categories_id='{$_GET['updatecategory']}'");
while ($thisuri = mysql_fetch_assoc($updateuris)) {
unset($catname);
$productsid = $thisuri['products_id'];
$productsname = implode(mysql_fetch_assoc(mysql_query("SELECT products_name FROM zen_products_description WHERE products_id='{$productsid}'")));
$catname = implode(mysql_fetch_assoc(mysql_query("SELECT uri FROM zen_ceon_uri_mappings WHERE main_page='index' AND associated_db_id='{$thisuri['master_categories_id']}'")));
$newuri = $catname."/".strtolower(str_replace(" ","-",$productsname));
//$newuri = "/".strtolower(str_replace(" ","-",$productsname)); // product-only on this site
$newuri = str_replace($replacechars,"",$newuri); // remove characters in the array above
$today = date('Y-m-d G:i:s'); // today
if($productsname == ''){continue;} // skip empty names
$exists = implode(mysql_fetch_assoc(mysql_query("SELECT * FROM zen_ceon_uri_mappings WHERE main_page='product_info' AND associated_db_id='$productsid'"))); // used to check if product already exists to do update vs insert
if ($exists) { // if already in zen_ceon_uri_mappings, update
mysql_query("UPDATE zen_ceon_uri_mappings SET uri='$newuri' WHERE main_page='product_info' AND associated_db_id='$productsid'");
$result = "Updated... ".mysql_error();
} else { // else, insert
mysql_query("INSERT IGNORE INTO zen_ceon_uri_mappings
(`uri`, `language_id`, `current_uri`, `main_page`, `query_string_parameters`, `associated_db_id`, `alternate_uri`, `redirection_type_code`, `date_added`) VALUES
('$newuri','1','1','product_info',NULL,'$productsid',NULL,NULL,'$today')");
$result = "Inserted... ".mysql_error();
}
echo "<p>$newuri (cat: {$thisuri['master_categories_id']}) - $result</p>\n"; // display whether updated or inserted and any problems encountered
}
?>
Bookmarks