3

I have a custom attribute called m2_price, which is the Metre Squared price of a piece of carpet.

I've enabled it to be filterable with results in the layered navigation and this all works fine.

However, the prices are stored EXCLUDING tax, so the filter is generated based on these prices. Is there any way I can make the filter then add Tax on to the m2_price just how it works with the normal product price?

I've tried searching for this and I've been unable to find anything which even hints to a solution.

0

There's an issue with app/Mage/Catalog/Model/Resource/Layer/Filter/Attribute.php

Swap out your class with the following and it problem should be solved.

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;
}
}

visit:-http://islamic-posters.aceph.me/post/21851233473/magento-you-cannot-define-a-correlation-name

  • I changed this but it did not fix my problem. – Karl Jul 13 '15 at 13:21
  • 1
    Bad idea. How does this solve the OPs question. What is this issue you are refering to. What was fixed. Would help clarify. Never a great idea to just go and replace core files like this. – ProxiBlue Aug 24 '16 at 23:22
0

I would start by looking how magento itself do with the built in price, these clases should be an starting point:

Mage_Catalog_Block_Layer_Filter_Price and from here you can come to: Mage_Catalog_Model_Layer_Filter_Price try to find how price filters are handle or create your layer filter inheriting from the default price one. There is a big amount of functionality involved though.

NOTE: A workaround I would try is to specify in front end that those prices are without taxes and then create a custom total for applying taxes over these values when adding product to cart.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.