Skip to main content
added the code snippet to show what I have achieved so far regarding this question
Source Link
Magebuddies
  • 147
  • 2
  • 13

Update added in the answerThis is what I have achieved so far

    $categoryid = (int)$this->getRequest()->getParam('cid');
    $designid = $this->getRequest()->getParam('manufacturer');
    $sizeid = $this->getRequest()->getParam('size');
    $colorid = $this->getRequest()->getParam('color');
    $pricerange = $this->getRequest()->getParam('price');
   
    $layer = Mage::getSingleton("catalog/layer"); 
    $_category = Mage::getSingleton("catalog/category")->load($categoryid);
    $layer->setCurrentCategory($_category);
    $attributes = $layer->getFilterableAttributes();
    
    $attrs["design"]['label'] = __("Brands");
    $attributeCode = Mage::getStoreConfig('shopbybrand/general/attribute_code', $storeId);        
    $attrCode = $attributeCode ? $attributeCode : 'manufacturer';
    $attrs["design"]['code'] = $attrCode;
    $attrs["design"]['sort'] = 1;
    
    $attrs["color"]['label'] = __("Color");
    $attrs["color"]['code'] = __("color");
    $attrs["color"]['sort'] = 2;
    
    $attrs["size"]['label'] = __("Size");
    $attrs["size"]['code'] = __("size");
    $attrs["size"]['sort'] = 3;
    
    $attrs["price"]['label'] = __("Price");
    $attrs["price"]['code'] = __("price");
    $attrs["price"]['sort'] = 4;
    
    // print_r($attributes->getData());exit();
    $attributeCollection =array();
    
    $i=0;
    $attributeCollection = array();
    foreach ($attributes as $attribute) {
    if($attribute->getAttributeCode() == 'price') {
     $filterBlockName = 'catalog/layer_filter_price';
    }elseif($attribute->getBackendType() == 'decimal'){
     $filterBlockName = 'catalog/layer_filter_decimal';
    }else{
    $filterBlockName = 'catalog/layer_filter_attribute';
    }
    $result = Mage::app()->getLayout()->createBlock($filterBlockName)->setLayer($layer)->setAttributeModel($attribute)->init();
    $attributeCollection[$i]['Code'] = $attribute->getAttributeCode();
    $attributeCollection[$i]['Label'] = $attribute->getStoreLabel();
    $j=0;
    $attributeOptionCollection =array();
    foreach($result->getItems() as $option) {
        $val = $option->getValue();
        if($attribute->getAttributeCode()=='price'){
            $attrs["price"]['options'][$j]['label'] = strip_tags($option->getLabel());
            if(trim($val) == ""){
                $val = $pricerange;
                }
            $val_arr = explode(',',$val);
            $pricerange_arr = explode(',',$pricerange);
            if(strstr($pricerange,',') || strstr($val,',')){
                $val = array_merge(array_diff($val_arr, $pricerange_arr), array_diff($pricerange_arr, $val_arr));
                $val = $val[0];
                }   
            $attrs["price"]['options'][$j]['value'] = $val;
        }elseif($attribute->getAttributeCode()=='color'){
            $attrs["color"]['options'][$j]['label'] = $option->getLabel();
            if(trim($val) == ""){
                $val = $colorid;
                }
            $val_arr = explode(',',$val);
            $colorid_arr = explode(',',$colorid);
            if(strstr($colorid,',') || strstr($val,',')){
                $val = array_merge(array_diff($val_arr, $colorid_arr), array_diff($colorid_arr, $val_arr));
                $val = $val[0];
                }
            $attrs["color"]['options'][$j]['value'] = $val;
        }elseif($attribute->getAttributeCode()=='size'){
            $attrs["size"]['options'][$j]['label'] = $option->getLabel();
            if(trim($val) == ""){
                $val = $sizeid;
                }
            $val_arr = explode(',',$val);
            $sizeid_arr = explode(',',$sizeid);
            if(strstr($sizeid,',') || strstr($val,',')){
                $val = array_merge(array_diff($val_arr, $sizeid_arr), array_diff($sizeid_arr, $val_arr));
                $val = $val[0];
                }
            $attrs["size"]['options'][$j]['value'] = $val;
        }elseif($attribute->getAttributeCode()=='manufacturer'){
            $attrs["design"]['options'][$j]['label'] = $option->getLabel();
            if(trim($val) == ""){
                $val = $designid;
                }
            $val_arr = explode(',',$val);
            $designid_arr = explode(',',$designid);
            if(strstr($designid,',') || strstr($val,',')){
                $val = array_merge(array_diff($val_arr, $designid_arr), array_diff($designid_arr, $val_arr));
                $val = $val[0];
                }
        $attrs["design"]['options'][$j]['value'] = $val;
    }
    $j++;
    }
    //$attributeCollection[$i]['Options'] = $attributeOptionCollection;
    $i++;
    }
    header("Content-Type: application/json");
    print_r(json_encode($attrs));
    die;    
   

Update added in the answer

Update This is what I have achieved so far

    $categoryid = (int)$this->getRequest()->getParam('cid');
    $designid = $this->getRequest()->getParam('manufacturer');
    $sizeid = $this->getRequest()->getParam('size');
    $colorid = $this->getRequest()->getParam('color');
    $pricerange = $this->getRequest()->getParam('price');
   
    $layer = Mage::getSingleton("catalog/layer"); 
    $_category = Mage::getSingleton("catalog/category")->load($categoryid);
    $layer->setCurrentCategory($_category);
    $attributes = $layer->getFilterableAttributes();
    
    $attrs["design"]['label'] = __("Brands");
    $attributeCode = Mage::getStoreConfig('shopbybrand/general/attribute_code', $storeId);        
    $attrCode = $attributeCode ? $attributeCode : 'manufacturer';
    $attrs["design"]['code'] = $attrCode;
    $attrs["design"]['sort'] = 1;
    
    $attrs["color"]['label'] = __("Color");
    $attrs["color"]['code'] = __("color");
    $attrs["color"]['sort'] = 2;
    
    $attrs["size"]['label'] = __("Size");
    $attrs["size"]['code'] = __("size");
    $attrs["size"]['sort'] = 3;
    
    $attrs["price"]['label'] = __("Price");
    $attrs["price"]['code'] = __("price");
    $attrs["price"]['sort'] = 4;
    
    // print_r($attributes->getData());exit();
    $attributeCollection =array();
    
    $i=0;
    $attributeCollection = array();
    foreach ($attributes as $attribute) {
    if($attribute->getAttributeCode() == 'price') {
     $filterBlockName = 'catalog/layer_filter_price';
    }elseif($attribute->getBackendType() == 'decimal'){
     $filterBlockName = 'catalog/layer_filter_decimal';
    }else{
    $filterBlockName = 'catalog/layer_filter_attribute';
    }
    $result = Mage::app()->getLayout()->createBlock($filterBlockName)->setLayer($layer)->setAttributeModel($attribute)->init();
    $attributeCollection[$i]['Code'] = $attribute->getAttributeCode();
    $attributeCollection[$i]['Label'] = $attribute->getStoreLabel();
    $j=0;
    $attributeOptionCollection =array();
    foreach($result->getItems() as $option) {
        $val = $option->getValue();
        if($attribute->getAttributeCode()=='price'){
            $attrs["price"]['options'][$j]['label'] = strip_tags($option->getLabel());
            if(trim($val) == ""){
                $val = $pricerange;
                }
            $val_arr = explode(',',$val);
            $pricerange_arr = explode(',',$pricerange);
            if(strstr($pricerange,',') || strstr($val,',')){
                $val = array_merge(array_diff($val_arr, $pricerange_arr), array_diff($pricerange_arr, $val_arr));
                $val = $val[0];
                }   
            $attrs["price"]['options'][$j]['value'] = $val;
        }elseif($attribute->getAttributeCode()=='color'){
            $attrs["color"]['options'][$j]['label'] = $option->getLabel();
            if(trim($val) == ""){
                $val = $colorid;
                }
            $val_arr = explode(',',$val);
            $colorid_arr = explode(',',$colorid);
            if(strstr($colorid,',') || strstr($val,',')){
                $val = array_merge(array_diff($val_arr, $colorid_arr), array_diff($colorid_arr, $val_arr));
                $val = $val[0];
                }
            $attrs["color"]['options'][$j]['value'] = $val;
        }elseif($attribute->getAttributeCode()=='size'){
            $attrs["size"]['options'][$j]['label'] = $option->getLabel();
            if(trim($val) == ""){
                $val = $sizeid;
                }
            $val_arr = explode(',',$val);
            $sizeid_arr = explode(',',$sizeid);
            if(strstr($sizeid,',') || strstr($val,',')){
                $val = array_merge(array_diff($val_arr, $sizeid_arr), array_diff($sizeid_arr, $val_arr));
                $val = $val[0];
                }
            $attrs["size"]['options'][$j]['value'] = $val;
        }elseif($attribute->getAttributeCode()=='manufacturer'){
            $attrs["design"]['options'][$j]['label'] = $option->getLabel();
            if(trim($val) == ""){
                $val = $designid;
                }
            $val_arr = explode(',',$val);
            $designid_arr = explode(',',$designid);
            if(strstr($designid,',') || strstr($val,',')){
                $val = array_merge(array_diff($val_arr, $designid_arr), array_diff($designid_arr, $val_arr));
                $val = $val[0];
                }
        $attrs["design"]['options'][$j]['value'] = $val;
    }
    $j++;
    }
    //$attributeCollection[$i]['Options'] = $attributeOptionCollection;
    $i++;
    }
    header("Content-Type: application/json");
    print_r(json_encode($attrs));
    die;    
   
removed update and added taht in the answer
Source Link
Magebuddies
  • 147
  • 2
  • 13

Update

This is what I have achieved so far, it is filtering the attributes based on category but how I can filter this based on an attribute value like added in case if I select the color as Red then how I can apply this to the current resultanswer

$categoryid = (int)$this->getRequest()->getParam('cid');
    $designid = $this->getRequest()->getParam('manufacturer');
    $sizeid = $this->getRequest()->getParam('size');
    $colorid = $this->getRequest()->getParam('color');
    $pricerange = $this->getRequest()->getParam('price');
   
    $layer = Mage::getSingleton("catalog/layer"); 
    $_category = Mage::getSingleton("catalog/category")->load($categoryid);
    $layer->setCurrentCategory($_category);
    $attributes = $layer->getFilterableAttributes();
    
    $attrs["design"]['label'] = __("Brands");
    $attributeCode = Mage::getStoreConfig('shopbybrand/general/attribute_code', $storeId);        
    $attrCode = $attributeCode ? $attributeCode : 'manufacturer';
    $attrs["design"]['code'] = $attrCode;
    $attrs["design"]['sort'] = 1;
    
    $attrs["color"]['label'] = __("Color");
    $attrs["color"]['code'] = __("color");
    $attrs["color"]['sort'] = 2;
    
    $attrs["size"]['label'] = __("Size");
    $attrs["size"]['code'] = __("size");
    $attrs["size"]['sort'] = 3;
    
    $attrs["price"]['label'] = __("Price");
    $attrs["price"]['code'] = __("price");
    $attrs["price"]['sort'] = 4;
    
    // print_r($attributes->getData());exit();
    $attributeCollection =array();
    
    $i=0;
    $attributeCollection = array();
    foreach ($attributes as $attribute) {
    if($attribute->getAttributeCode() == 'price') {
     $filterBlockName = 'catalog/layer_filter_price';
    }elseif($attribute->getBackendType() == 'decimal'){
     $filterBlockName = 'catalog/layer_filter_decimal';
    }else{
    $filterBlockName = 'catalog/layer_filter_attribute';
    }
    $result = Mage::app()->getLayout()->createBlock($filterBlockName)->setLayer($layer)->setAttributeModel($attribute)->init();
    $attributeCollection[$i]['Code'] = $attribute->getAttributeCode();
    $attributeCollection[$i]['Label'] = $attribute->getStoreLabel();
    $j=0;
    $attributeOptionCollection =array();
    foreach($result->getItems() as $option) {
    if($attribute->getAttributeCode()=='price'){
        $attrs["price"]['options'][$j]['label'] = strip_tags($option->getLabel());
        $attrs["price"]['options'][$j]['value'] = $option->getValue();
    }elseif($attribute->getAttributeCode()=='color'){
        $attrs["color"]['options'][$j]['label'] = $option->getLabel();
        $attrs["color"]['options'][$j]['value'] = $option->getValue();
    }elseif($attribute->getAttributeCode()=='size'){
        $attrs["size"]['options'][$j]['label'] = $option->getLabel();
        $attrs["size"]['options'][$j]['value'] = $option->getValue();
    }else{
        $attrs["design"]['options'][$j]['label'] = $option->getLabel();
        $attrs["design"]['options'][$j]['value'] = $option->getValue();
    }
    $j++;
    }
    //$attributeCollection[$i]['Options'] = $attributeOptionCollection;
    $i++;
    }
    header("Content-Type: application/json");
    print_r(json_encode($attrs));
    die;    

Update

This is what I have achieved so far, it is filtering the attributes based on category but how I can filter this based on an attribute value like in case if I select the color as Red then how I can apply this to the current result

$categoryid = (int)$this->getRequest()->getParam('cid');
    $designid = $this->getRequest()->getParam('manufacturer');
    $sizeid = $this->getRequest()->getParam('size');
    $colorid = $this->getRequest()->getParam('color');
    $pricerange = $this->getRequest()->getParam('price');
   
    $layer = Mage::getSingleton("catalog/layer"); 
    $_category = Mage::getSingleton("catalog/category")->load($categoryid);
    $layer->setCurrentCategory($_category);
    $attributes = $layer->getFilterableAttributes();
    
    $attrs["design"]['label'] = __("Brands");
    $attributeCode = Mage::getStoreConfig('shopbybrand/general/attribute_code', $storeId);        
    $attrCode = $attributeCode ? $attributeCode : 'manufacturer';
    $attrs["design"]['code'] = $attrCode;
    $attrs["design"]['sort'] = 1;
    
    $attrs["color"]['label'] = __("Color");
    $attrs["color"]['code'] = __("color");
    $attrs["color"]['sort'] = 2;
    
    $attrs["size"]['label'] = __("Size");
    $attrs["size"]['code'] = __("size");
    $attrs["size"]['sort'] = 3;
    
    $attrs["price"]['label'] = __("Price");
    $attrs["price"]['code'] = __("price");
    $attrs["price"]['sort'] = 4;
    
    // print_r($attributes->getData());exit();
    $attributeCollection =array();
    
    $i=0;
    $attributeCollection = array();
    foreach ($attributes as $attribute) {
    if($attribute->getAttributeCode() == 'price') {
     $filterBlockName = 'catalog/layer_filter_price';
    }elseif($attribute->getBackendType() == 'decimal'){
     $filterBlockName = 'catalog/layer_filter_decimal';
    }else{
    $filterBlockName = 'catalog/layer_filter_attribute';
    }
    $result = Mage::app()->getLayout()->createBlock($filterBlockName)->setLayer($layer)->setAttributeModel($attribute)->init();
    $attributeCollection[$i]['Code'] = $attribute->getAttributeCode();
    $attributeCollection[$i]['Label'] = $attribute->getStoreLabel();
    $j=0;
    $attributeOptionCollection =array();
    foreach($result->getItems() as $option) {
    if($attribute->getAttributeCode()=='price'){
        $attrs["price"]['options'][$j]['label'] = strip_tags($option->getLabel());
        $attrs["price"]['options'][$j]['value'] = $option->getValue();
    }elseif($attribute->getAttributeCode()=='color'){
        $attrs["color"]['options'][$j]['label'] = $option->getLabel();
        $attrs["color"]['options'][$j]['value'] = $option->getValue();
    }elseif($attribute->getAttributeCode()=='size'){
        $attrs["size"]['options'][$j]['label'] = $option->getLabel();
        $attrs["size"]['options'][$j]['value'] = $option->getValue();
    }else{
        $attrs["design"]['options'][$j]['label'] = $option->getLabel();
        $attrs["design"]['options'][$j]['value'] = $option->getValue();
    }
    $j++;
    }
    //$attributeCollection[$i]['Options'] = $attributeOptionCollection;
    $i++;
    }
    header("Content-Type: application/json");
    print_r(json_encode($attrs));
    die;    

Update added in the answer

added the code snippet to show what I have achieved so far regarding this question
Source Link
Magebuddies
  • 147
  • 2
  • 13

Update

This is what I have achieved so far, it is filtering the attributes based on category but how I can filter this based on an attribute value like in case if I select the color as Red then how I can apply this to the current result

$categoryid = (int)$this->getRequest()->getParam('cid');
    $designid = $this->getRequest()->getParam('manufacturer');
    $sizeid = $this->getRequest()->getParam('size');
    $colorid = $this->getRequest()->getParam('color');
    $pricerange = $this->getRequest()->getParam('price');
   
    $layer = Mage::getSingleton("catalog/layer"); 
    $_category = Mage::getSingleton("catalog/category")->load($categoryid);
    $layer->setCurrentCategory($_category);
    $attributes = $layer->getFilterableAttributes();
    
    $attrs["design"]['label'] = __("Brands");
    $attributeCode = Mage::getStoreConfig('shopbybrand/general/attribute_code', $storeId);        
    $attrCode = $attributeCode ? $attributeCode : 'manufacturer';
    $attrs["design"]['code'] = $attrCode;
    $attrs["design"]['sort'] = 1;
    
    $attrs["color"]['label'] = __("Color");
    $attrs["color"]['code'] = __("color");
    $attrs["color"]['sort'] = 2;
    
    $attrs["size"]['label'] = __("Size");
    $attrs["size"]['code'] = __("size");
    $attrs["size"]['sort'] = 3;
    
    $attrs["price"]['label'] = __("Price");
    $attrs["price"]['code'] = __("price");
    $attrs["price"]['sort'] = 4;
    
    // print_r($attributes->getData());exit();
    $attributeCollection =array();
    
    $i=0;
    $attributeCollection = array();
    foreach ($attributes as $attribute) {
    if($attribute->getAttributeCode() == 'price') {
     $filterBlockName = 'catalog/layer_filter_price';
    }elseif($attribute->getBackendType() == 'decimal'){
     $filterBlockName = 'catalog/layer_filter_decimal';
    }else{
    $filterBlockName = 'catalog/layer_filter_attribute';
    }
    $result = Mage::app()->getLayout()->createBlock($filterBlockName)->setLayer($layer)->setAttributeModel($attribute)->init();
    $attributeCollection[$i]['Code'] = $attribute->getAttributeCode();
    $attributeCollection[$i]['Label'] = $attribute->getStoreLabel();
    $j=0;
    $attributeOptionCollection =array();
    foreach($result->getItems() as $option) {
    if($attribute->getAttributeCode()=='price'){
        $attrs["price"]['options'][$j]['label'] = strip_tags($option->getLabel());
        $attrs["price"]['options'][$j]['value'] = $option->getValue();
    }elseif($attribute->getAttributeCode()=='color'){
        $attrs["color"]['options'][$j]['label'] = $option->getLabel();
        $attrs["color"]['options'][$j]['value'] = $option->getValue();
    }elseif($attribute->getAttributeCode()=='size'){
        $attrs["size"]['options'][$j]['label'] = $option->getLabel();
        $attrs["size"]['options'][$j]['value'] = $option->getValue();
    }else{
        $attrs["design"]['options'][$j]['label'] = $option->getLabel();
        $attrs["design"]['options'][$j]['value'] = $option->getValue();
    }
    $j++;
    }
    //$attributeCollection[$i]['Options'] = $attributeOptionCollection;
    $i++;
    }
    header("Content-Type: application/json");
    print_r(json_encode($attrs));
    die;    

Update

This is what I have achieved so far, it is filtering the attributes based on category but how I can filter this based on an attribute value like in case if I select the color as Red then how I can apply this to the current result

$categoryid = (int)$this->getRequest()->getParam('cid');
    $designid = $this->getRequest()->getParam('manufacturer');
    $sizeid = $this->getRequest()->getParam('size');
    $colorid = $this->getRequest()->getParam('color');
    $pricerange = $this->getRequest()->getParam('price');
   
    $layer = Mage::getSingleton("catalog/layer"); 
    $_category = Mage::getSingleton("catalog/category")->load($categoryid);
    $layer->setCurrentCategory($_category);
    $attributes = $layer->getFilterableAttributes();
    
    $attrs["design"]['label'] = __("Brands");
    $attributeCode = Mage::getStoreConfig('shopbybrand/general/attribute_code', $storeId);        
    $attrCode = $attributeCode ? $attributeCode : 'manufacturer';
    $attrs["design"]['code'] = $attrCode;
    $attrs["design"]['sort'] = 1;
    
    $attrs["color"]['label'] = __("Color");
    $attrs["color"]['code'] = __("color");
    $attrs["color"]['sort'] = 2;
    
    $attrs["size"]['label'] = __("Size");
    $attrs["size"]['code'] = __("size");
    $attrs["size"]['sort'] = 3;
    
    $attrs["price"]['label'] = __("Price");
    $attrs["price"]['code'] = __("price");
    $attrs["price"]['sort'] = 4;
    
    // print_r($attributes->getData());exit();
    $attributeCollection =array();
    
    $i=0;
    $attributeCollection = array();
    foreach ($attributes as $attribute) {
    if($attribute->getAttributeCode() == 'price') {
     $filterBlockName = 'catalog/layer_filter_price';
    }elseif($attribute->getBackendType() == 'decimal'){
     $filterBlockName = 'catalog/layer_filter_decimal';
    }else{
    $filterBlockName = 'catalog/layer_filter_attribute';
    }
    $result = Mage::app()->getLayout()->createBlock($filterBlockName)->setLayer($layer)->setAttributeModel($attribute)->init();
    $attributeCollection[$i]['Code'] = $attribute->getAttributeCode();
    $attributeCollection[$i]['Label'] = $attribute->getStoreLabel();
    $j=0;
    $attributeOptionCollection =array();
    foreach($result->getItems() as $option) {
    if($attribute->getAttributeCode()=='price'){
        $attrs["price"]['options'][$j]['label'] = strip_tags($option->getLabel());
        $attrs["price"]['options'][$j]['value'] = $option->getValue();
    }elseif($attribute->getAttributeCode()=='color'){
        $attrs["color"]['options'][$j]['label'] = $option->getLabel();
        $attrs["color"]['options'][$j]['value'] = $option->getValue();
    }elseif($attribute->getAttributeCode()=='size'){
        $attrs["size"]['options'][$j]['label'] = $option->getLabel();
        $attrs["size"]['options'][$j]['value'] = $option->getValue();
    }else{
        $attrs["design"]['options'][$j]['label'] = $option->getLabel();
        $attrs["design"]['options'][$j]['value'] = $option->getValue();
    }
    $j++;
    }
    //$attributeCollection[$i]['Options'] = $attributeOptionCollection;
    $i++;
    }
    header("Content-Type: application/json");
    print_r(json_encode($attrs));
    die;    
Source Link
Magebuddies
  • 147
  • 2
  • 13
Loading