0

我们具有按类别、价格和颜色对类别中的产品进行排序的功能 -屏幕截图。类别和价格排序工作完美,但是,颜色抛出错误:

You cannot define a correlation name 'color_range_idx' more than once

我能够追踪堆栈跟踪,但它看起来像 jibbersih,因为我是 Magento 开发的新手。堆栈跟踪可以在这里找到:https ://gist.github.com/4490917

如果有帮助,颜色是自定义产品属性,我正在使用 Magento Enterprise v1.12.0.2

我在这里遇到了类似的问题,但我不确定它是否是正确的修复,或者我将如何使用提供的方法修复它。

4

1 回答 1

0

app/Mage/Catalog/Model/Resource/Layer/Filter/Attribute.php有问题

用以下替换你的类,它的问题应该得到解决。

class Mage_Catalog_Model_Resource_Layer_Filter_Attribute extends Mage_Core_Model_Resource_Db_Abstract
{
/**
 * Initialize connection and define main table name
 *
 */
protected function _construct()
{
    $this->_init('catalog/product_index_eav', 'entity_id');
}

/**
 * Apply attribute filter to product collection
 *
 * @param Mage_Catalog_Model_Layer_Filter_Attribute $filter
 * @param int $value
 * @return Mage_Catalog_Model_Resource_Layer_Filter_Attribute
 */
public function applyFilterToCollection($filter, $value)
{

    $filterSingleton = FilterSingleton::singleton();

    if (!isset($filterSingleton->return)) {

        $collection = $filter->getLayer()->getProductCollection();
        $attribute  = $filter->getAttributeModel();
        $connection = $this->_getReadAdapter();
        $tableAlias = $attribute->getAttributeCode() . '_idx';
        $conditions = array(
            "{$tableAlias}.entity_id = e.entity_id",
            $connection->quoteInto("{$tableAlias}.attribute_id = ?", $attribute->getAttributeId()),
            $connection->quoteInto("{$tableAlias}.store_id = ?", $collection->getStoreId()),
            $connection->quoteInto("{$tableAlias}.value = ?", $value)
        );

        $collection->getSelect()->join(
            array($tableAlias => $this->getMainTable()),
            join(' AND ', $conditions),
            array()
        );

        $filterSingleton->return = $this;

        return $this;

    } else {
        return $filterSingleton->return;
    }
}

/**
 * Retrieve array with products counts per attribute option
 *
 * @param Mage_Catalog_Model_Layer_Filter_Attribute $filter
 * @return array
 */
public function getCount($filter)
{
    // clone select from collection with filters
    $select = clone $filter->getLayer()->getProductCollection()->getSelect();
    // reset columns, order and limitation conditions
    $select->reset(Zend_Db_Select::COLUMNS);
    $select->reset(Zend_Db_Select::ORDER);
    $select->reset(Zend_Db_Select::LIMIT_COUNT);
    $select->reset(Zend_Db_Select::LIMIT_OFFSET);

    $connection = $this->_getReadAdapter();
    $attribute  = $filter->getAttributeModel();
    $tableAlias = sprintf('%s_idx', $attribute->getAttributeCode());
    $conditions = array(
        "{$tableAlias}.entity_id = e.entity_id",
        $connection->quoteInto("{$tableAlias}.attribute_id = ?", $attribute->getAttributeId()),
        $connection->quoteInto("{$tableAlias}.store_id = ?", $filter->getStoreId()),
    );

    $select
        ->join(
            array($tableAlias => $this->getMainTable()),
            join(' AND ', $conditions),
            array('value', 'count' => new Zend_Db_Expr("COUNT({$tableAlias}.entity_id)")))
        ->group("{$tableAlias}.value");

    return $connection->fetchPairs($select);
    }
}
class FilterSingleton {

static private $instance;

public $return = null;

    private function __construct() {

}

static public function singleton() {
     if (!isset(self::$instance)) {
        $c = __CLASS__;
        self::$instance = new $c;
    }

    return self::$instance;
}
}

http://aceph.tumblr.com/post/21851233473/magento-you-cannot-define-a-correlation-name

于 2013-01-09T15:04:18.400 回答