12

Magentoでは、レイヤードナビゲーションで「color」属性を選択すると、「color」の値が自動的に消えて結果が表示されます。選択したフィルターの名前を取得するにはどうすればよいですか?

4

3 に答える 3

35

適用されたすべてのフィルターは、レイヤー状態オブジェクトに格納されます。次のスニペットを使用すると、簡単に取得できます。

$appliedFilters = Mage::getSingleton('catalog/layer')->getState()->getFilters();

フィルタアイテムオブジェクトの配列が返されます。次のようにすると、単一のフィルター項目の名前と適用値を取得できます。

foreach ($appliedFilters as $item) {
    $item->getName(); // Name of the filter
    $item->getLabel(); // Currently selected value
    $item->getFilter()->getRequestVar(); // Filter code (usually attribute code, except category filter, where it equals "cat")
}
于 2012-08-08T13:31:03.103 に答える
0

次のコードを使用して、フィルターの属性コードまたはIDを取得できます。

$appliedFilters = Mage::getSingleton('catalog/layer')->getState()->getFilters();
foreach ($appliedFilters as $item) {
    echo $item->getFilter()->getAttributeModel()->getAttributeId();
    echo $item->getFilter()->getAttributeModel()->getAttributeCode();
}
于 2019-02-12T11:27:04.550 に答える
0

Magento 2の場合:$ this-> getLayer()-> getState()-> getData( "filters")

于 2021-01-18T09:14:44.913 に答える