VirtueMart Forum

VirtueMart 2 + 3 + 4 => Security (https) / Performance / SEO, SEF, URLs => Topic started by: erhabe on May 06, 2015, 02:27:33 AM

Title: Manufacturer name in product url
Post by: erhabe on May 06, 2015, 02:27:33 AM
Hello

How can i modify this code to make the manufacturer name beeing included in url right after the category name on product page?
//Shop product details view
case 'productdetails';

$virtuemart_product_id = false;
if (isset($jmenu['virtuemart_product_id'][ $query['virtuemart_product_id'] ] ) ) {
$query['Itemid'] = $jmenu['virtuemart_product_id'][$query['virtuemart_product_id']];
unset($query['virtuemart_product_id']);
unset($query['virtuemart_category_id']);
} else {
if(isset($query['virtuemart_product_id'])) {
if ($helper->use_id) $segments[] = $query['virtuemart_product_id'];
$virtuemart_product_id = $query['virtuemart_product_id'];
unset($query['virtuemart_product_id']);
}
if(empty( $query['virtuemart_category_id'])){
$query['virtuemart_category_id'] = $helper->getParentProductcategory($virtuemart_product_id);
}
if(!empty( $query['virtuemart_category_id'])){
$categoryRoute = $helper->getCategoryRoute($query['virtuemart_category_id']);
if ($categoryRoute->route) $segments[] = $categoryRoute->route;
if ($categoryRoute->itemId) $query['Itemid'] = $categoryRoute->itemId;
else $query['Itemid'] = $jmenu['virtuemart'];
} else {
$query['Itemid'] = $jmenu['virtuemart']?$jmenu['virtuemart']:@$jmenu['virtuemart_category_id'][0];
}
unset($query['virtuemart_category_id']);

if($virtuemart_product_id)
$segments[] = $helper->getProductName($virtuemart_product_id);
}
break;



I try different methods to insert this code
case 'manufacturer';

if(isset($query['virtuemart_manufacturer_id'])) {
if (isset($jmenu['virtuemart_manufacturer_id'][ $query['virtuemart_manufacturer_id'] ] ) ) {
$query['Itemid'] = $jmenu['virtuemart_manufacturer_id'][$query['virtuemart_manufacturer_id']];
} else {
$segments[] = $helper->lang('manufacturers').'/'.$helper->getManufacturerName($query['virtuemart_manufacturer_id']) ;
if ( isset($jmenu['manufacturer']) ) $query['Itemid'] = $jmenu['manufacturer'];
else $query['Itemid'] = $jmenu['virtuemart'];
}
unset($query['virtuemart_manufacturer_id']);
} else {
if ( isset($jmenu['manufacturer']) ) $query['Itemid'] = $jmenu['manufacturer'];
else $query['Itemid'] = $jmenu['virtuemart'];
}
break;

in many different ways but i didnt succeded and the category name dissapeard.
Title: Re: Manufacturer name in product url
Post by: Tomitom222 on May 13, 2017, 21:03:01 PM
What you can do is
Create a function in components/com_virtuemart/router.php

public function getMyManufacturerId($virtuemart_product_id ){
$db = JFactory::getDBO();
$query = $db->getQuery(true);
$query->select('virtuemart_manufacturer_id');
$query->from('#__virtuemart_product_manufacturers');
$query->where('virtuemart_product_id ='. $virtuemart_product_id.'');   
$db->setQuery($query);
$o= $db->loadResult();
return $o;
}

Now in Case Productdetails around the line 210 of that same router.php file, modify last IF statement to. This will call your new helper function, after which default helper function for Virtuemart Manufacturer SLUG value is delivered. Pay attention this solution may work with 1 manufacturer. In case you assign more manufacturers per product, you may need to decide which value from the aforementioned function to take i.e. return $o[0] or other.

if($virtuemart_product_id){
               $segments[] = $helper->getManufacturerName($helper->getMyManufacturerId($virtuemart_product_id)) ."/". $helper->getProductName($virtuemart_product_id);   
         }
Title: Re: Manufacturer name in product url
Post by: joseugs on February 21, 2018, 22:58:07 PM
huh... i guess this wont ever make it as a setting in the official VM config
Title: Re: Manufacturer name in product url
Post by: jjk on February 22, 2018, 23:18:19 PM
Quote from: joseugs on February 21, 2018, 22:58:07 PM
huh... i guess this wont ever make it as a setting in the official VM config
The most simple method is to add the manufacturer name to the 'product-alias' field when you add a new product.