Filter Magento2类滤光片
如何筛选Magento2多类别Filter Magento2类滤光片,filter,magento2,Filter,Magento2,如何筛选Magento2多类别 <?xml version="1.0" encoding="UTF-8"?> <listing xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd"><listingToolbar name="listing
<?xml version="1.0" encoding="UTF-8"?>
<listing xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd"><listingToolbar name="listing_top">
<filters name="listing_filters">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="templates" xsi:type="array">
<item name="filters" xsi:type="array">
<item name="select" xsi:type="array">
<item name="component" xsi:type="string">Magento_Ui/js/form/element/ui-select</item>
<item name="template" xsi:type="string">ui/grid/filters/elements/ui-select</item>
</item>
</item>
</item>
</item>
</argument>
</filters>
Magento_Ui/js/form/element/Ui选择
ui/网格/过滤器/元素/ui选择
请帮助我如何添加类别过滤器最近我有机会重写Magento的分层导航标准功能。请求非常具体,因为客户机希望所有“过滤器”始终可见。例如,如果您希望按颜色过滤结果(假设您有黄色、绿色、红色、蓝色和洋红),则会过滤产品,但分层导航会显示所有过滤器。这样,客户可以重新筛选当前类别中的产品,而无需返回到类别视图 用于分层导航的文件位于app
/design/frontend/base/default/template/catalog/layer/
文件夹中。用于分层导航的文件是view.phtml
——当我们点击一个类别时,它会显示所有的过滤器。用于活动状态的文件是state.phtml
——当我们点击其中一个过滤器时,它负责结果——所以我们要编辑这个。因此,将state.phtml
从base复制到您的包或主题中
这是state.phtml中的原始代码:
<?php $_filters = $this->getActiveFilters() ?>
<?php if(!empty($_filters)): ?>
<div class="currently">
<p class="block-subtitle"><?php echo $this->__('Currently Shopping by:') ?></p>
<ol>
<?php foreach ($_filters as $_filter): ?>
<li>
<a href="<?php echo $_filter->getRemoveUrl() ?>" title="<?php echo $this->__('Remove This Item') ?>" class="btn-remove"><?php echo $this->__('Remove This Item') ?></a>
<span class="label"><?php echo $this->__($_filter->getName()) ?>:</span> <?php echo $this->stripTags($_filter->getLabel()) ?>
</li>
<?php endforeach; ?>
</ol>
<div class="actions"><a href="<?php echo $this->getClearUrl() ?>"><?php echo $this->__('Clear All') ?></a></div>
</div>
<?php endif; ?>
Since we’re going to need url path of current category add this code before “currently” div block
<?php $obj = new Mage_Catalog_Block_Navigation(); ?>
<?php $_current_category=$obj->getCurrentCategory()->getUrlPath(); ?> //getting url path of current category
<?php $subs = $obj->getCurrentCategory()->getAllChildren(true); ?> //getting ids of subcategories of current category
即使您将属性设置为Filterable(带结果)
您仍然需要对产品进行计数,以便只输出产品计数>0的属性值
<?php foreach($split as $color): ?> //check out how many products have the same attribute value
<?php if($color==$attr["value"]): ?>
<?php $count++;?>
<?php endif; ?>
<?php endforeach; ?>
<?php endif;?>
<?php endforeach; ?>
<?php if($count>0):?> // check if any product has that attribute value
<li><a href="<?php echo $this->getUrl('').$_current_category ?>?color=<?php echo $attr["value"]?>" ><?php echo $attr["label"]; ?></a></li> // if not currently active filter make a link
<?php endif; ?>
<?php else:?>
<li class="current"> <?php echo $this->stripTags($_filter->getLabel()); ?></li> // if currently active filter write out the label
<?php endif;?>
<?php endif; ?>
<?php endforeach; ?>
<?php endforeach; ?> // ending the first for loop (foreach($filters as $filter))
</ol>
</dd>
</dl>
<a class="all" style="float:right;" href="<?php echo $this->getClearUrl()?>">All</a> // show all products, return from current state back to category view
</div>
<?php endif; ?>
//检查有多少产品具有相同的属性值
//检查是否有任何产品具有该属性值
//如果当前未激活筛选器,请创建链接
//如果当前过滤器处于活动状态,请写出标签
//结束第一个for循环(foreach($filters as$filter))
//显示所有产品,从当前状态返回类别视图
就这样。我们一直保持过滤器可见的任务已经完成,StackOverflow并不是一个教程服务。在请求帮助之前,请联机搜索并尝试执行某些操作。
<?php foreach($attroptions as $attr): ?> // get value and label of each attribute
<?php $count=0; ?>
<?php if($attr["value"]!=""): ?>
<?php $val=$attr["value"] ?>
<?php $collection->addFieldToFilter(array(array('attribute'=>'themes','gt'=>10)))?> // collection of attribute values and labels for all values
//greater then 10 (in this case attribute values range was 18-39)
<?php $proddata=$collection->getData() ?> // get product data for all attribute values
<?php if($attr["label"]!= $this->stripTags($_filter->getLabel())): ?> // make a nice looking label
<?php foreach($proddata as $prod):?>
<?php if($prod["type_id"]=="configurable"): ?> // in this store all products were configurable
<?php $split=split(",", $prod["color"]);?> // get the attribute values that correspond with one product (a product may have more
// then one attribute value and they're separated by commas that's why we split the string with "," as deliminator)
<?php foreach($split as $color): ?> //check out how many products have the same attribute value
<?php if($color==$attr["value"]): ?>
<?php $count++;?>
<?php endif; ?>
<?php endforeach; ?>
<?php endif;?>
<?php endforeach; ?>
<?php if($count>0):?> // check if any product has that attribute value
<li><a href="<?php echo $this->getUrl('').$_current_category ?>?color=<?php echo $attr["value"]?>" ><?php echo $attr["label"]; ?></a></li> // if not currently active filter make a link
<?php endif; ?>
<?php else:?>
<li class="current"> <?php echo $this->stripTags($_filter->getLabel()); ?></li> // if currently active filter write out the label
<?php endif;?>
<?php endif; ?>
<?php endforeach; ?>
<?php endforeach; ?> // ending the first for loop (foreach($filters as $filter))
</ol>
</dd>
</dl>
<a class="all" style="float:right;" href="<?php echo $this->getClearUrl()?>">All</a> // show all products, return from current state back to category view
</div>
<?php endif; ?>