<?php
include("../include/config.php");
include("include/functions-phoncart.php");
if(SITE_URL==MAINSITE_URL){
	  $apibaseurl='https://ormwebapi.quicklly.com/';
	} else if(SITE_URL==UATSITE_URL){
		 $apibaseurl='https://uatrestapi.goquicklly.com/';
	}else {
		 $apibaseurl='https://devrestapi.goquicklly.com/';
	}
session_start();
if (isset($_REQUEST['postalcode'])) {
    $zip =$_REQUEST['postalcode'];
} else {
    $zip = '60610';
}

 $url = '';

$q = $_REQUEST['q'];
if($_REQUEST['value_user_id']!=''){
	$uid=$_REQUEST['value_user_id'];
} else {
	$uid=0;
}
$token=$_REQUEST['apitokensearch'];
$page=$_REQUEST['start'];
if($_REQUEST['searchid']){
	$searchid=$_REQUEST['searchid'];
} else {
	$searchid=0;
}
$filtercount=0;
$filtercount2=0;
$filtercount3=false;
if($_REQUEST["filterstore"]){
	$filtercount++;
	$filtercount3=true;
	
} 
if($_REQUEST["filterdiscount"]){
	$filtercount++;
	$filtercount2++;
	
} 
if($_REQUEST["filtercategory"]==''){
$_REQUEST["filtercategory"]='1,3';	
}
if($_REQUEST["filtercategory"]){
$filtercount++;	
$filtercount2++;
}   
$result = callAPI('POST', $apibaseurl."common/search-v2", array('zipcode' => $zip, 'query' => $q, 'uid' => $uid, 'searchID' => $searchid, 'filterCategoryIDs' => $_REQUEST["filtercategory"], 'filterStoreIDs' => $_REQUEST["filterstore"], 'filterDiscountIDs' => $_REQUEST["filterdiscount"], 'sortby' => $_REQUEST["filtersortby"],'page' => $page ,'token'=>$token));
$number_of_rec = count($result->lstProds);
?>
<?php if ($number_of_rec > 0 && $page==0) { 
			$lstFilterStores=$result->lstFilterStores;
			$lstFilterStoresdefault=$result->lstFilterStores;
			$lstCategory=$result->lstCategory;
			if($searchid==0){
              setcookie('lstCategory', $lstCategory, time() + (86400 * 30 * 12), "/"); // 86400 = 1 day
			  setcookie('lstFilterStores', $lstFilterStores, time() + (86400 * 30 * 12), "/"); // 86400 = 1 day
			  if($filtercount3==false){
			  $_SESSION["lstFilterStoresdefault"] = $lstFilterStoresdefault;
			  }
			 
			} else {
				if($filtercount2>=0){
					setcookie('lstFilterStores', $lstFilterStores, time() + (86400 * 30 * 12), "/"); // 86400 = 1 day
				}
			}
		
			
			setcookie('searchid', $result->searchID, time() + (86400 * 30 * 12), "/"); // 86400 = 1 day
} ?>
<?php if ($number_of_rec == 0){echo trim('false');} else {
	  foreach ($result->lstProds as $resultProduct) {
            $sectionid=$resultProduct->section_id;
			$sectionslug=$resultProduct->section_url;
			
			if($sectionid==1){
$finalurl="grocery-store".'/' . buildURL($resultProduct->name).'/'.$resultProduct->pid;  
$section='grocery';									   
 } elseif($sectionid==3){
										 if ($url != '') {
										 $finalurl="order-food-online".'/' . $url.'/'.$resultProduct->store_slug;  
									   } else {
										   $finalurl="order-food-online".'/'.$resultProduct->store_slug;
									   } 
									   	
 }
  elseif($sectionid==4){
	
										 if ($url != '') {
										 $finalurl="indian-catering".'/' . $url.'/'.$resultProduct->store_slug;  
									   } else {
										   $finalurl="indian-catering".'/'.$resultProduct->store_slug;
									   }
									  
 }
   elseif($sectionid==5){
	
										$finalurl='indian-meal-kit-delivery';
										
 }
  elseif($sectionid==6){
	
										if ($url != '') {
										 $finalurl="indian-tiffin".'/' . $url.'/'.$resultProduct->store_slug;  
									   } else {
										   $finalurl="indian-tiffin".'/'.$resultProduct->store_slug;
									   }
									  
 }
 elseif($sectionid==7){
	
									$finalurl='indian-meal-kit-delivery';
									
 }
 elseif($sectionid==8){
	
										$finalurl=$sectionslug;
										
 }
 elseif($sectionid==9){
	
										$finalurl=$sectionslug;
										
 }
 elseif($sectionid==10){
	
										$finalurl=$sectionslug;
										
 }
 elseif($sectionid==11){
	
										$finalurl='indian-seasoning-kit';
										
 }
 elseif($sectionid==12){
	
$finalurl=$sectionslug;
$section='mealkit';
 }
 elseif($sectionid==13){
    
	$finalurl="liquor-store".'/'.buildURLAlcohol($resultProduct->name);
 }
 elseif($sectionid==14){
	
									$finalurl=$sectionslug;
									$section='mealkit';
 }
 elseif($sectionid==15){
	
										$finalurl=$sectionslug;
										$section='mealkit';
 }
 elseif($sectionid==16){
	
						 $finalurl=$sectionslug;	
$section='mealkit';						 
 }
 elseif($sectionid==17){
	
										$finalurl=$sectionslug;
										$section='mealkit';
 }
 elseif($sectionid==19){
	
										$finalurl=$sectionslug;
										$section='mealkit';
 }elseif($sectionid==20){
	
										$finalurl='indian-mangoes-online';
										$section='mealkit';
 }elseif($sectionid==21){
	
										$finalurl=$sectionslug;
										$section='mealkit';
 }  elseif($sectionid==22){
	
										$finalurl=$sectionslug;
										$section='mealkit';
 } elseif($sectionid==24){
	
										$finalurl= $sectionslug;
										$section='mealkit';
 }
	    if($resultProduct->section == "Grocery"){ ?>
						  <div class="clsProd">
                            <a  class="productwthsalsTag productwthsalsTag1 clicksavepath" data-sectionid="<?php echo $sectionid;?>" <?php if ($resultProduct->sid == 194) {?>href="indian-instant-pot-delivery" <?php } else {?>href="javascript:void(0)" <?php } ?> title="<?php echo $resultProduct->name; ?>" >
                                <?php if ($resultProduct->photo) { ?>
                                    <img src="https://www.quicklly.com/images/img-lazy.jpg" data-src="<?php echo stripcslashes($resultProduct->photo); ?>" id="img_<?php echo $resultProduct->pid; ?>" alt="<?php echo $resultProduct->name; ?>" class="clsProdImg lazyload">
                                <?php } else { ?>
                                    <img src="https://www.quicklly.com/images/img-lazy.jpg" data-src="https://www.quicklly.com/images/no-img.jpg" id="img_<?php echo $resultProduct->pid; ?>" alt="<?php echo $resultProduct->name; ?>" class="clsProdImg lazyload">
                                <?php } ?>
                                <span class="clsTitle"> <?php echo ucwords(strtolower($resultProduct->name)); ?> <?php echo stripslashes($resultProduct->size);?></span>
								
								<span class="clsTitle storemyicon" style="visibility:hidden;"><img src="images/img-lazy.jpg" data-src="images/mealkit-icon.svg"  alt="<?php echo ucwords(strtolower($resultProduct->store_name)); ?>" class="lazyload"/><?php echo ucwords(strtolower($storeresult->store_name));?></span>		
                            </a>
							<div class="restallsectioncat newtags">
							<span class="clsPrice"><img src="https://www.quicklly.com/images/img-lazy.jpg" data-src="https://www.quicklly.com/images/ggicon.svg" alt="<?php echo $resultProduct->store_name;?>" class="clsStoreImg lazyload"/><label>Grocery</label></span>
                                <img src="images/img-lazy.jpg" data-src="<?php echo $resultProduct->store_icon;?>" alt="<?php echo $resultProduct->store_name;?>" class="clsStoreImg lazyload"/>
							</div>
                            <div class="restallsectioncat actionbtn">
                                <?php
                                if ($resultProduct->in_stock == 1) {
                                   $tax_value = $resultProduct->tax;
                                    ?>
                                    <span class="clsPrice"><?php if ($resultProduct->cost < $resultProduct->mrp) { ?>
                                            <span style="text-decoration:line-through"><?php echo $website_currency_symbol .$resultProduct->mrp; ?></span>- <?php } echo $website_currency_symbol . $resultProduct->cost;?></span>
								                                 
                                    <a  <?php if($resultProduct->sid == 194) { ?>
                            href='indian-instant-pot-delivery'
                       <?php } else { ?> href="javascript:void(0)" onClick="addToCart(this);" <?php } ?> class="clsProdAdd"
                                       data-sid="<?php echo $resultProduct->sid ?>" data-sname="<?php echo $resultProduct->store_name;?>"  data-tax="<?php echo $tax_value; ?>" data-smin="<?php echo $resultProduct->mini_fee; ?>"
                           data-minorder="<?php echo $resultProduct->mini_amt; ?>" data-simg="<?php echo $resultProduct->store_icon;?>" data-pid="<?php echo $resultProduct->pid ?>"
                           data-name="<?php echo $resultProduct->name ?>" data-price="<?php echo $resultProduct->cost;?>" data-mrp="<?php echo $resultProduct->mrp;?>"
                           <?php if ($resultProduct->photo) { ?>
                               data-photo="<?php echo $resultProduct->photo; ?>"
                           <?php } else { ?>
                               data-photo="images/no-img.jpg"
                           <?php } ?>>Add</a>
								  <?php }  else {
                                       echo "<span class='clsPrice'>Out of stock</span>";
                                   }
                                   ?>
                            </div>
 </div>
				
	<?php } else if($resultProduct->section == "Food") { ?> 
					  <div class="clsProd">
                            <a  class="productwthsalsTag productwthsalsTag1 clicksavepath" data-sectionid="<?php echo $sectionid;?>" <?php if ($resultProduct->sid == 194) {?>href="indian-instant-pot-delivery" <?php } else {?>href="javascript:void(0)" <?php } ?> title="<?php echo $resultProduct->name; ?>" >
                                <?php if ($resultProduct->photo) { ?>
                                    <img src="images/img-lazy.jpg" data-src="<?php echo stripcslashes($resultProduct->photo); ?>" id="img_<?php echo $resultProduct->pid; ?>" alt="<?php echo $resultProduct->name; ?>" class="clsProdImg lazyload">
                                <?php } else { ?>
                                    <img src="images/img-lazy.jpg" data-src="images/no-img.jpg" id="img_<?php echo $resultProduct->pid; ?>" alt="<?php echo $resultProduct->name; ?>" class="clsProdImg lazyload">
                                <?php } ?>	
                                <span class="clsTitle"> <?php echo ucwords(strtolower($resultProduct->name)); ?> <?php echo stripslashes($resultProduct->size);?></span>
								
								<span class="clsTitle storemyicon" style="visibility:hidden;"><img src="images/img-lazy.jpg" data-src="images/mealkit-icon.svg"  alt="<?php echo ucwords(strtolower($resultProduct->store_name)); ?>" class="lazyload"/><?php echo ucwords(strtolower($storeresult->store_name));?></span>		
                            </a>
							<div class="restallsectioncat newtags">
							<span class="clsPrice"><img src="https://www.quicklly.com/images/img-lazy.jpg" data-src="https://www.quicklly.com/images/ggfood.svg" alt="<?php echo $resultProduct->store_name;?>" class="clsStoreImg lazyload"/><label>Restaurant</label></span>
							
                                <img src="images/img-lazy.jpg" data-src="<?php echo $resultProduct->store_icon;?>" alt="<?php echo $resultProduct->store_name;?>" class="clsStoreImg lazyload"/>							
							</div>
                            <div class="restallsectioncat actionbtn">
                                <?php
                                if ($resultProduct->in_stock == 1) {
                                   $tax_value = $resultProduct->tax;
                                    ?>  
                                    <span class="clsPrice"><?php if ($resultProduct->cost < $resultProduct->mrp) { ?>
                                            <span style="text-decoration:line-through"><?php echo $website_currency_symbol .$resultProduct->mrp; ?></span>- <?php } echo $website_currency_symbol . $resultProduct->cost;?></span> 
                                    <a  <?php if($resultProduct->sid == 194) { ?>
                            href='indian-instant-pot-delivery'
                       <?php } else { ?> href="javascript:void(0)" onClick="addToCart_Food(this);" <?php } ?> data-sectionid="<?php echo $sectionid;?>" class="clsProdAdd"
                                       data-sid="<?php echo $resultProduct->sid ?>" data-sname="<?php echo $resultProduct->store_name;?>"  data-tax="<?php echo $tax_value; ?>" data-smin="<?php echo $resultProduct->mini_fee; ?>"
                           data-minorder="<?php echo $resultProduct->mini_amt; ?>" data-simg="<?php echo $resultProduct->store_icon;?>" data-pid="<?php echo $resultProduct->pid ?>"
                           data-name="<?php echo $resultProduct->name ?>" data-price="<?php echo $resultProduct->cost;?>" data-mrp="<?php echo $resultProduct->mrp;?>"
                          <?php if ($resultProduct->photo) { ?>
                               data-photo="<?php echo $resultProduct->photo; ?>"
                           <?php } else { ?>
                               data-photo="images/no-img.jpg"
                           <?php } ?>>Add</a>
								  <?php }  else {
                                       echo "<span class='clsPrice'>Out of stock</span>";
                                   }
                                   ?>
                            </div>
 </div>
	<?php } else if($resultProduct->section == "Alcohol") { ?> 
					  <div class="clsProd">
                            <a  class="productwthsalsTag productwthsalsTag1 clicksavepath" data-sectionid="<?php echo $sectionid;?>" <?php if ($resultProduct->sid == 194) {?>href="indian-instant-pot-delivery" <?php } else {?> href="<?php echo $finalurl;?>" <?php } ?> title="<?php echo $resultProduct->name; ?>" >
                                <?php if ($resultProduct->photo) { ?>
                                    <img src="images/img-lazy.jpg" data-src="<?php echo stripcslashes($resultProduct->photo); ?>" id="img_<?php echo $resultProduct->pid; ?>" alt="<?php echo $resultProduct->name; ?>" class="clsProdImg lazyload">
                                <?php } else { ?>
                                    <img src="images/img-lazy.jpg" data-src="images/no-img.jpg" id="img_<?php echo $resultProduct->pid; ?>" alt="<?php echo $resultProduct->name; ?>" class="clsProdImg lazyload">
                                <?php } ?>
								
									
								
								
                                <span class="clsTitle"> <?php echo ucwords(strtolower($resultProduct->name)); ?> <?php echo stripslashes($resultProduct->size);?></span>
								
								<span class="clsTitle storemyicon" style="visibility:hidden;"><img src="images/img-lazy.jpg" data-src="images/mealkit-icon.svg"  alt="<?php echo ucwords(strtolower($resultProduct->store_name)); ?>" class="lazyload"/><?php echo ucwords(strtolower($storeresult->store_name));?></span>	
								
                            </a>
							<div class="restallsectioncat newtags alcoholtag">
							<span class="clsPrice"><img src="images/img-lazy.jpg" data-src="images/ggalcohol.svg" alt="<?php echo $resultProduct->store_name;?>" class="clsStoreImg lazyload"/><label>Alcohol</label></span>
							
                                <img src="images/img-lazy.jpg" data-src="<?php echo $resultProduct->store_icon;?>" alt="<?php echo $resultProduct->store_name;?>" class="clsStoreImg lazyload"/>
							
							
							</div>
                            <div class="restallsectioncat actionbtn">
							

                                <?php
                                if ($resultProduct->in_stock == 1) {
                                   $tax_value = $resultProduct->tax;
                                    ?>
                                  
                                  
                                    <span class="clsPrice"></span>
									
                                  
                                    <a  <?php if($resultProduct->sid == 194) { ?>
                            href='indian-instant-pot-delivery'
                       <?php } else { ?> href="<?php echo $finalurl;?>"  <?php } ?> data-sectionid="<?php echo $sectionid;?>" class="clsProdAdd clicksavepath"
                                       data-sid="<?php echo $resultProduct->sid ?>" data-sname="<?php echo $resultProduct->store_name;?>"  data-tax="<?php echo $tax_value; ?>" data-smin="<?php echo $resultProduct->mini_fee; ?>"
                           data-minorder="<?php echo $resultProduct->mini_amt; ?>" data-simg="<?php echo $resultProduct->store_icon;?>" data-pid="<?php echo $resultProduct->pid ?>"
                           data-name="<?php echo $resultProduct->name ?>" data-price="<?php echo $resultProduct->cost;?>" 
                           <?php if (is_file("upload_images/product/thumb/" . $resultProduct->photo)) { ?>
                               data-photo="upload_images/product/thumb/<?php echo $resultProduct->photo; ?>"
                           <?php } else { ?>
                               data-photo="images/no-img.jpg"
                           <?php } ?>>View Store</a>
								  <?php }  else {
                                       echo "<span class='clsPrice'>Out of stock</span>";
                                   }
                                   ?>
                            </div>
	</div><?php } else {?> 
					  <div class="clsProd">
                            <a  class="productwthsalsTag productwthsalsTag1 clicksavepath" data-sectionid="<?php echo $sectionid;?>" <?php if ($resultProduct->sid == 194) {?>href="indian-instant-pot-delivery" <?php } else {?>href="<?php echo $finalurl;?>" <?php } ?> title="<?php echo $resultProduct->name; ?>" >
                                <?php if ($resultProduct->photo) { ?>
                                    <img src="images/img-lazy.jpg" data-src="<?php echo stripcslashes($resultProduct->photo); ?>" id="img_<?php echo $resultProduct->pid; ?>" alt="<?php echo $resultProduct->name; ?>" class="clsProdImg lazyload">
                                <?php } else { ?>
                                    <img src="images/img-lazy.jpg" data-src="images/no-img.jpg" id="img_<?php echo $resultProduct->pid; ?>" alt="<?php echo $resultProduct->name; ?>" class="clsProdImg lazyload">
                                <?php } ?>
								<?php $productname=$resultProduct->name.' '.$resultProduct->size;
								$string = strip_tags($productname);
                               if (strlen($string) > 85) {   
							       // truncate string
								   $stringCut = substr($string, 0, 85);
                                   $endPoint = strrpos($stringCut, ' ');

                                   //if the string doesn't contain any space then it will cut without word basis.
                                   $string = $endPoint? substr($stringCut, 0, $endPoint) : substr($stringCut, 0);
                                     $string .= '...';
                                } 
    
								?>
                                <span class="clsTitle"> <?php echo ucwords(strtolower($string)); ?></span>
								
								<span class="clsTitle storemyicon" style="visibility:hidden;"><img src="images/img-lazy.jpg" data-src="images/mealkit-icon.svg"  alt="<?php echo ucwords(strtolower($resultProduct->store_name)); ?>" class="lazyload"/><?php echo ucwords(strtolower($storeresult->store_name));?></span>	
								
                            </a>
							<div class="restallsectioncat newtags">
							<span class="clsPrice"><img src="images/img-lazy.jpg" data-src="images/ggmealkit.svg" alt="<?php echo $resultProduct->store_name;?>" class="clsStoreImg lazyload"/><label><?php if($resultProduct->section == "Moments"){?>Moments <?php } else {?>Meal Kit<?php } ?></label></span>
							
                                <img src="images/img-lazy.jpg" data-src="<?php echo $resultProduct->store_icon;?>" alt="<?php echo $resultProduct->store_name;?>" class="clsStoreImg lazyload"/>
							
							
							</div>
                            <div class="restallsectioncat actionbtn">
							

                                <?php
                                if ($resultProduct->in_stock == 1) {
                                   $tax_value = $resultProduct->tax;
                                    ?>
                                  
                                  
                                    <span class="clsPrice"></span>
									
                                  
                                    <a  <?php if($resultProduct->sid == 194) { ?>
                            href='indian-instant-pot-delivery'
                       <?php } else { ?> href="<?php echo $finalurl;?>" <?php } ?> data-sectionid="<?php echo $sectionid;?>" class="clsProdAdd clicksavepath"
                                       data-sid="<?php echo $resultProduct->sid ?>" data-sname="<?php echo $resultProduct->store_name;?>"  data-tax="<?php echo $tax_value; ?>" data-smin="<?php echo $resultProduct->mini_fee; ?>"
                           data-minorder="<?php echo $resultProduct->mini_amt; ?>" data-simg="<?php echo $resultProduct->store_icon;?>" data-pid="<?php echo $resultProduct->pid ?>"
                           data-name="<?php echo $resultProduct->name ?>" data-price="<?php echo $resultProduct->cost;?>" 
                           <?php if (is_file("upload_images/product/thumb/" . $resultProduct->photo)) { ?>
                               data-photo="upload_images/product/thumb/<?php echo $resultProduct->photo; ?>"
                           <?php } else { ?>
                               data-photo="images/no-img.jpg"
                           <?php } ?>>View Store</a>
								  <?php }  else {
                                       echo "<span class='clsPrice'>Out of stock</span>";
                                   }
                                   ?>
                            </div>
	</div> <?php } } } ?>
	<?php if ($number_of_rec > 0 && $page==0) { ?>	
	<input type="hidden" id="ttproductcount" value="<?php echo $result->totalProds;?>">
	<input type="hidden" id="ttsearchid" value="<?php echo $result->searchID;?>">
	 
	<?php 
if($searchid==0 && $filtercount==0){
if($lstCategory==''){
	 $lstCategory=$_COOKIE['lstCategory'];
}
?>
<?php if(count($lstCategory)>0){?>
<div id="sectionlisthtml" style="display:none;"> 
<ul class="tplink mainppp">                 
	               <li class="mainpp"><label><span>Category<img class="angledown" src="https://www.quicklly.com/images/angle-arrow-down.svg"></span></label></li>
                   <ul class="childfilter scrollablefilter listfilter">
				   				   
				    <?php foreach ($lstCategory as $resultcategory) { 
					if($resultcategory->name!='Mealkit'){
					?>
					 <li><label onclick="filtersearchdata(0,1,1)"><input type="checkbox" name="section[]" data-sectionid="<?php echo $resultcategory->key;?>" value="section<?php echo $resultcategory->key;?>" data-bname="<?php echo $resultcategory->name;?>"><span><?php echo $resultcategory->name;?></span></label></li>
					 <?php }
					}
					 ?>
				  
				   
				   
				  </ul>
  </ul>
</div>
<?php  } }
if($searchid==0 || $filtercount2>=0){
if($lstFilterStores==''){
	 $lstFilterStores=$_COOKIE['lstFilterStores'];
}
 if($filtercount2==0 && $filtercount3==true){
			 $lstFilterStores=$_SESSION["lstFilterStoresdefault"];
		 }

if(count($lstFilterStores)>0){?>
<div id="storelisthtml" style="display:none;">  
				   <ul class="tplink mainppp">                 
	               <li class="mainpp"><label><span>Store<img class="angledown" src="https://www.quicklly.com/images/angle-arrow-down.svg"></span></label></li>
                   <ul class="childfilter scrollablefilter listfilter">
				   				   <li><label onclick="filtersearchdata(0,1,1)"><span class="storeinput"><input type="checkbox" id="checkAll" name="stores[]" data-storeid="" value="store" data-bname="All Stores"></span><span>All Stores</span></label></li>
								    <?php foreach ($lstFilterStores as $resultstore) { ?>
				   				   				   				   <li><label onclick="filtersearchdata(0,1,1)"><span class="storeinput"><input type="checkbox" name="stores[]" data-storeid="<?php echo $resultstore->sid;?>" value="store<?php echo $resultstore->sid;?>" data-bname="<?php echo $resultstore->name;?>"></span><span><?php echo $resultstore->name;?></span></label></li>
																   
									<?php } ?>		   				  
				   				     </ul>
  </ul></div>
<?php } } ?> 
    <div class="clsTemplate">
        <div id="tempQty">
            <span class="clsQty searchQty">
                Qty:
                <select onChange="ddlQty_onChange(this);">
                    <option value="0">0</option>
                    <option value="1" selected>1</option>
                    <option value="2">2</option>
                    <option value="3">3</option>
                    <option value="4">4</option>
                    <option value="5">5</option>
                    <option value="6">6</option>
                    <option value="7">7</option>
                    <option value="8">8</option>
                    <option value="9">9</option>
                    <option value="10">10</option>
                    <option value="11">11</option>
                    <option value="12">12</option>
                    <option value="13">13</option>
                    <option value="14">14</option>
                    <option value="15">15</option>
                    <option value="16">16</option>
                    <option value="17">17</option>
                    <option value="18">18</option>
                    <option value="19">19</option>
                    <option value="20">20</option>
                </select>
            </span>
        </div>
    </div>
    <script type="text/javascript" src="js/phonecart.js" ></script>
	<?php } ?>