News:

Looking for documentation? Take a look on our wiki

Main Menu

How to remove categories on product link

Started by ornicom, July 01, 2016, 21:39:48 PM

Previous topic - Next topic

ornicom

Hello,

I use Virtuemart 3.0.16 and sh404sef 4.7.3.3292

I would like to remove the categories when a product is showed

In normal mode, the link to a category is 'domain/products/category/sub-category.html'
the link for a product is 'domain.com/products/category/sub-category/productname.html'

I not need to change the link to category but I would like to change the link to the product as 'domain/productname.html'
this change is very important to not have duplicate content when a product is set on two or more categories !


I have already remove some lines on the file '/components/com_virtuemart/router.php'

                case 'productdetails';

                        $virtuemart_product_id = false;
                        if (isset($jmenu['virtuemart_product_id']) and 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']);
                                unset($query['virtuemart_manufacturer_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($helper->full){
                                        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];
                                        }
                                } else {
                                        //Itemid is needed even if seo_full = 0
                                        $query['Itemid'] = $jmenu['virtuemart']?$jmenu['virtuemart']:@$jmenu['virtuemart_category_id'][0];
                                }
                                unset($query['limitstart']);
                                unset($query['limit']);
                                unset($query['virtuemart_category_id']);
                                unset($query['virtuemart_manufacturer_id']);

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

like that

                case 'productdetails';

                        $virtuemart_product_id = false;
                        if (isset($jmenu['virtuemart_product_id']) and 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']);
                                unset($query['virtuemart_manufacturer_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']);
                                }

                                unset($query['limitstart']);
                                unset($query['limit']);
                                unset($query['virtuemart_category_id']);
                                unset($query['virtuemart_manufacturer_id']);

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


the change seem to work but when I use xmap to make the sitemap (html and xml)
each product have 'products' in his link as 'domain/products/productname.html'
the two links 'domain/productname.html' and 'domain/products/productname.html' work without error 404

I have removed too much line or not enough ?

Somebody can help me ?

Ornicom.com


GJC Web Design

uncheck "Use full category tree for product links"  in VM config-> SEO tab?
GJC Web Design
VirtueMart and Joomla Developers - php developers https://www.gjcwebdesign.com
VM4 AusPost Shipping Plugin - e-go Shipping Plugin - VM4 Postcode Shipping Plugin - Radius Shipping Plugin - VM4 NZ Post Shipping Plugin - AusPost Estimator
Samport Payment Plugin - EcomMerchant Payment Plugin - ccBill payment Plugin
VM2 Product Lock Extension - VM2 Preconfig Adresses Extension - TaxCloud USA Taxes Plugin - Virtuemart  Product Review Component
https://extensions.joomla.org/profile/profile/details/67210
Contact for any VirtueMart or Joomla development & customisation

ornicom

Thank you for your reply !

Yes, it's more easy when the function is included in the configuration (not like before)
I will not need to modify the router.php after each update...

Many thanks

Now this problem is resolved but the product link is like 'domain/products/productname.html'
Xmap will work correctly with the same link but all links are referred to Google without the '/products/'
As I have about 1000 products in two languages, do you know a solution to make an automatic 301 redirection and not loose Google ranking ?

Ornicom.com