From 21aa688da5b2c74fcb1b1335be4ac38d87d22120 Mon Sep 17 00:00:00 2001 From: hamidabbaszadeh Date: Sun, 7 Dec 2014 22:48:13 +0330 Subject: [PATCH] add indexing --- classes/Catalog.php | 134 +++++++++++++++++++++++++++++++++ config/autoload.php | 19 +++-- config/config.php | 3 + models/CatalogProductModel.php | 2 +- 4 files changed, 149 insertions(+), 9 deletions(-) create mode 100644 classes/Catalog.php diff --git a/classes/Catalog.php b/classes/Catalog.php new file mode 100644 index 0000000..5b89752 --- /dev/null +++ b/classes/Catalog.php @@ -0,0 +1,134 @@ + + * @package News + */ +class Catalog extends \Frontend +{ + + /** + * Add product items to the indexer + * @param array + * @param integer + * @param boolean + * @return array + */ + public function getSearchablePages($arrPages, $intRoot=0, $blnIsSitemap=false) + { + $arrRoot = array(); + + if ($intRoot > 0) + { + $arrRoot = $this->Database->getChildRecords($intRoot, 'tl_page'); + } + + $time = time(); + $arrProcessed = array(); + + // Get all catalog categories + $objCategory = \CatalogCategoryModel::findByProtected(''); + + // Walk through each archive + if ($objCategory !== null) + { + while ($objCategory->next()) + { + // Skip catalog categories without target page + if (!$objCategory->jumpTo) + { + continue; + } + + // Skip catalog categories outside the root nodes + if (!empty($arrRoot) && !in_array($objCategory->jumpTo, $arrRoot)) + { + continue; + } + + // Get the URL of the jumpTo page + if (!isset($arrProcessed[$objCategory->jumpTo])) + { + $objParent = \PageModel::findWithDetails($objCategory->jumpTo); + + // The target page does not exist + if ($objParent === null) + { + continue; + } + + // The target page has not been published (see #5520) + if (!$objParent->published || ($objParent->start != '' && $objParent->start > $time) || ($objParent->stop != '' && $objParent->stop < $time)) + { + continue; + } + + // The target page is exempt from the sitemap (see #6418) + if ($blnIsSitemap && $objParent->sitemap == 'map_never') + { + continue; + } + + // Set the domain (see #6421) + $domain = ($objParent->rootUseSSL ? 'https://' : 'http://') . ($objParent->domain ?: \Environment::get('host')) . TL_PATH . '/'; + + // Generate the URL + $arrProcessed[$objCategory->jumpTo] = $domain . $this->generateFrontendUrl($objParent->row(), ((\Config::get('useAutoItem') && !\Config::get('disableAlias')) ? '/%s' : '/items/%s'), $objParent->language); + } + + $strUrl = $arrProcessed[$objCategory->jumpTo]; + + echo "HELLO!"; + + // Get the items + $objProduct = \CatalogProductModel::findPublishedByPid($objCategory->id); + + if ($objProduct !== null) + { + while ($objProduct->next()) + { + $arrPages[] = $this->getLink($objProduct, $strUrl); + } + } + } + } + + return $arrPages; + } + + + /** + * Return the link of a product + * @param object + * @param string + * @param string + * @return string + */ + protected function getLink($objItem, $strUrl) + { + // Link to the default page + return sprintf($strUrl, (($objItem->alias != '' && !\Config::get('disableAlias')) ? $objItem->alias : $objItem->id)); + } + +} diff --git a/config/autoload.php b/config/autoload.php index 4c354c9..f051465 100644 --- a/config/autoload.php +++ b/config/autoload.php @@ -25,16 +25,19 @@ */ ClassLoader::addClasses(array ( + // Modules + 'catalog\ModuleCatalogDetail' => 'system/modules/catalog/modules/ModuleCatalogDetail.php', + 'catalog\ModuleCatalogRelated' => 'system/modules/catalog/modules/ModuleCatalogRelated.php', + 'catalog\ModuleCatalog' => 'system/modules/catalog/modules/ModuleCatalog.php', + 'catalog\ModuleCatalogList' => 'system/modules/catalog/modules/ModuleCatalogList.php', + // Models - 'catalog\CatalogTypeModel' => 'system/modules/catalog/models/CatalogTypeModel.php', 'catalog\CatalogProductModel' => 'system/modules/catalog/models/CatalogProductModel.php', 'catalog\CatalogCategoryModel' => 'system/modules/catalog/models/CatalogCategoryModel.php', + 'catalog\CatalogTypeModel' => 'system/modules/catalog/models/CatalogTypeModel.php', - // Modules - 'catalog\ModuleCatalogList' => 'system/modules/catalog/modules/ModuleCatalogList.php', - 'catalog\ModuleCatalogRelated' => 'system/modules/catalog/modules/ModuleCatalogRelated.php', - 'catalog\ModuleCatalogDetail' => 'system/modules/catalog/modules/ModuleCatalogDetail.php', - 'catalog\ModuleCatalog' => 'system/modules/catalog/modules/ModuleCatalog.php', + // Classes + 'catalog\Catalog' => 'system/modules/catalog/classes/Catalog.php', )); @@ -43,10 +46,10 @@ */ TemplateLoader::addFiles(array ( - 'mod_catalog_related' => 'system/modules/catalog/templates/modules', 'mod_catalog_list' => 'system/modules/catalog/templates/modules', 'mod_catalog_detail' => 'system/modules/catalog/templates/modules', + 'mod_catalog_related' => 'system/modules/catalog/templates/modules', + 'product_list' => 'system/modules/catalog/templates/product', 'product_full' => 'system/modules/catalog/templates/product', 'product_short' => 'system/modules/catalog/templates/product', - 'product_list' => 'system/modules/catalog/templates/product', )); diff --git a/config/config.php b/config/config.php index cc29353..78c7c52 100644 --- a/config/config.php +++ b/config/config.php @@ -37,3 +37,6 @@ 'catalog_related' => 'ModuleCatalogRelated', ) )); + +$GLOBALS['TL_HOOKS']['getSearchablePages'][] = array('Catalog', 'getSearchablePages'); + diff --git a/models/CatalogProductModel.php b/models/CatalogProductModel.php index 417fe64..b682f57 100644 --- a/models/CatalogProductModel.php +++ b/models/CatalogProductModel.php @@ -160,7 +160,7 @@ public static function countPublishedByPids($arrPids, $blnFeatured=null, array $ public static function findPublishedDefaultByPid($intPid, array $arrOptions=array()) { $t = static::$strTable; - $arrColumns = array("$t.pid=? AND $t.source='default'"); + $arrColumns = array("$t.pid=?"); if (!BE_USER_LOGGED_IN) {