在 Magento 中,如果在分层导航中选择“颜色”属性,“颜色”的值会自动消失并显示结果。如何检索所选过滤器的名称?
All the applied filters are stored in layer state object. You can easily retrieve them by using the following snippet:
$appliedFilters = Mage::getSingleton('catalog/layer')->getState()->getFilters();
It will return you an array of filter item objects. You can retrieve name and applied value of a single filter item by doing something like this:
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")
}
You can get filter's attribute code or id through this code:
$appliedFilters = Mage::getSingleton('catalog/layer')->getState()->getFilters();
foreach ($appliedFilters as $item) {
echo $item->getFilter()->getAttributeModel()->getAttributeId();
echo $item->getFilter()->getAttributeModel()->getAttributeCode();
}
在 Magento 2 中: $this->getLayer()->getState()->getData("filters")
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.