如何在magento中获取活动属性活动选项?

时间:2015-07-20 12:03:12

标签: magento

如何在magento中获取活动属性活动选项? 如何仅显示属性和属性选项,如分层导航左侧块。它仅显示所选类别的活动属性和选项。

我的代码是toolbar.phtml

Tasks: TOP => /tmp/passenger-install.vzccp7/support-binaries/PassengerAgent => /tmp/passenger-ins                              tall.vzccp7/libuv/.libs/libuv.a
------------- End command output snippet -------------
The full log can be found in /tmp/passenger-install-log-1qcyhcn

indexcontroller.php代码是

    <?php
        if(Mage::getStoreConfig('customtoolbar/customtoolbar_general/enabled') == 1):
    ?>
                    <div class="filter-by" style="float: left; padding-left: 10px;">
                        <?php 
                            $entity_type_id =Mage::getModel('catalog/product')->getResource()->getTypeId();
                            $attributes = Mage::getResourceModel('eav/entity_attribute_collection')->setEntityTypeFilter($entity_type_id)->addFieldToFilter("backend_type",array("eq"=>'int'))->addFieldToFilter("frontend_input",array("eq"=>'select'))->addFieldToFilter("used_for_filter_by",array("eq"=>'1'));
                        ?>
                        <table><tr><td>
                                    <label><?php echo $this->__('Shop By') ?></label></td>
                                <td>
                                    <select onchange="fillattvalue(this.value)" id="attributes" style="width: 82px;">
                                        <option value="select"><?php echo $this->__('Please Select') ?></option>
                                        <?php foreach($attributes as $attribute): ?>
                                            <option value="<?php echo $attribute->getAttributeCode(); ?>">
                                                <?php echo $attribute->getFrontendLabel() ?>
                                            </option>
                                            <?php endforeach; ?>
                                    </select></td>
                                <td id="attvalue" style="display: none; padding-left: 10px; "></td>
                            </tr></table>
                    </div>
                     <?php endif ?>









<script language ="javascript" type="text/javascript">
    function fillattvalue(item)
    {
        var parameters = {att_code : item }
        var url = '<?php echo Mage::helper('adminhtml')->getUrl('customtoolbar/index/fillattvalues'); ?>';
        var e = document.getElementById("attributes");
        var select_index = e.options[e.selectedIndex].value;
        if(select_index == "select")
            {
            document.getElementById('attvalue').style.display='none';
        }
        else
            {
            document.getElementById('loading-mask').style.display = 'none';
            new Ajax.Request(url, {
                    method: 'post',
                    //asynchronous: false,
                    onSuccess: function(transport) {
                        document.getElementById('loading-mask').style.display='none';
                        if(transport.responseText) {
                            var response = transport.responseText;
                            response = response.evalJSON();
                            var total_length = response.length;
                            var html='';
                            var cur_url = location.href;
                            var cur_att = document.getElementById("attributes").value;
                            var cur_cat_url ='<?php echo Mage::getBaseUrl().Mage::getModel('catalog/layer')->getCurrentCategory()->getUrlPath() ?>'
                            html+= '<select onchange="setLocation(this.value)" style="width:82px">';
                            html+= '<option value="">Please Select</option>';
                            for (var i=1;i<total_length;i++){
                                var inner_parameters = {
                                    lable : response[i]['lable'],
                                    value : response[i]['value']
                                }
                                <?php $is_anchor = Mage::getModel('catalog/layer')->getCurrentCategory()->getIsAnchor();
                                    if($is_anchor == 1){ ?>
                                    var baseURL = cur_cat_url + "?" + cur_att +"=" + response[i]['value'];
                                    <?php } else { ?>
                                    //var baseURL = cur_url.substring(0, cur_url.indexOf('/', 14))+ "/index.php/catalogsearch/result/?q=" + response[i]['lable'];
                                    var baseURL =  '<?php  echo Mage::getBaseUrl() ?>' + "catalogsearch/advanced/result/?"+item+"[]=" + response[i]['value'];
                                    <?php } ?>
                                html+= '<option value="'+baseURL+'">';
                                html+= response[i]['lable'];
                                html+='</option>';
                            }
                            html+='</select>'
                            document.getElementById('attvalue').innerHTML=html; 
                            document.getElementById('loading-mask').style.display='none';
                            document.getElementById('attvalue').style.display='inline-block';
                        }
                    },
                    parameters:parameters
            });
        }
    }

</script>

1 个答案:

答案 0 :(得分:0)

要使属性显示在导航图层中,以下步骤可能会有所帮助

  1. 转到目录 - &gt;管理产品,选择任何产品,然后点击“创建新属性”
  2. 创建自己的新属性,这里我以“制造”为例
  3. 输入属性信息,在前端属性部分中, 一个。将商店所有者的目录输入类型设置为“下拉列表” 湾在分层导航中使用以下之一:可过滤(带结果),可过滤(无结果) C。将搜索结果中的使用分层导航设置为“是”
  4. 完成“管理/标签选项”详细信息
  5. 保存配置