i found an error back in 2005 (
http://forums.phpshop.org/viewtopic.php?id=6049
) that i finally needed to fix, so here it is. the problem is that if
a category name is changed, the url field is updated, but all the
category_url's that depend on it are not updated. this additional
function and the updated "update" function go in the
ps_product_category.inc file.
[code]
/
**************************************************************************
** name: update_subcat_urls()
** created by: jnewman67
** description: updates the category_urls after a category is
updated/relocated
** parameters: parent category_id and parent category_url
** returns:
***************************************************************************/
function update_subcat_urls($cat_id, $cat_url) {
$db = new ps_DB;
$dbc = new ps_DB;
$q = "SELECT * FROM category, category_xref ";
$q .= "WHERE category_xref.category_parent_id='$cat_id' AND ";
$q .= "category_xref.category_child_id=category.category_id ";
$db->query($q);
while ($db->next_record()) {
$new_url = $cat_url . "_" . str_replace(" ", "", strtolower($db->f
("category_name")));
$q = "UPDATE category ";
$q .= "SET category_url = '" . $new_url . "' ";
$q .= "WHERE category_id = '" . $db->f("category_id") . "' ";
$dbc->query($q);
$this->update_subcat_urls($db->f("category_id"), $new_url);
}
return True;
}
/
**************************************************************************
** name: update()
** created by: pablo
** description: updates category information
** parameters:
** returns:
***************************************************************************/
function update(&$d) {
$db = new ps_DB;
global $ps_vendor_id;
$timestamp = time();
if ($this->validate_update($d)) {
// check to see if updating the subcategories is necessary
$update_subs = False;
$q = "SELECT * FROM category ";
$q .= "WHERE category.category_id='" . $d["category_id"] . "' ";
$db->query($q);
if ($db->next_record()) {
if ($db->f("cateogry_url") <> $d["category_url"]) $update_subs =
True;
}
$q = "UPDATE category SET ";
$q .= "category_id='" . $d["category_id"];
$q .= "',category_name='" . $d["category_name"];
if ($d["category_publish"] != "Y") {
$d["category_publish"] = "N";
}
$q .= "',category_url='" . $d["category_url"];
$q .= "',category_publish='" . $d["category_publish"];
$q .= "',category_description='" . $d["category_description"];
$q .= "',category_flypage='" . $d["category_flypage"];
$q .= "', mdate='$timestamp";
$q .= "' WHERE category_id='" . $d["category_id"] . "' ";
$q .= "AND vendor_id='$ps_vendor_id' ";
$db->query($q);
$db->next_record();
/*
** Update category x-reference table with parent-child
relationship
*/
$q = "UPDATE category_xref SET ";
$q .= "category_parent_id='" . $d["category_parent_id"];
$q .= "' WHERE category_child_id='" . $d["category_id"] . "'";
$db->query($q);
$db->next_record();
// Update subcategories if necessary
if ($update_subs) $this->update_subcat_urls($d["category_id"], $d
["category_url"]);
return True;
}
else {
return False;
}
}
[/code]