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?
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.
Pinochico the world not uses the same configurations as you. Please respond with less arrogance if you really want to respond. Thank you
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.
I have added and found the solution myself!
@huubs,
It would be nice if You would share how You did this with others...
Jörgen @ Kreativ Fotografi
are you using multi-variant?
see image attached
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.