2015-07-20 129 views
0

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

我的代码是toolbar.phtml

<?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> 

indexcontroller.php代码

<?php 
    class Biztech_Customtoolbar_IndexController extends Mage_Core_Controller_Front_Action 
    { 
     public function indexAction() 
     { 
      $this->loadLayout();  
      $this->renderLayout(); 
     } 
     public function fillattvaluesAction() 
     { 
      $att_code = $this->getRequest()->getParam('att_code'); 
      $json = array(); 
      $att = Mage::getSingleton('eav/config')->getAttribute('catalog_product', $att_code); 
      $options = $att->getSource()->getAllOptions(); 

      foreach($options as $option) 
      { 
       $json[] = array(
        'lable' => $option['label'], 
        'value' => $option['value'] 
       ); 
      } 
      $this->getResponse()->setBody(Zend_Json::encode($json)); 
     } 


} 

回答

0

要出现在导航层中的属性,下面的步骤可以帮助

  1. 围棋到产品目录 - >管理产品,选择任何产品,然后点击'创建新属性'
  2. 创建属于您自己的新属性,这里我以“制造”为例
  3. 输入属性信息,在前端属性部分 a。 b。将商店所有者的商品目录输入类型设置为“下拉” b。在分层导航中使用以下选项之一:可筛选(带结果),可筛选(无结果) c。在搜索设置使用效果分层导航到“是”
  4. 完成“管理/标签选项”细节
  5. 保存配置
+0

我目前使用这个扩展http://www.magentocommerce.com/ magento-connect/custom-product-grid-filters.html我这两个文件来自这个扩展。 – Sarps