Hi,
I'm creating a category structure and I'm having problems with the correct url.
I create category 1 (id = 1), create category 2 (id = 2). I create product 1 (id = 1).
Now I'm going through the category tree:
mysite.com/1-category-one/ - it's OK!
mysite.com/2-category-one/category-two/ - it's NOT OK! Why did the 'category-one' id change?
mysite.com/2-category-one/category-two/1-product-one/ - it's NOT OK!
Should the Link (path) to category 1 change?
If you go to the address mysite.com/2-categoryone/ - I get a 404 error!
Category route problem
- Jan
- Phoca Hero
- Posts: 48403
- Joined: 10 Nov 2007, 18:23
- Location: Czech Republic
- Contact:
Re: Category route problem
Hi, maybe this are more questions on Joomla! core developers and Joomla! routing system.
mysite.com/ID-of-current-category-name-of-parent-category/name-of-category/name-of-subcategory-which-is-current-category
So if you want to see category two, the ID is just from category tow
So you are asking product one in category two. In case you will ask product one in category one, you will have this link:
mysite.com/1-category-two/1-product-one/
So, first I am not the developer of this system, so maybe this question should be not answered by be but if you want that your system really understand all requests, you just need such system.
This system can understand:
- which ID is category ID
- which ID is product ID
and
- build tree of categories
There are even more issues, which must be solved when requesting page. E.g. what happens when the alias of subcategory includes ID, like:
mysite.com/1-category-two/3subcategory
In such case the system ist not able to understand if you ask for subcategory or product, because it tries to parste two numbers in url and return category as first and product as second.
Why the system is dependent on numbers? Because integer (number) can be very quickly processed. In Joomla! 4, there will be new router where you can skip using numbers but of course this will take more resources and even such router can have many issues.
If the urls don't fit your needs, you can disable the SEF or write own specific rules in components\com_phocacart\router.php but be always aware, there are thousands of possible combinations which can somehow break the requests, so it is necessary to work with caution)
mysite.com/1-category-one/ - it's OK!
It is not ID of category one but of category two - in Joomla! but even generally you can have only on ID for category in URL so the system knows which category you want to see. In Joomla! the tree is built this way:mysite.com/2-category-one/category-two/ - it's NOT OK! Why did the 'category-one' id change?
mysite.com/ID-of-current-category-name-of-parent-category/name-of-category/name-of-subcategory-which-is-current-category
So if you want to see category two, the ID is just from category tow
the same like above - the ID is of the current category (category two), the url gets all categories in tree and the last ID is for the product including its ID.mysite.com/2-category-one/category-two/1-product-one/ - it's NOT OK!
So you are asking product one in category two. In case you will ask product one in category one, you will have this link:
mysite.com/1-category-two/1-product-one/
If there is one number in url, it tries to find the category, if none of the category meets the url, it tries to find the product. If the alias does not exists, it can be ignored and only ID can be used to recognize the request. Unfortunately, we can have two IDs (category, products), so only one of those can be used in this situation - it is the product, so if you get 404, this can mean that the product ID 2 does not exist.If you go to the address mysite.com/2-categoryone/ - I get a 404 error!
So, first I am not the developer of this system, so maybe this question should be not answered by be but if you want that your system really understand all requests, you just need such system.
This system can understand:
- which ID is category ID
- which ID is product ID
and
- build tree of categories
There are even more issues, which must be solved when requesting page. E.g. what happens when the alias of subcategory includes ID, like:
mysite.com/1-category-two/3subcategory
In such case the system ist not able to understand if you ask for subcategory or product, because it tries to parste two numbers in url and return category as first and product as second.
Why the system is dependent on numbers? Because integer (number) can be very quickly processed. In Joomla! 4, there will be new router where you can skip using numbers but of course this will take more resources and even such router can have many issues.
If the urls don't fit your needs, you can disable the SEF or write own specific rules in components\com_phocacart\router.php but be always aware, there are thousands of possible combinations which can somehow break the requests, so it is necessary to work with caution)
If you find Phoca extensions useful, please support the project
-
- Phoca Member
- Posts: 21
- Joined: 25 Mar 2020, 23:54
Re: Category route problem
Thank you very much for your response!
I have already forgotten how Joomla includes the ID in the link - for several years I have been using the built-in Joomla articles "sef_advanced" mode with removing the ID from the url.
If I were a Google or Yandex bot and saw the link "mysite.com/2-category-one/category-two/1-product-one/", I'd go to the link "mysite.com/2-category-one/" and got a 404 error.
If I have thousands of child categories on my site, it is impossible to set a redirect for each such case. However, many search engines display the site structure in the search results. But the structure must be clearly defined
I found the "sef_advanced_link" string in the phoca cart router and replaced the value with "1" (in the build and parse functions).
Now I get normal structure and links like :
mysite.com/category-one/
mysite.com/category-one/category-two/
mysite.com/category-one/category-two/product-one/
And added some modifications to parse function (just a draft code):
if($advanced == 1){
$segmentid = '';
$segmentcatid = '';
for ($i = 0; $i < $total; $i++){
$query = $db->getQuery(true)
->select($db->quoteName(array('id')))
->from($db->quoteName('#__phocacart_categories'))
->where($db->quoteName('alias') . ' = ' . $db->quote($segments[$i]));
$db->setQuery($query);
$segmentid = $db->loadResult();
if(empty($segmentid)){
$segmentprodid = '';
$query = $db->getQuery(true)
->select($db->quoteName(array('id')))
->from($db->quoteName('#__phocacart_products'))
->where($db->quoteName('alias') . ' = ' . $db->quote($segments[$i]));
$db->setQuery($query);
$segmentprodid = $db->loadResult();
if(!empty($segmentprodid)) $segments[$i] = $segmentprodid.'-'.$segments[$i];
} else $segmentcatid = $segmentid;
}
if(!empty($segmentcatid)) $segments[0] = $segmentcatid.'-'.$segments[0];
$advanced = 0;
}
Everything works correctly, and I haven't noticed any significant speed degradation yet.
I would be very grateful if you noticed any errors in my offer!
I have already forgotten how Joomla includes the ID in the link - for several years I have been using the built-in Joomla articles "sef_advanced" mode with removing the ID from the url.
If I were a Google or Yandex bot and saw the link "mysite.com/2-category-one/category-two/1-product-one/", I'd go to the link "mysite.com/2-category-one/" and got a 404 error.
If I have thousands of child categories on my site, it is impossible to set a redirect for each such case. However, many search engines display the site structure in the search results. But the structure must be clearly defined
I found the "sef_advanced_link" string in the phoca cart router and replaced the value with "1" (in the build and parse functions).
Now I get normal structure and links like :
mysite.com/category-one/
mysite.com/category-one/category-two/
mysite.com/category-one/category-two/product-one/
And added some modifications to parse function (just a draft code):
if($advanced == 1){
$segmentid = '';
$segmentcatid = '';
for ($i = 0; $i < $total; $i++){
$query = $db->getQuery(true)
->select($db->quoteName(array('id')))
->from($db->quoteName('#__phocacart_categories'))
->where($db->quoteName('alias') . ' = ' . $db->quote($segments[$i]));
$db->setQuery($query);
$segmentid = $db->loadResult();
if(empty($segmentid)){
$segmentprodid = '';
$query = $db->getQuery(true)
->select($db->quoteName(array('id')))
->from($db->quoteName('#__phocacart_products'))
->where($db->quoteName('alias') . ' = ' . $db->quote($segments[$i]));
$db->setQuery($query);
$segmentprodid = $db->loadResult();
if(!empty($segmentprodid)) $segments[$i] = $segmentprodid.'-'.$segments[$i];
} else $segmentcatid = $segmentid;
}
if(!empty($segmentcatid)) $segments[0] = $segmentcatid.'-'.$segments[0];
$advanced = 0;
}
Everything works correctly, and I haven't noticed any significant speed degradation yet.
I would be very grateful if you noticed any errors in my offer!
- Jan
- Phoca Hero
- Posts: 48403
- Joined: 10 Nov 2007, 18:23
- Location: Czech Republic
- Contact:
Re: Category route problem
Hi, great, thank you for the code, are you able to paste here the link to whole router file, so I can see where the changes exactly occur. I can add it then to RC version as experimental feature, so users can test it more.
Thank you, Jan
Thank you, Jan
If you find Phoca extensions useful, please support the project
- Jan
- Phoca Hero
- Posts: 48403
- Joined: 10 Nov 2007, 18:23
- Location: Czech Republic
- Contact:
Re: Category route problem
Hmm, testing now:
index.php/phoca-cart/category
index.php/phoca-cart/category/product
categories view instead of product view
There are conflict when between aliases like "category" and "category-2", etc.
Jan
index.php/phoca-cart/category
index.php/phoca-cart/category/product
categories view instead of product view
There are conflict when between aliases like "category" and "category-2", etc.
Did you test it with e.g. 5000 products and 300 categories?significant speed degradation yet
Jan
If you find Phoca extensions useful, please support the project
-
- Phoca Member
- Posts: 21
- Joined: 25 Mar 2020, 23:54
Re: Category route problem
I don't think I understand your question?
As for the speed of work - there will certainly be an additional load, but this function can be optional (like disabling some SQL queries in phoca cart 3.5)
1. Joomla SEF and sef_rewrite should be enabled (no index.php in url)
2. This feature could be optional in phoca cart settings, as done in Joomla articles
3. Tested catergories with aliases: phoca, phoca-1, phoca-2, phoca1, phoca2 in "child-parent" combinations:
mysite.com/phocamainpage/phoca/phoca-1/phoca-2/phoca1/phoca2/product1
Works OK!
As for the speed of work - there will certainly be an additional load, but this function can be optional (like disabling some SQL queries in phoca cart 3.5)
1. Joomla SEF and sef_rewrite should be enabled (no index.php in url)
2. This feature could be optional in phoca cart settings, as done in Joomla articles
3. Tested catergories with aliases: phoca, phoca-1, phoca-2, phoca1, phoca2 in "child-parent" combinations:
mysite.com/phocamainpage/phoca/phoca-1/phoca-2/phoca1/phoca2/product1
Works OK!
-
- Phoca Member
- Posts: 21
- Joined: 25 Mar 2020, 23:54
Re: Category route problem
How do I add the router code here?
Your message contains 17492 characters.
The maximum number of allowed characters is 5600.
-
- Phoca Member
- Posts: 21
- Joined: 25 Mar 2020, 23:54
- Jan
- Phoca Hero
- Posts: 48403
- Joined: 10 Nov 2007, 18:23
- Location: Czech Republic
- Contact:
Re: Category route problem
Great, thank you very much, I will take a look at it.
Jan
Jan
If you find Phoca extensions useful, please support the project
- Jan
- Phoca Hero
- Posts: 48403
- Joined: 10 Nov 2007, 18:23
- Location: Czech Republic
- Contact:
Re: Category route problem
Hi, testing now, seems like it works for the basic tree, but when e.g. dispaying the Ask a question view in product view:
the popup displays item (product) view instead of ask a question view
The url to submit view is normaly in this form:
index.php/phoca-cart/question/1-category/1-product?tmpl=component
question = view
category = 1-category
product = 1-product
When advaced is enabled:
index.php/phoca-cart/question/category/product?tmpl=component
It just does not recognize view/catid/id
Jan
the popup displays item (product) view instead of ask a question view
The url to submit view is normaly in this form:
index.php/phoca-cart/question/1-category/1-product?tmpl=component
question = view
category = 1-category
product = 1-product
When advaced is enabled:
index.php/phoca-cart/question/category/product?tmpl=component
It just does not recognize view/catid/id
Jan
If you find Phoca extensions useful, please support the project