Hi Everyone,
Have used these forums a lot to help me learn Zen Cart and I have done 3 customized carts so far with great success. Since I have gotten so much help from the info here I wanted to share a tweak for SSU I figured out to help with the issue of having multiple URLs for the same product when that product is in multiple categories.
I would wait for Raine to verify if he thinks there are any implications of doing this, but so far it is working as I need it for me. Perhaps this can be added in the future as an option, ill detail my idea more below.
So basically almost all my products belong to two categories, so if you are browsing the 1st category with product A, you have one link, and if you are in the 2nd category with product A, you have another link, since links are formatted with the category name in them.
What I did was modify the product parser to pull back only the master category id when formulating the product URL. So no matter what category page I am on, the links to the product are using the path containing the master category id.
Location the following file:
/includes/classes/ssu/plugins/parsers/product.php and go to about line 121 to find this code:
PHP Code:
static function getProductPath($products_id, $cPath) {
global $db;
$categories_id = self::getID($cPath, '_');
$category_query = "select p2c.categories_id, p.master_categories_id
from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c
where p.products_id = '" . $products_id . "'
and p.products_id = p2c.products_id
and (p.master_categories_id = '$categories_id' or p2c.categories_id='$categories_id') limit 1";
$category = $db->Execute($category_query);
// fall back if needed to
if ($category->RecordCount() == 0){
$category_query = "select p.master_categories_id
from " . TABLE_PRODUCTS . " p
where p.products_id = '" . $products_id . "' limit 1";
$category = $db->Execute($category_query);
if ($category->RecordCount() > 0)
$categories_id = $category->fields['master_categories_id'];
}
$cPath = "";
now, comment out the first query section so that the code is forced to use the fallback code which pulls back the master category id only. the resulting code should look like the following:
PHP Code:
static function getProductPath($products_id, $cPath) {
global $db;
$categories_id = self::getID($cPath, '_');
/*
$category_query = "select p2c.categories_id, p.master_categories_id
from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c
where p.products_id = '" . $products_id . "'
and p.products_id = p2c.products_id
and (p.master_categories_id = '$categories_id' or p2c.categories_id='$categories_id') limit 1";
$category = $db->Execute($category_query);
*/
// fall back if needed to
//if ($category->RecordCount() == 0){
$category_query = "select p.master_categories_id
from " . TABLE_PRODUCTS . " p
where p.products_id = '" . $products_id . "' limit 1";
$category = $db->Execute($category_query);
if ($category->RecordCount() > 0)
$categories_id = $category->fields['master_categories_id'];
//}
$cPath = "";
This is the only code change necessary. Upload the file (make sure you saved the original just in case) and then go into the SEO URL Manager in Admin under Extras and clear out the cache for the products. You may need to clear out all cache but im not sure of the overall impact, maybe Raine can comment.
So going forward, I propose to Raine to add a flag in the admin for "Use Master Category Always". When this is set to true, it will force the master category to be used in the link at all times and bypass that first part of the code like I have done here. This would be the more formal approach for your own release and would be a lot easier for you to do than me, I am sure!
Again I thank you for this mod as well as the community for all the info I have gained here!
Jason
Bookmarks