Router not working properly for same alias with suffix active in vm 3.0.16

Started by Studio 42, May 18, 2016, 16:50:19 PM

Previous topic - Next topic

Studio 42

Hi,
category and product cannot have same alias
config :
suffix enabled
suffix set to ".htm"

Tested this alias :
index.php/en/volkswagen/volkswagen-passat
return :
  'view' => string 'productdetails' (length=14)
  'virtuemart_product_id' => string '4026' (length=4)
  'virtuemart_category_id' => string '71' (length=2)
Tested this alias
index.php/en/volkswagen/volkswagen-passat/volkswagen-passat.htm
return :
'view' => string 'productdetails' (length=14)
  'virtuemart_product_id' => string '4026' (length=4)
  'virtuemart_category_id' => string '965' (length=3)

Category view volkswagen/volkswagen-passat is set as product 4026 so you cannot use currently same alias for category and product in vm 3.0.16. with or without suffix enabled.
I dumped the var directly in the router, so nothing else router.php can modify this values.

Regards,
Patrick

VirtueMart 3.0.16,Joomla 3.5.1

Studio 42

Working solution :
change in router.php:
$product = $helper->getProductId($segments ,$helper->activeMenu->virtuemart_category_id, false);
to
$product = $helper->getProductId($segments ,$helper->activeMenu->virtuemart_category_id, true);
change
//if so then its a product load the details page
if(isset($product['virtuemart_product_id'])) {

to
//if so then its a product load the details page
if(!empty($product['virtuemart_product_id'])) {

and change
if($seo_sufix and !empty($this->seo_sufix_size) ){
$productName =  substr($productName, 0, -(int)$this->seo_sufix_size );
}

to
if($seo_sufix and !empty($this->seo_sufix_size) ){
if(substr($productName, -(int)$helper->seo_sufix_size ) !== $helper->seo_sufix) {
return array('virtuemart_product_id' =>0, 'virtuemart_category_id' => false);
}
$productName =  substr($productName, 0, -(int)$this->seo_sufix_size );
}


And no more product and category alias conflit using suffix

Milbo

Looks great
But one question, the helper is not available in getProductId, I think it is

if($seo_sufix and !empty($this->seo_sufix_size) ){
if(substr($productName, -(int)$this->seo_sufix_size ) !== $this->seo_sufix) {
return array('virtuemart_product_id' =>0, 'virtuemart_category_id' => false);
}
$productName =  substr($productName, 0, -(int)$this->seo_sufix_size );
}
Should I fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

babu65

I'm trying for change my file  router.php as you say, but I cant't find the lines to change in it.

Studio 42

@max : The problem is that the URL is tested 2 times in virtuemartParseRoute with
$helper->getProductId( $segments, $helper->activeMenu->virtuemart_category_id,true );
AND $helper->getProductId( $segments, $helper->activeMenu->virtuemart_category_id,false );
In second case, if category have same alias as product, the product is found with 3.0.16 code, because this is rechecked(for nothing) but without suffix and always find the (product)alias if you have the same.
I don't wanted to modify all, but i think it's not very clear, why this double check.

This code should do the work :
if($seo_sufix and !empty($this->seo_sufix_size) ){
if(substr($productName, -(int)$this->seo_sufix_size ) !== $this->seo_sufix) {
return array('virtuemart_product_id' =>0, 'virtuemart_category_id' => false);
}
$productName =  substr($productName, 0, -(int)$this->seo_sufix_size );
}

or better:
if($this->use_seo_suffix and !empty($this->seo_sufix_size) ){
if(substr($productName, -(int)$this->seo_sufix_size ) !== $this->seo_sufix) {
return array('virtuemart_product_id' =>0, 'virtuemart_category_id' => false);
}
$productName =  substr($productName, 0, -(int)$this->seo_sufix_size );
}

The second check is then obsolete and can be removed.
I think, the code can be simplified more then this. But this is another thing.

Milbo

Quote from: Studio 42 on May 23, 2016, 23:30:05 PM
or better:
if($this->use_seo_suffix and !empty($this->seo_sufix_size) ){
if(substr($productName, -(int)$this->seo_sufix_size ) !== $this->seo_sufix) {
return array('virtuemart_product_id' =>0, 'virtuemart_category_id' => false);
}
$productName =  substr($productName, 0, -(int)$this->seo_sufix_size );
}



Must be that way, else you get problems when the suffix is written in the textfield, but disabled.
Should I fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/