因此,我将对此主题进行详细说明,因为它很重要,但原始主题/答案有点不完整(截至 Enterprise 1.14.1)。
简单地重写a/c/c/E/Catalog/Model/Index/Action/Category/Flat/Refresh.php 只是解决方案的一半。在类别的拖放重新排序期间,在观察类别保存和移动事件的观察者中会调用以下代码...
public function processCategorySaveEvent(Varien_Event_Observer $observer)
{
if ($this->_isLiveCategoryReindexEnabled()) {
// ...
$client->execute('enterprise_catalog/index_action_category_flat_refresh_row', $arguments);
}
}
public function processCategoryMoveEvent(Varien_Event_Observer $observer)
{
if ($this->_isLiveCategoryReindexEnabled()) {
// ...
$client->execute('enterprise_catalog/index_action_category_flat_refresh_changelog');
}
};
很遗憾,enterprise_catalog/index_action_category_flat_refresh_row 和 enterprise_catalog/index_action_category_flat_refresh_changelog 直接扩展了 a/c/c/E/Catalog/Model/Index/Action/Category/Flat/Refresh.php,因此也需要重写。
最后,最终修复看起来更像这样......
a/c/local/Namespace/Modulename/etc/config.xml
<config>
<global>
<models>
<modulename>
<class>Namespace_Modulename_Model</class>
</modulename>
<!-- Enterprise_Catalog_Model_Index_Action_Category_Flat_Refresh_Row -->
<!-- Enterprise_Catalog_Model_Index_Action_Category_Flat_Refresh_Changelog -->
<!-- Enterprise_Catalog_Model_Index_Action_Category_Flat_Refresh -->
<enterprise_catalog>
<rewrite>
<index_action_category_flat_refresh_row>Namespace_Modulename_Model_Catalog_Index_Action_Category_Flat_Refresh_Row</index_action_category_flat_refresh_row>
<index_action_category_flat_refresh_changelog>Namespace_Modulename_Model_Catalog_Index_Action_Category_Flat_Refresh_Changelog</index_action_category_flat_refresh_changelog>
<index_action_category_flat_refresh>Namespace_Modulename_Model_Catalog_Index_Action_Category_Flat_Refresh</index_action_category_flat_refresh>
</rewrite>
</enterprise_catalog>
</models>
</global>
</config>
a/c/local/Namespace/Modulename/Model/Catalog/Index/Action/Category/Flat/Refresh/Row.php
class Namespace_Module_Model_Catalog_Index_Action_Category_Flat_Refresh_Row extends Namespace_Module_Model_Catalog_Index_Action_Category_Flat_Refresh
{
protected $_keyColumnIdValue;
public function __construct(array $args)
{
parent::__construct($args);
if (isset($args['value'])) {
$this->_keyColumnIdValue = $args['value'];
}
}
public function execute()
{
if (!$this->_isFlatIndexerEnabled()) {
return $this;
}
$this->_validate();
$this->_reindex(array($this->_keyColumnIdValue));
return $this;
}
}
a/c/local/Namespace/Modulename/Model/Catalog/Index/Action/Category/Flat/Refresh/Changelog.php
class Namespace_Module_Model_Catalog_Index_Action_Category_Flat_Refresh_CHangelog extends Namespace_Module_Model_Catalog_Index_Action_Category_Flat_Refresh
{
public function execute()
{
if (!$this->_isFlatIndexerEnabled()) {
return $this;
}
$this->_validate();
$changedIds = $this->_selectChangedIds();
if (is_array($changedIds) && count($changedIds) > 0) {
$idsBatches = array_chunk($changedIds, Mage::helper('enterprise_index')->getBatchSize());
foreach ($idsBatches as $changedIds) {
$this->_reindex($changedIds);
}
$this->_setChangelogValid();
}
return $this;
}
}
a/c/local/Namespace/Modulename/Model/Catalog/Index/Action/Category/Flat/Refresh.php
foreach ($categoriesIdsChunk as $categoryId) {
if (!isset($attributesData[$categoryId])) {
continue;
}
// Flat Reindexing Fix
// Flat Reindexing Fix
$category = Mage::getModel('catalog/category');
// Flat Reindexing Fix
// Flat Reindexing Fix
if ($category->load($categoryId)->getId()) {
$data[] = $this->_prepareValuesToInsert(
array_merge(
$category->getData(),
$attributesData[$categoryId],
array('store_id' => $store->getId())
)
);
}
}
我觉得可能有更好的方法来实现这一点,这种方法侵入性较小,但确实有效。请在更新时注意此代码,因为它可能需要注意。