cancel
Showing results for 
Search instead for 
Did you mean: 

How to search the product by its attributes(location, available from, available to) in Magento 2?

How to search the product by its attributes(location, available from, available to) in Magento 2?

We have a search form in a banner. In the form, we have three tabs and each tab have input boxes like "what you want", "location", "from", "to". We have created this form to search the products based on the location and "from-to date".

The form works only when we search the products but it's not working while we look at the product by location and other things. Below is the code we are using:

 

<dl class="search-forms-tabs">
<dt class="item title active" data-role="collapsible">
<a class="switch" data-toggle="trigger" href="javascript&colon;void(0);" data-target="construction">Construction</a>
</dt>
<dd id="construction" class="item content active" data-role="content" >

<form method="GET" action="<?php echo $block->getUrl('catalogsearch/result/');?>">
<fieldset class="search-forms-fieldset" id="date-range-1">
<legend class="legend"><span><?= /* @escapeNotVerified */ __('Search Settings') ?></span></legend>

<div class="field region">
<label for="select" class="label"><span>Select</span></label>

<div class="control" id="conselect">
<input type="text" name="q" placeholder="<?= /* @escapeNotVerified */ __('What are you looking for?') ?>" />
<?php /*?><select name="looking" id="looking">
<option value="">Please select</option>
<option value="5">5</option>
<option value="10">10</option>
<option value="15">15</option>
<option value="20">20</option>
</select><?php */?>
</div>
</div>
<div class="field">
<label for="location" class="label"><span><?= /* @escapeNotVerified */ __('Location') ?></span></label>

<div class="control" id="conlocation">
<input type="text" name="location" placeholder="<?= /* @escapeNotVerified */ __('Location') ?>" />
</div>
</div>

<div class="field">
<label for="available_from" class="label"><span><?= /* @escapeNotVerified */ __('Available From') ?></span></label>

<div class="control" id="confrom">
<input type="text" name="available_from" placeholder="<?= /* @escapeNotVerified */ __('Available From') ?>" id="date-from-1" />
</div>
</div>
<div class="field">
<label for="available_to" class="label"><span><?= /* @escapeNotVerified */ __('Location') ?></span></label>

<div class="control" id="conto">
<input type="text" name="available_to" placeholder="<?= /* @escapeNotVerified */ __('Available To') ?>" id="date-to-1"/>
</div>
</div>

</fieldset>
<div class="actions-toolbar">
<div class="primary">
<button type="submit"
class="action search primary"
title="<?= $block->escapeHtml(__('Search')) ?>">
<span><?= /* @escapeNotVerified */ __('Search') ?></span>
</button>
</div>
</div>
</form>

Could anyone please look into this and help me?

Screenshot from 2019-07-16 17-23-18.png