Skip to content

Commit

Permalink
add indexing
Browse files Browse the repository at this point in the history
  • Loading branch information
hamidpeywasti committed Dec 7, 2014
1 parent c8ec5d6 commit 21aa688
Show file tree
Hide file tree
Showing 4 changed files with 149 additions and 9 deletions.
134 changes: 134 additions & 0 deletions classes/Catalog.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
<?php

/**
* Contao Open Source CMS
*
* Copyright (c) 2005-2014 Leo Feyer
*
* @package Catalog
* @link https://respinar.org/catalog
* @license http://www.gnu.org/licenses/lgpl-3.0.html LGPL
*/


/**
* Run in a custom namespace, so the class can be replaced
*/
namespace catalog;


/**
* Class News
*
* Provide methods regarding news archives.
* @copyright Leo Feyer 2005-2014
* @author Leo Feyer <https://contao.org>
* @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));
}

}
19 changes: 11 additions & 8 deletions config/autoload.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
));


Expand All @@ -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',
));
3 changes: 3 additions & 0 deletions config/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,6 @@
'catalog_related' => 'ModuleCatalogRelated',
)
));

$GLOBALS['TL_HOOKS']['getSearchablePages'][] = array('Catalog', 'getSearchablePages');

2 changes: 1 addition & 1 deletion models/CatalogProductModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down

0 comments on commit 21aa688

Please sign in to comment.