DrByte:
@bobthemolder,
I think the following does the same thing, but uses the Zen Cart $db stuff to do the queries, making your stuff compatible with newer ZC versions.
I don't have a CEON URI site to test it on, but I think I've converted it correctly.
// display categories to select from
$categories = $db->Execute("SELECT * FROM " . TABLE_CATEGORIES . " c LEFT JOIN " . TABLE_CATEGORIES_DESCRIPTION . " cd ON c.categories_id = cd.categories_id WHERE c.categories_status='1'");
echo "<p>Click on a category to update its products: <br/>";
while (!$categories->EOF) {
echo "<a href='update-ceon-uri.php?updatecategory={$categories->fields['categories_id']}'>{$categories->fields['categories_name']}</a>, \n";
$categories->MoveNext();
}
echo "</p>\n<hr/>\n";
$replacechars = array("(",")","'",""","$","%","&"); // specify all characters to be eliminated
// update all products in category
$_GET['updatecategory'] = (int)$_GET['updatecategory'];
$updateuris = $db->Execute("SELECT * FROM " . TABLE_PRODUCTS . " WHERE master_categories_id='{$_GET['updatecategory']}'");
while (!$updateuris->EOF)) {
$thisuri = $updateuris->fields;
unset($catname);
$productsid = $thisuri['products_id'];
$productsname = zen_get_products_name($productsid);
if($productsname == '') continue; // skip empty names
$result = $db->Execute("SELECT uri FROM " . TABLE_CEON_URI_MAPPINGS . " WHERE main_page='index' AND associated_db_id='{$thisuri['master_categories_id']}'");
$catname = $result->fields['uri'];
$newuri = $catname."/".strtolower(str_replace(" ","-",$productsname));
//$newuri = "/".strtolower(str_replace(" ","-",$productsname)); // product-only on this site
// remove characters in the array above
$newuri = str_replace($replacechars,"",$newuri);
$today = date('Y-m-d G:i:s'); // today
// check if product already exists to do update vs insert
$result = $db->Execute("SELECT * FROM " . TABLE_CEON_URI_MAPPINGS . " WHERE main_page='product_info' AND associated_db_id='$productsid'");
$exists = $result->RecordCount();
if ($exists) { // if already in TABLE_CEON_URI_MAPPINGS, update
$db->Execute("UPDATE " . TABLE_CEON_URI_MAPPINGS . " SET uri='$newuri' WHERE main_page='product_info' AND associated_db_id='$productsid'");
$status = "Updated. ";
} else { // else, insert
$db->Execute("INSERT IGNORE INTO " . TABLE_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')");
$status = "Inserted. ";
}
// display whether updated or inserted and any problems encountered
echo "<p>$newuri (cat: {$thisuri['master_categories_id']}) - $status</p>\n";
$updateuris->MoveNext();
}
Hi,
I am not sure I understood how to use the code above, I mean how to make in work.
bobthemolder said to copy it in a amdin page but I did it in the categories.php page and all what I get is a blank page (zen cart v1.5.5)
Can you please explain it in more details?
Thanks
enzo