Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

Custom Attribute Range in Advanced Search
 
clickcomkyle
Jr. Member
 
Total Posts:  28
Joined:  2008-08-07
 

I am trying get a range in the advanced search, similar to the price range feature. It seems to be possible but I can’t get it to work. Ive looked in /app/design/fontend/mytheme/../default/template/catalogsearch/advanced/form.phtml

I see

<?php switch($this->getAttributeInputType($_attribute)):
                case 
'number'?>
                
<div class="range field-row">
                    <
input name="<?php echo $_code ?>[from]" value="<?php echo $this->htmlEscape($this->getAttributeValue($_attribute, 'from')) ?>" id="<?php echo $_code ?>" title="<?php echo $this->htmlEscape($this->getAttributeLabel($_attribute)) ?>"  class="input-text validate-number" type="text" />
                    -
                    <
input name="<?php echo $_code ?>[to]" value="<?php echo $this->htmlEscape($this->getAttributeValue($_attribute, 'to')) ?>" id="<?php echo $_code ?>_to" title="<?php echo $this->htmlEscape($this->getAttributeLabel($_attribute)) ?>"  class="input-text validate-number" type="text" />
                </
div>
                
<?php break;
                case 
'price'?>
                
<div class="range field-row">
                    <
input name="<?php echo $_code ?>[from]" value="<?php echo $this->htmlEscape($this->getAttributeValue($_attribute, 'from')) ?>" id="<?php echo $_code ?>" title="<?php echo $this->htmlEscape($this->getAttributeLabel($_attribute)) ?>"  class="input-text validate-number" type="text" />
                    -
                    <
input name="<?php echo $_code ?>[to]" value="<?php echo $this->htmlEscape($this->getAttributeValue($_attribute, 'to')) ?>" id="<?php echo $_code ?>_to" title="<?php echo $this->htmlEscape($this->getAttributeLabel($_attribute)) ?>"  class="input-text validate-number" type="text" />

                    (
<?php echo $this->getCurrency($_attribute); ?>)
                
<?php break;
                case 
'select'?>
Which seems promising… But no matter what I do to my custom attribute I cannot get it’s AttributeInputType to be anything other than ‘string’. So I went to the eav_attribute table and changed the fields to match that of price, without the backend model and a few others. It seemed to work, it made the display to be a range with the [from] and [to] fields… But then searching doesnt work.

I don’t want to have to really modify this just to be able to search for a range.

I am using this for width height and depth fields that i have created, and obviously a straight text input field would not be very successful. Please help.

 
Magento Community Magento Community
Magento Community
Magento Community
 
Claudia Mattos
Jr. Member
 
Total Posts:  2
Joined:  2008-11-04
 

i have the same problem… the products have length and height and there is no way to search by a range.... i´ve tried many things, but nothing really works.
anyone can help?

 
Magento Community Magento Community
Magento Community
Magento Community
 
clickcomkyle
Jr. Member
 
Total Posts:  28
Joined:  2008-08-07
 

I got it functioning. You’ll have to modify the database because no matter what you do in the admin, it won’t work. Heres what I did to get it working:
1. create your attribute, and make sure you select ‘yes’ for advanced search.
2. find your new attribute in the eav_attribute table. Update it so the backend_type is ‘int’ and the frontend class is ‘validate-digits’
3. delete any values you’ve already set in the catalog_product_entity_decimal table (or any of the catalog_product_entity_[whatever] tables). If you leave values in there for your attributes, the admin will only update these values, and not where you want them (in the catalog_product_entity_int table)
4. once thats done. go add a value to one of your products and search for it using the advanced search…

the downside to using this method, is that if i use the admin to update my attribute, it will undo my changes, the ‘backend_type’ will get changed, so I’d have to go into the database to fix it. But it does work.

I have only tested this with integer values, i did not try getting it to work with decimal values, for I just wanted to search for a particular size in integer inches.

hope that helps anyone whos been struggling with it.

 
Magento Community Magento Community
Magento Community
Magento Community
 
timovski
Jr. Member
 
Avatar
Total Posts:  18
Joined:  2008-04-26
France
 

To avoid the type int or decimal change when you update, you must force the attribute to attribute system.
To do this, go to the database and find your attribute code in magento_eav_attribute table, edit like this for your attribute configuration:

is_user_defined = 0
is_visible = 1
fronted_input = text
backend_type = decimal or int
is_visible_in_advanced_search = 1

through is_user_defined = 0 it is ok to update.

wink
Good job !

 
Magento Community Magento Community
Magento Community
Magento Community
 
GeorgeV
Jr. Member
 
Total Posts:  4
Joined:  2007-12-20
 

I know this is an old thread, but you can copy the values from catalog_product_entity_varchar to catalog_product_entity_<<decimal or int>>, without loosing data using this query

INSERT into catalog_product_entity_<decimal or int> (`entity_type_id`, `attribute_id`, `store_id`, `entity_id`, `value`) select `entity_type_id`, `attribute_id`, `store_id`, `entity_id`, `valuefrom  catalog_product_entity_varchar WHERE `attribute_id`=<attribute id>
And then delete them using:
DELETE FROM catalog_product_entity_varchar WHERE attribute_id=<attribute_id>
 
Magento Community Magento Community
Magento Community
Magento Community
 
Amasty
Mentor
 
Avatar
Total Posts:  3988
Joined:  2009-11-10
 

Do you think the Search By Ranges and Categories extension will work for this situation?

 
Magento Community Magento Community
Magento Community
Magento Community
 
Claudia Mattos
Jr. Member
 
Total Posts:  2
Joined:  2008-11-04
 

would work if complatible to 1.4
=/

 
Magento Community Magento Community
Magento Community
Magento Community
 
Amasty
Mentor
 
Avatar
Total Posts:  3988
Joined:  2009-11-10
 

The extension is fully compatible only with 1.3.* versions

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top