Example #1
0
 /**
  * Adds canonical product URLs to the document
  * @param   IsotopeProduct
  */
 protected function addCanonicalProductUrls(IsotopeProduct $objProduct)
 {
     global $objPage;
     $arrPageIds = \Database::getInstance()->getChildRecords($objPage->rootId, \PageModel::getTable());
     $arrPageIds[] = $objPage->rootId;
     // Find the categories in the current root
     $arrCategories = array_intersect($objProduct->getCategories(), $arrPageIds);
     foreach ($arrCategories as $intPage) {
         // Do not use the index page as canonical link
         if ($objPage->alias == 'index' && count($arrCategories) > 1) {
             continue;
         }
         // Current page is the primary one, do not generate canonical link
         if ($intPage == $objPage->id) {
             break;
         }
         if (($objJumpTo = \PageModel::findWithDetails($intPage)) !== null) {
             $strDomain = \Environment::get('base');
             // Overwrite the domain
             if ($objJumpTo->dns != '') {
                 $strDomain = ($objJumpTo->useSSL ? 'https://' : 'http://') . $objJumpTo->dns . TL_PATH . '/';
             }
             $GLOBALS['TL_HEAD'][] = sprintf('<link rel="canonical" href="%s">', $strDomain . $objProduct->generateUrl($objJumpTo));
             break;
         }
     }
 }