Author Topic: Canonical url to parent product for child products  (Read 605 times)

Huubs

  • Jr. Member
  • **
  • Posts: 285
Canonical url to parent product for child products
« on: October 20, 2020, 13:16:00 pm »
Hello,

I try to change the canonical url of the child products to the parent product in my Virtuemart. At the moment the canonical url in the child points to itself, but I want it to point to the parent. How can I achieve this?

pinochico

  • 3rd party VirtueMart Developer
  • Full Member
  • *
  • Posts: 901
    • MiniJoomla
  • Skype Name: support-easysoftware
  • VirtueMart Version: 3
Re: Canonical url to parent product for child products
« Reply #1 on: October 20, 2020, 15:37:49 pm »
I don't show child products in category view, then I don't see URL to child products, then I don't have to use this solution - only setup canonical link into parent.
www.minijoomla.org  - new portal for Joomla!, Virtuemart and other extensions
XML Easy Feeder - feeds from products, orders and database table
Virtuemart Email Manager - customs email templates

ermes

  • Jr. Member
  • **
  • Posts: 92
Re: Canonical url to parent product for child products
« Reply #2 on: October 20, 2020, 17:50:38 pm »
Pinochico the world not uses the same configurations as you. Please respond with less arrogance if you really want to respond. Thank you

pinochico

  • 3rd party VirtueMart Developer
  • Full Member
  • *
  • Posts: 901
    • MiniJoomla
  • Skype Name: support-easysoftware
  • VirtueMart Version: 3
Re: Canonical url to parent product for child products
« Reply #3 on: October 20, 2020, 18:48:30 pm »
To Ermes:

Arrogance?
Oh man, I said, only how to use self, please don't look for anything that isn't there :)

Maybe You may ask what reason I have for this solution, but not put in my mouth what I did not say.
Or you can easily thank for an interesting idea, which you definitely do not want to use.

Or you can write what you wrote.



www.minijoomla.org  - new portal for Joomla!, Virtuemart and other extensions
XML Easy Feeder - feeds from products, orders and database table
Virtuemart Email Manager - customs email templates

Huubs

  • Jr. Member
  • **
  • Posts: 285
Re: Canonical url to parent product for child products
« Reply #4 on: October 24, 2020, 10:53:38 am »
I have added and found the solution myself!

Jörgen

  • Global Moderator
  • Sr. Member
  • *
  • Posts: 3225
    • Kreativ Fotografi
  • VirtueMart Version: 3.4.x
Re: Canonical url to parent product for child products
« Reply #5 on: October 24, 2020, 12:27:08 pm »
@huubs,

It would be nice if You would share how You did this with others...

Jörgen @ Kreativ Fotografi
Joomla 3.9.18
Virtuemart 3.4.x
Olympiantheme Hera (customized)
This reflects current status when viewing old post.

PRO

  • Global Moderator
  • Super Hero
  • *
  • Posts: 10423
  • VirtueMart Version: 3+
Re: Canonical url to parent product for child products
« Reply #6 on: October 26, 2020, 18:43:40 pm »
are you using multi-variant?


see image attached
J3.9+ VM 3.4.2
Slowest Page Speed Score (88) (Category)
Fastest Page Speed Score (94-96) (productdetails)

Huubs

  • Jr. Member
  • **
  • Posts: 285
Re: Canonical url to parent product for child products
« Reply #7 on: October 27, 2020, 16:42:59 pm »
are you using multi-variant?


see image attached
No for some reason I don't get that working as intended. I use the generic child variant.

Code: [Select]
$productModel = VmModel::getModel('Product');
//Accessoires
$parentProduct = $productModel->getProduct($this->product->product_parent_id);

$document = JFactory::getDocument();


foreach($document->_links as $key=> $value)
{
    if(is_array($value))
    {
        if(array_key_exists('relation', $value))
        {
            if($value['relation'] == 'canonical')
            {                       
       

                $canonicalUrl = JURI::root() . JRoute::_($parentProduct->link);

                $document->_links[$canonicalUrl] = $value;
                unset($document->_links[$key]);
                break;                     
            }
        }
    }
}

This was the code i used.