在每个页面上调用magento类别树菜单查询

时间:2012-07-10 13:49:50

标签: magento tree windows-ce categories

我在Magento CE 1.6.2的每个页面都调用了这个查询。为了找出它的调用位置,我已经禁用了所有模块,删除了已完成的自定义但仍然被调用,这个查询正在减慢页面加载时间,并且在我的智慧结束时试图找出如何阻止它从被执行。

下面给出了查询,为简单起见,我删除了很多类别id'以保持sql简短。如果我能得到解决方案或提示来阻止调用这个查询,那就太好了。

SELECT `e`.*, IF(at_is_active.value_id > 0, at_is_active.value, at_is_active_default.value) AS `is_active`, IF(at_include_in_menu.value_id > 0, at_include_in_menu.value, at_include_in_menu_default.value) AS `include_in_menu`, `core_url_rewrite`.`request_path` FROM `catalog_category_entity` AS `e`
INNER JOIN `catalog_category_entity_int` AS `at_is_active_default` ON (`at_is_active_default`.`entity_id` = `e`.`entity_id`) AND (`at_is_active_default`.`attribute_id` = '119') AND `at_is_active_default`.`store_id` = 0
LEFT JOIN `catalog_category_entity_int` AS `at_is_active` ON (`at_is_active`.`entity_id` = `e`.`entity_id`) AND (`at_is_active`.`attribute_id` = '119') AND (`at_is_active`.`store_id` = 1)
INNER JOIN `catalog_category_entity_int` AS `at_include_in_menu_default` ON (`at_include_in_menu_default`.`entity_id` = `e`.`entity_id`) AND (`at_include_in_menu_default`.`attribute_id` = '934') AND `at_include_in_menu_default`.`store_id` = 0
LEFT JOIN `catalog_category_entity_int` AS `at_include_in_menu` ON (`at_include_in_menu`.`entity_id` = `e`.`entity_id`) AND (`at_include_in_menu`.`attribute_id` = '934') AND (`at_include_in_menu`.`store_id` = 1)
LEFT JOIN `core_url_rewrite` ON (core_url_rewrite.category_id=e.entity_id) AND (core_url_rewrite.is_system=1 AND core_url_rewrite.product_id IS NULL AND core_url_rewrite.store_id='1' AND id_path LIKE 'category/%') WHERE (`e`.`entity_type_id` = '9') AND (`e`.`entity_id` IN('105', '125', '284', '285', '286', '288', '289', '185', '463', '464', '465', '625')) AND (`e`.`entity_id` NOT IN('140', '145',  '530', '531', '775')) AND (IF(at_is_active.value_id > 0, at_is_active.value, at_is_active_default.value) = '1') AND (IF(at_include_in_menu.value_id > 0, at_include_in_menu.value, at_include_in_menu_default.value) = '1')

干杯 阿琼

4 个答案:

答案 0 :(得分:1)

这可能是由index indexue_url

引起的

快速解决方法是将所有索引设置为手动。

然后通过cron hourly运行此shell脚本:

php shell/indexer.php --reindex catalog_product_attribute
php shell/indexer.php --reindex catalog_product_price
php shell/indexer.php --reindex tag_summary
php shell/indexer.php --reindex cataloginventory_stock
php shell/indexer.php --reindex catalogsearch_fulltext
php shell/indexer.php --reindex catalog_category_product
php shell/indexer.php --reindex catalog_category_flat
php shell/indexer.php --reindex catalog_product_flat 

它会对所有网址进行索引。

然后每晚运行一次:

<?php

echo "clearing core_url_rewrite so that indexer can repopulate immediately\n";

require_once "/home/path/to/store/app/Mage.php";
umask( 0 );
Mage::App('default');

$resource = Mage::getSingleton('core/resource');

$writeConnection = $resource->getConnection('core_write');

$query = "TRUNCATE `core_url_rewrite`";

$writeConnection->query($query);

echo "cleared\n";

$start = time();

echo "reindexing catalog_url start \n";

$process = Mage::getSingleton('index/indexer')->getProcessByCode('catalog_url');
$process->reindexEverything();

$finish = time() - $start;

echo "reindexing catalog_url finished in ".$finish." seconds \n";

?>

答案 1 :(得分:0)

看起来像是一个用于导航的查询。 magento默认主题将动态顶部导航的类别拉入:

/app/code/core/Mage/Catalog/Block/Navigation.php

renderCategoriesMenuHtml()从(默认情况下)从:

调用

碱/默认/模板/目录/导航/ top.phtml

答案 2 :(得分:0)

top.phtml代码替换为定期更新的菜单静态版本。

在magento根文件夹中创建文件menu.php

#!/usr/bin/php
<?php
    require_once('app/Mage.php');
    Mage::app();

        $block = new Mage_Catalog_Block_Navigation();
        $_menu = $block->renderCategoriesMenuHtml(0,'level-top');

        echo "
        <div class='nav-container'>
            <ul id='nav'>
                        $_menu
            </ul>
        </div>
        ";
?>

然后,在./shell目录中创建另一个文件create-category-menus.sh

#!/bin/bash
/[path to magento root]/menu.php > /[path to magento root]/app/design/frontend/default/[template_name]/template/catalog/navigation/top.phtml.temp

rm -f /[path to magento root]/app/design/frontend/default/[template_name]/template/catalog/navigation/top.phtml

mv  /[path to magento root]/app/design/frontend/default/[template_name]/template/catalog/navigation/top.phtml.temp  /[path to magento root]/app/design/frontend/default/[template_name]/template/catalog/navigation/top.phtml

chown [webserver-user].[webserver-group]  /[path to magento root]/app/design/frontend/default/[template_name]/template/catalog/navigation/top.phtml

现在,只需定期将create-category-menus.sh添加到您的crontab,比如15分钟左右。

您可能需要为输出文件创建文件夹结构,这也假设您使用的是Linux服务器。如果你不是那么你应该。 :)

答案 3 :(得分:0)

启用Blocks HTML输出缓存。因此,菜单必须仅呈现第一个页面调用。由于magento 1.7不再缓存此块,因此需要以编程方式启用缓存。

相关问题