VirtueMart Forum

VirtueMart 2 + 3 + 4 => General Questions => Topic started by: Kuubs on October 20, 2020, 13:16:00 PM

Title: Canonical url to parent product for child products
Post by: Kuubs 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?
Title: Re: Canonical url to parent product for child products
Post by: pinochico 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.
Title: Re: Canonical url to parent product for child products
Post by: ermes 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
Title: Re: Canonical url to parent product for child products
Post by: pinochico 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.



Title: Re: Canonical url to parent product for child products
Post by: Kuubs on October 24, 2020, 10:53:38 AM
I have added and found the solution myself!
Title: Re: Canonical url to parent product for child products
Post by: Jörgen 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
Title: Re: Canonical url to parent product for child products
Post by: PRO on October 26, 2020, 18:43:40 PM
are you using multi-variant?


see image attached
Title: Re: Canonical url to parent product for child products
Post by: Kuubs on October 27, 2020, 16:42:59 PM
Quote from: PRO on October 26, 2020, 18:43:40 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.

$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.