protected function GetListBaseQueryRestrictedToCategories(&$oListConfig, $aCategoryList = null)
    {
        $aCustRestriction = array();

        // get category products
        $categories = $oListConfig->GetMLTIdList('shop_category_mlt');

        $databaseConnection = $this->getDatabaseConnection();
        $quotedListConfigId = $databaseConnection->quote($oListConfig->id);
        $quotedCategories = implode(',', array_map(array($databaseConnection, 'quote'), $categories));

        $sQuery = "SELECT DISTINCT `shop_module_article_list_article`.`name` AS conf_alternativ_header, (-1*`shop_module_article_list_article`.`position`) AS cms_search_weight, `shop_article`.*
                 FROM `shop_article`
            LEFT JOIN `shop_article_shop_category_mlt` ON `shop_article`.`id` = `shop_article_shop_category_mlt`.`source_id`
            LEFT JOIN `shop_article_stats` ON `shop_article`.`id` = `shop_article_stats`.`shop_article_id`
            LEFT JOIN `shop_article_stock` ON `shop_article`.`id` = `shop_article_stock`.`shop_article_id`
            LEFT JOIN `shop_module_article_list_article` ON (`shop_module_article_list_article`.`shop_module_article_list_id` = $quotedListConfigId AND `shop_article`.`id` = `shop_module_article_list_article`.`shop_article_id`)
              ";
        if (count($categories) > 0) {
            $aCustRestriction[] = "`shop_article_shop_category_mlt`.`target_id` IN ($quotedCategories)";
        }

        $manuallySelectedArticles = &$oListConfig->GetFieldShopModuleArticleListArticleList();
        if ($manuallySelectedArticles->Length() > 0) {
            $aCustRestriction[] = "`shop_module_article_list_article`.`shop_module_article_list_id` = $quotedListConfigId";
        }

        // get warengruppen
        $productGroupRestriction = $oListConfig->GetMLTIdList('shop_article_group_mlt');
        if (count($productGroupRestriction) > 0) {
            $sQuery .= ' LEFT JOIN `shop_article_shop_article_group_mlt` ON `shop_article`.`id` = `shop_article_shop_article_group_mlt`.`source_id` ';
            $productGroupRestriction = implode(',', array_map(array($databaseConnection, 'quote'), $productGroupRestriction));
            $aCustRestriction[] = "`shop_article_shop_article_group_mlt`.`target_id` IN ($productGroupRestriction)";
        }

        $sCustQuery = 'WHERE 1=0';
        if (count($aCustRestriction) > 0) {
            $sCustQuery = 'WHERE ('.implode("\nOR ", $aCustRestriction).')';
        }
        if (null !== $aCategoryList) {
            $escapedCategoryList = implode(',', array_map(array($databaseConnection, 'quote'), $aCategoryList));
            $sCustQuery .= " AND (`shop_article_shop_category_mlt`.`target_id` IN ($escapedCategoryList))";
        }
        $sQuery .= $sCustQuery;

        return $sQuery;
    }