Created
March 13, 2020 14:28
-
-
Save dassimanuel000/e0a4e0eb7a4e89740e5fa783a6827af0 to your computer and use it in GitHub Desktop.
RECOVERED FROM RESULTS OF A LARAVEL RECHERCHE
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Hello I would like to recover products to bring them back to the invoice which are above the search without adding them to any database | |
Sorry if it's long but really I'm back to the wall | |
So I did some research on AJAX to retrieve values that vary using button and display them in the table. | |
L | |
THE REAL PROBLEM IS TO RECOVER THE NAME OF THE PRODUCT AFTER THE RESEARCH AND INSERT IT INTO THE INVOICE BUT SEEN I HAVE TRIED A FUNCTION THAT DISPLAYS THE RESULT IN JAVASCRIPT BUT SEEN THAT IT IS A VARIABLE IT WILL RECOVER ONLY THE FIRST RESULT | |
HERE IS THE RESEARCH IN QUESTION enter image description here | |
But the price and quantity must absolutely therefore these values will be inserted by the user in inputs | |
Like this | |
@extends('agence_A.agence_A') | |
@section('content') | |
<script src="{{asset('js/jquery.min.js')}}"></script> | |
<section class="content ecommerce-page"> | |
<div class="block-header"> | |
<div class="row"> | |
<div class="col-lg-7 col-md-6 col-sm-12"> | |
<h2>La Commande | |
<?php// echo 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; ?> | |
<small>Bienvenue sur Unity Construction</small> | |
</h2> | |
</div> | |
<div class="col-lg-5 col-md-6 col-sm-12"> | |
<ul class="breadcrumb float-md-right"> | |
<li class="breadcrumb-item"><a href=""><i class="zmdi zmdi-home"></i> Unity Construction</a></li> | |
<li class="breadcrumb-item active">La Commande</li> | |
</ul> | |
</div> | |
</div> | |
</div> | |
<div class="container-fluid"> | |
<div class="row clearfix"> | |
<div class="col-lg-12"> | |
<div class="card product_item"> | |
<div class="body"> | |
<table class="table-responsive table"> | |
<thead> | |
<tr> | |
<td>Unity Construction</td> | |
<td> </td> | |
<td> </td> | |
</tr> | |
<tr> | |
<td class="td_command">Nom client : <span class="span_command">{{ $client_agence_A->name_client }}</span></td> | |
<td>Fait le: <span class="span_command">{{ date('Y-m-d H:i:s') }}</span> </td> | |
</tr> | |
<tr> | |
<td>Entreprise client : <span class="span_command">{{ $client_agence_A->entreprise_client }}</span></td> | |
<td class="td_command">A :</td> | |
</tr> | |
</thead> | |
</table> | |
<table id="DataTable" class="table table-hover m-b-0"> | |
<thead> | |
<tr> | |
<th class="xs-small" data-breakpoints=" xs">N.</th> | |
<th>Designation</th> | |
<th>Prix Unitaire</th> | |
<th class="quantity-small-td" data-breakpoints="quantity-small-td">Commandé</th> | |
<th class="quantity-small-td" data-breakpoints="quantity-small-td">Livré</th> | |
<th class="quantity-small-td" data-breakpoints="quantity-small-td">Reste a Livrer</th> | |
<th data-breakpoints="cs">Total</th> | |
</tr> | |
</thead> | |
<tbody id="shopping_cart"> | |
<td>1</td> | |
<td id="name_product"></td> | |
<td><input type="number" name="prix_product_bill" placeholder="PRIX de vente du Produit" id="prix_product_bill"></td> | |
<td><input type="number" name="quantity_product_bill" placeholder="Quantite commande" id="quantity_product_bill"></td> | |
<td></td> | |
<td></td> | |
<td></td> | |
</tbody> | |
<tfoot> | |
<tr> | |
<td style="border: 1px solid dimgrey" colspan="5" align="right">Remise</td> | |
<td colspan="2"></td> | |
</tr> | |
<tr> | |
<td colspan="5" align="right"> Total</td> | |
<td id="total_facture" colspan="2"></td> | |
</tr> | |
</tfoot> | |
</table> | |
<div class="form-group"> | |
<br/> | |
<br/> | |
<button type="submit" class="btn btn-width btn-success"> | |
<i class="fa fa-btn fa-sign-in"></i>Envoyer la commande au magazinier | |
</button> | |
<a href="/agence_A"> | |
<button class="btn btn-danger"> | |
<i class="fa fa-btn fa-sign-in"></i>Cancel | |
</button> | |
</a> | |
</div> | |
<br/> | |
<br/> | |
<h2>Selectionner les articles</h2> | |
<br/> | |
<div class="form-group"> | |
<input type="text" class="form-control lonf" id="search" name="search" value="" placeholder="Search.."/> | |
</div> | |
<br/> | |
<br/> | |
<br/> | |
<br/> | |
<div class="container-fluid"> | |
<div class="row clearfix" id="tbody"> | |
</div> | |
</div> | |
<!--<script> | |
function insert_commande0() { | |
document.getElementById("name_product0").value = document.getElementById("title_product0").value; | |
} | |
function insert_commande1() { | |
document.getElementById("name_product1").value = document.getElementById("title_product1").value; | |
} | |
</script>--> | |
<script type="text/javascript"> | |
const search = document.getElementById('search'); | |
const tableBody = document.getElementById('tbody'); | |
function getContent(){ | |
const searchValue = search.value; | |
const xhr = new XMLHttpRequest(); | |
xhr.open('GET','{{route('search_client')}}/?search=' + searchValue ,true); | |
xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest'); | |
xhr.onreadystatechange = function() { | |
if(xhr.readyState == 4 && xhr.status == 200) | |
{ | |
tableBody.innerHTML = xhr.responseText; | |
} | |
} | |
xhr.send() | |
} | |
search.addEventListener('input',getContent); | |
</script> | |
<script type="text/javascript"> | |
function cart_add() { | |
//var product_id_var = document.getElementById('product_id'); | |
var product_id_var = $( "#product_id" ).val(); | |
alert(product_id_var); | |
} | |
</script> | |
<script> | |
$(document).ready(function(){ | |
$( "#add_to_cart" ).click(function() { | |
alert( "Handler for .click() called." ); | |
}); | |
}); | |
</script> | |
</div> | |
</div> | |
</div> | |
</div> | |
</div> | |
</section> | |
@endsection |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public function search_client(Request $request){ | |
//$client_agence_A = client_agence_A::findOrfail($id); | |
if($request->ajax()){ | |
$output=""; | |
$products = add_product::where('referent','LIKE','%'.$request->search."%") | |
->Orwhere('title','LIKE','%'.$request->search."%") | |
->Orwhere('description','LIKE','%'.$request->search."%") | |
->Orwhere('product_type','LIKE','%'.$request->search."%") | |
->Orwhere('category','LIKE','%'.$request->search."%") | |
->get(); | |
if($products){ | |
foreach ($products as $row) { | |
$i = 0; | |
$output.='<div class="col-lg-3 col-md-4 col-sm-12">'. | |
'<div class="card product_item">'. | |
'<div class="body">'. | |
'<div class="cp_img">'. | |
'<img class="img-fluid2 img-fluid" src="../uploads/stock_agence_A/'.$row->image.'">'. | |
'<div class="hover">'. | |
//<a href='/commande/{{ $client_agence_A->id }}?add=true'>Run PHP Function</a> | |
//'<input type="text" id="product_id" value="'.$row->id.'"/>'. | |
'<button class="btn btn-primary btn-sm waves-effect" name="add_to_cart_name" onclick="cart_add()" id="add_to_cart">'. | |
'<i class="zmdi zmdi-plus"></i>'. | |
'</button>'. | |
'<a href="javascript:void(0);" class="btn btn-danger btn-sm waves-effect"><i class="zmdi zmdi-shopping-cart"></i></a>'. | |
'</div>'. | |
'</div>'. | |
'<div class="product_details">'. | |
'<h5>'.'<input readonly class="input_commande" type="text" data-id="'.$row->id.'" value="'.$row->title.'"/></h5>'. | |
'<ul class="product_price list-unstyled">'. | |
'<li class="old_price">'.$row->price_min.' Fcfa</li>'. | |
'</ul>'. | |
'</div>'. | |
'</div>'. | |
'</div>'. | |
'</div>'; | |
$i++; | |
} | |
return $output; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment