Page 2 of 3
Re: Category route problem
Posted: 05 Apr 2020, 15:24
by Jan
I have done some quick tests and seems like this can solve the situation with question view:
Code: Select all
if($advanced == 1){
$segmentId = '';
$segmentCatid = '';
for ($i = 0; $i < $total; $i++){
if(isset($segments[$i]) && $i == 0 && in_array($segments[$i], $viewsNotOwnId)) {
$vars['view'] = $segments[$i];
continue;
}
if(empty($segmentCatid)){
$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);
$segmentCatid = $db->loadResult();
if(!empty($segmentCatid)) {
$segments[$i] = $segmentCatid.'-'.$segments[$i];
continue;
}
}
if (empty($segmentId)){
//$segmentProductId = '';
$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);
$segmentId = $db->loadResult();
if(!empty($segmentId)) {
$segments[$i] = $segmentId.'-'.$segments[$i];
}
}
}
$advanced = 0;
}
But there are still problems when using more menu links to eshop (e.g. to categories view and to category view)
This is even problematic:
Code: Select all
$segments[$i] = preg_replace('/-/', ':', $segments[$i], 1);
because it changes the aliases. E.g. product name is "Product 2", product alias is "product-2" and this alias is changed to "product:2" which is not correct.
EDIT: seems like the last solution I have added (05/04/2020 15:57), solves the issue with more menu links
If there will be no other issues, I can add it to 3.5.0 stable as expermintal setting:
Jan
Re: Category route problem
Posted: 05 Apr 2020, 16:22
by Jan
Re: Category route problem
Posted: 05 Apr 2020, 21:20
by NickS
Thank you for your attention.
I really did not check the work of everything, but only products and categories, calculation and personal account.
I am very happy that your extension is getting better and better!
Re: Category route problem
Posted: 06 Apr 2020, 13:29
by NickS
I tested the new router-it doesn't work correctly!
This way we will always get the ID of the FIRST category in the url. If we have several categories in the url, we will never go to them.
Code: Select all
if(empty($segmentCatid)){
$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);
$segmentCatid = $db->loadResult();
if(!empty($segmentCatid)) {
$segments[$i] = $segmentCatid.'-'.$segments[$i];
continue;
}
}
mainpage/skoda/ - category with ID=1 (alias "skoda"), OK
mainpage/skoda/suv/ - We have found the ID=1 by alias "skoda" and are no longer looking for the next one (alias "suv")
mainpage/skoda/suv/premium/ - We have found the ID=1 and so on
so for me works the next code (from line 405 to line 447):
Code: Select all
if($advanced == 1){
$segmentId = '';
$segmentCatid = '';
for ($i = 0; $i < $total; $i++){
if(isset($segments[$i]) && $i == 0 && in_array($segments[$i], $viewsNotOwnId)) {
$vars['view'] = $segments[$i];
continue;
}
$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);
$segmentCatid = $db->loadResult();
//we found or did not find the category ID, we will check it later
if (empty($segmentId)){
//$segmentProductId = '';
$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);
$segmentId = $db->loadResult();
if(!empty($segmentId)) {
$segments[$i] = $segmentId.'-'.$segments[$i];
}
}
}
if(!empty($segmentCatid)) {
//we found one or more category IDS, and add the last ID to the beginning of the line (to the first segment)
$segments[0] = $segmentCatid.'-'.$segments[0];
}
//disable advanced mode and then the router works as before
$advanced = 0;
}
Re: Category route problem
Posted: 06 Apr 2020, 13:48
by NickS
Some corrections:
Code: Select all
if($advanced == 1){
$segmentId = '';
$segmentCatid = '';
for ($i = 0; $i < $total; $i++){
if(isset($segments[$i]) && $i == 0 && in_array($segments[$i], $viewsNotOwnId)) {
$vars['view'] = $segments[$i];
continue;
}
$segmentCatidTemp = '';
$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);
$segmentCatidTemp = $db->loadResult();
if(!empty($segmentCatidTemp)) {
$segmentCatid = $segmentCatidTemp;
continue;
}
//we found or did not find the category ID, we will check it later
if (empty($segmentId)){
//$segmentProductId = '';
$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);
$segmentId = $db->loadResult();
if(!empty($segmentId)) {
$segments[$i] = $segmentId.'-'.$segments[$i];
}
}
}
if(!empty($segmentCatid)) {
//we found one or more category IDS, and add the last ID to the beginning of the line (to the first segment)
$segments[0] = $segmentCatid.'-'.$segments[0];
}
//disable advanced mode and then the router works as before
$advanced = 0;
}
Re: Category route problem
Posted: 06 Apr 2020, 23:30
by Jan
The problem of the last correction is, it adds ID for quick view, but quick view should not be handled as category:
Jan
Re: Category route problem
Posted: 06 Apr 2020, 23:46
by Jan
Try to test this code:
Code: Select all
if($advanced == 1){
$segmentId = '';
$segmentCatid = '';
// As default first part is category but it can even be view
// If it is a view, shift they key to next part
$segmentCatidKey = 0;
for ($i = 0; $i < $total; $i++){
if(isset($segments[$i]) && $i == 0 && in_array($segments[$i], $viewsNotOwnId)) {
$segmentCatidKey = 1;// First part is a view (e.g. Quick View), shift the key to next part
$vars['view'] = $segments[$i];
continue;
}
$segmentCatidTemp = '';
$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);
$segmentCatidTemp = $db->loadResult();
if(!empty($segmentCatidTemp)) {
$segmentCatid = $segmentCatidTemp;
continue;
}
//we found or did not find the category ID, we will check it later
if (empty($segmentId)){
//$segmentProductId = '';
$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);
$segmentId = $db->loadResult();
if(!empty($segmentId)) {
$segments[$i] = $segmentId.'-'.$segments[$i];
}
}
}
if(!empty($segmentCatid)) {
//we found one or more category IDS, and add the last ID to the beginning of the line (to the first segment)
$segments[$segmentCatidKey] = $segmentCatid.'-'.$segments[$segmentCatidKey];
}
//disable advanced mode and then the router works as before
$advanced = 0;
}
I have added only the function to schift the key of $segmentCatid variable in case, it is not a category but view. It should not affect the code, you have add as last.
It looks like it can work even with subcategories:
0 ... view
1 ... 2 id of subcategory, "category" is alias of parent category
2 ... alias of subcategory (id is included in parent)
4 ... 3 id of product including its alias ... so the link is OK
But next problem is returning status:
phoca-cart/category/subcategory/not-existing-product
Category exists, subcategory exists but "not-existing-product" does not exists:
- it should return 404 for not found category
- or return 404 for not found product
- but it returns 200 with displayed subcategory
The same with not existing subcategory:
phoca-cart/category/not-existing-subcategory
Jan
Re: Category route problem
Posted: 07 Apr 2020, 00:52
by NickS
Thanks! The new router works OK!
But next problem is returning status:
phoca-cart/category/subcategory/not-existing-product
Category exists, subcategory exists but "not-existing-product" does not exists:
- it should return 404 for not found category
- or return 404 for not found product
- but it returns 200 with displayed subcategory
I don't see any problem with this, the router works similarly on a stable version of Phoca Cart:
https://www.phoca.cz/phocacartdemo/3-audi/10-audi-a1
https://www.phoca.cz/phocacartdemo/3-audi/audi-a1 - returns 200 with displayed subcategory
Re: Category route problem
Posted: 08 Apr 2020, 10:18
by NickS
Hi! Do you plan to add a new router to RC version?
Re: Category route problem
Posted: 12 Apr 2020, 18:09
by Jan
Hi, yes, it is there. I will be released in 3.5.0 Stable version. It will be possible to enable/disable it per expert options, so it can be disabled, if there will be some issues and it can be improved in some of the next versions.
Jan