Author Topic: Manufacturer name in product url  (Read 1589 times)

erhabe

  • Jr. Member
  • **
  • Posts: 58
Manufacturer name in product url
« 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?
Code: [Select]
//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
Code: [Select]
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

  • Beginner
  • *
  • Posts: 1
  • A beginner
Re: Manufacturer name in product url
« Reply #1 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);   
         }

joseugs

  • Beginner
  • *
  • Posts: 4
Re: Manufacturer name in product url
« Reply #2 on: February 21, 2018, 22:58:07 pm »
huh... i guess this wont ever make it as a setting in the official VM config

jjk

  • Global Moderator
  • Sr. Member
  • *
  • Posts: 3354
  • using Matomo instead of Google Analytics
Re: Manufacturer name in product url
« Reply #3 on: February 22, 2018, 23:18:19 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