0

I SAW LOT OF POSTS ON Stackoverflow & here also , I DIDN'T get SINGLE proper answer.

Hi dudes, I have Filter option when i goto other Category->Product listing page .

I want to make it like Sort Dropdown of magento by default.

I have custom attr. as Carat for golden shop . I set its value from backend ,like 14,15 etc.

I m fetching it properly in drop down.

What should be done if i want to filter products by Carat ?

Till now my code to fetch Custom attr. & show in DDList.

    <!--Modified Code 27 Oct-->
    <?php 
        $name='carat_dropdown';
        $attributeInfo = Mage::getResourceModel('eav/entity_attribute_collection')->setCodeFilter($name)->getFirstItem();
        $attributeId = $attributeInfo->getAttributeId();                                    
        $attribute = Mage::getModel('catalog/resource_eav_attribute')->load($attributeId);
        $attributeOptions = $attribute ->getSource()->getAllOptions(false); 
    ?>

    <div class="sort-by">
        <label><?php echo $this->__('Filter By') ?></label>
        <select name="filterByCaret" >
                <option value="" >Select</option>                         
            <?php
            foreach($attributeOptions as $single){
            ?>
                <option value="<?php echo $single['value']?>" >                         
                    <?php echo $single['label']?>
                </option>          
            <?php
            }                                   
            ?>
        </select>
    </div>        
    <!--//Modified Code 27 Oct-->

DDList = Drop Down List.

Even in simple way

. Hi see, i have custom field in backend for jewellery shop Caret Value .So in drop down i will have all values i enter from backend for Carat Value like 13,14 etc. So in front end i want to show DDList ,and if i select 14 , products with Carat value 14 will be filtered &shown Thanks for help.

  • First of all, what is a 'DDList' list? Second, you mean this like a layered navigation kind of filtering? It sounds like you just need to make this an anchor category and use default Magento functionality – Sander Mangel Oct 27 '14 at 11:40
  • @SanderMangel , DDList-> DropDownList – Pratik Oct 27 '14 at 11:40
  • @SanderMangel . Hi see, i have custom field in backend for jewellery shop Caret Value .So in drop down i will have all values i enter from backend for Carat Value like 13,14 etc. So in front end i want to show DDList ,and if i select 14 , products with Carat value 14 will be filtered &shown – Pratik Oct 27 '14 at 11:43
  • Ok but why not use the layered navigation? Make the caret value a filterable product attribute and have it show up in layered navigation? – Sander Mangel Oct 27 '14 at 11:43
  • @SanderMangel ok no problem, already i m fed up with magento . NO clear docs, Question asked is what is ABC , answers explain What is XYZ . PRETTY MESSY – Pratik Oct 27 '14 at 11:45
1

From the way you are discribing the functionality it sounds like you want layered navigation. In this case you should make an attribute for caret value and make it dropdown and filterable. Then set the category to anchor.

Below is some information about layered navigation

  • Thanks bro , cheers you made my day.I see lot of Confusion related to Majento coding. – Pratik Oct 27 '14 at 12:52
0
$collection = Mage::getResourceModel('catalog/product_collection');
$collection->addAttributeToFilter('carat', 'value');

Just edit value to be the value of the attribute you are interested in.

FYI, starting your question with a row of capitals and bold lettering doesn't overly encourage people to help you...

  • Now Where to add this line ? Which file shuld be edited ? what folder to open to open this file ?Will it work with view i have ? I have <form> and just besides Sort menu, there is filter menu .Will it work with phtml i made? Do i need to create any module ? Thanks – Pratik Oct 27 '14 at 11:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.