Frage

Ich versuche, die Produktkollektion zu überschreiben, die von $ this-> getloadedProductCollection () stammt (), also habe ich versucht, die Methode zu überschreiben

class **_**_Model_Rewrite_Layer extends Mage_Catalog_Model_Layer {
  public function prepareProductCollection($collection) {
  ...
  $collection->addAttributeToFilter('my_attribute', array('in' => array(67)));
  ...
}

Aber das scheint nicht zu funktionieren. Wenn ich hinzufüge

echo ( $collection->getSelect() );

Die Abfrage enthält nicht einmal die geschichteten Navigationsfilter, daher kann ich ihre Logik nicht überschreiben.

Ich versuche zu ändern, wie ein geschichteter Navigationsfilter funktioniert.

Bin ich auf dem richtigen Weg, um die präparareProductCollection () zu überschreiben, oder sollte ich eine Methode überschreiben, die später im Prozess aufgerufen wird?

Jede Hilfe wäre geschätzt.

War es hilfreich?

Lösung 2

Okay, dank Tobias Zander habe ich es geschafft, mein Problem zu lösen. Keine Ahnung, wenn dies der richtige Weg ist, aber es tut das, was es für mich sollte, also hier ist meine Lösung dazu:

1. In Ihrer vorhandenen Modul config.xml -Datei fügen Sie dem Folgenden zu den folgenden hinzu <global> Umfang:

<models>
    <catalog_resource>
        <rewrite>
            <layer_filter_attribute>YourCompany_YourModule_Catalog_Model_Resource_Layer_Filter_Attribute</layer_filter_attribute>
        </rewrite>
    </catalog_resource>
</models>

2. Erstellen Sie eine Datei in /app/code/local/YourCompany/YourModule/Catalog/Model/Resource/Layer/Filter/Attribute.php

3. Fügen Sie Folgendes zum neu erstellten hinzu Attribute.php Datei:

<?php
class YourCompany_YourModule_Catalog_Model_Resource_Layer_Filter_Attribute extends Mage_Catalog_Model_Resource_Layer_Filter_Attribute {
public function applyFilterToCollection($filter, $value) {
    $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)
    );

    if( $attribute->getAttributeCode() == 'my_attribute' ) { // Use another logic for your attribute only
        $value = 'x,y,z'; // Your logic goes here to add multiple values for the SQL IN() statement below
        $conditions[3] = $connection->quoteInto("{$tableAlias}.value IN($value)", $value);
    }

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

    return $this;
    }
}
?>

Der einzige Unterschied in meinem Fall besteht darin, zu verwenden

$connection->quoteInto("{$tableAlias}.value IN($value)", $value)

Anstatt von

$connection->quoteInto("{$tableAlias}.value = ?", $value)

Andere Tipps

Ich habe das gelöst, indem ich die Methode apply () der MAGE_CATALOG_MODEL_LAYER_FILTER_ATTRIBUTE -Klasse neu geschrieben habe.

An diesem Ort wird der Attributfilter der Sammlung hinzugefügt, bevore, es wird ausgeführt und Sie können alles tun, was Sie wollen. Dh zur Filterung <= Verwendung:

$oAttributeModel = $this->getAttributeModel();
$this->getLayer()->getProductCollection()->addAttributeToFilter(
                    $oAttributeModel,
                        array(
                            'lteq'  => $sFilterValue,
                        )
                );
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit magento.stackexchange
scroll top