News:

Support the VirtueMart project and become a member

Main Menu

Manufacturer name in product url

Started by erhabe, May 06, 2015, 02:27:33 AM

Previous topic - Next topic

erhabe

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.

Tomitom222

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);   
         }

joseugs

huh... i guess this wont ever make it as a setting in the official VM config

jjk

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.
Non-English Shops: Are your language files up to date?
http://virtuemart.net/community/translations