I want to display a list of ALL suppliers available in the order detail page in a select box and all suppliers available for that product in another select box.
What I tried to do is add to \prestashop\admin\themes\default\template\controllers\orders\helpers\view\view.tpl:
<div class="form-group">
<label for="id_supplier" class="control-label col-lg-3">{l s='Supplier'}</label>
<div class="col-lg-9">
<div class="col-lg-8">
<select id="id_supplier" name="id_supplier">
{foreach from=$suppliers item='supplier'}
<option value="{$supplier.id_supplier}">{$supplier.name}</option>
{/foreach}
</select>
</div>
</div>
</div>
But this doesn't work (the select box is empty).
there's no $supplier in controllers/admin/AdminOrdersController.php which means that you need to get informations about Suppliers by using this code:
$suppliers = Supplier::getSuppliers();
of course you need to foreach this loop and check which supplier is already in order and create another array for second select
after that you need to assign those variables in renderView method in controller
Related
when the user click add more and submit their form data, I'm having a problem saving form array like this (service[], Amount[], Description[]) in database rows. I have two related tables of invoices and invoice_details, i want the form array to submit the list of form data into the invoice_details table. I have successfully created the models and relations between the invoice and invoice_details.
<!--Blade -->
<div class="service-box">
<div class="row">
<div class="col-md-12 service-group">
<div class="row">
<div class="form-group mb-3 col-md-6">
<label class="form-label">Service</label>
<div >
<select type="text" class="form-select" placeholder="Services" value="" name="service[]" id="service">
<option value="" disabled selected>Select your option</option>
#foreach ($services as $service)
<option value="{{$service->service_name}}" data-id="{{$service->amount}}">{{$service->service_name}}</option>
#endforeach
</select>
</div>
</div>
<div class="form-group mb-3 col-md-6">
<label class="form-label">Amount</label>
<div >
<input type="text" class="form-control" name="amount[]" id="amount" placeholder="Amount" readonly>
</div>
</div>
<div class="form-group mb-3 col-md-12">
<label class="form-label">Description</label>
<textarea class="form-control" id="description" name="description[]" rows="6" placeholder="Description.." ></textarea>
</div>
</div>
</div>
</div>
</div>
//Controller
$invoicedetailModel = new Invoice_detail;
//Here is where the problem lies, I have to save for arrays.
$invoicedetailModel->service = request('service');
$invoicedetailModel->amount = request('amount');
$invoicedetailModel->description = request('description');
$invoiceModel->Invoice_details()->save($invoicedetailModel);
It seems to me (correct me if I'm misinterpreting) that you're trying to save a batch of different InvoiceDetails and attach them to an original Invoice model.
The problem here is that you're trying to do so by passing arrays to a single invoiceDetails model so let's suppose you have the you have two detail instances passed by form you would have the request parameters structured like this:
$request->service: ['serviceX','serviceY']
$request->amount: [1,2]
$request->description: ['Lorem', 'Ipsum']
So if you tried to create the model you're trying to save in your code you would be doing something like this:
Invoice_Details::create([
'service' => ['serviceX', 'serviceY'],
'amount' => [1,2]
'description' => ['Lorem', 'Ipsum']
]);
Which can not work because those values are not set as Json to the database, and also explains why the createMany is not working, because there's a single object that uses an array of values for each value. What you might want is a situation like this:
Invoice_Details::createMany([
[
'service' => 'serviceX',
'amount' => 1
'description' => 'Lorem'
],
[
'service' => 'serviceY',
'amount' => 2
'description' => 'Ipsum'
]
]);
So you should iterate the request parameters and save a whole array of single models rather than try to stuff everything into a single one.
Also, it's pretty legitimate to ask yourself "Sure, but they all have two parameters, why doesn't it just split them when I use the createMany method?" Well, let's suppose the same situation with different parameters:
$request->service: ['serviceX','serviceY']
$request->amount: [1,2]
$request->description: ['Ipsum']
To which model does that description belong to? We could just go by appearence order, but this kind of assumption might lead to huge problems in case of bad implementations. This sadly means that everytime we need to create multiple models we need to define every single one, even though it means adding an iteration beforehand.
TL;DR: Instead of an array of parameters you need an array of models. Iterate through your parameters and build your models before saving them.
//Supposing you already fetched the arrays and they are all of the same length
$details = [];
foreach($services as $key => $service) {
$invoicedetailModel = new Invoice_detail();
$invoicedetailModel->service = $services[$key];
$invoicedetailModel->amount = $amounts[$key];
$invoicedetailModel->description = $descriptions[$key]);
$details[] = $invoicedetailModel;
}
// code to create and attach the many models
Is it possible to order the form list by previously already selected values? these values are already selected when the page is loaded.
<div class="col-xs-12 col-sm-12 col-md-12">
<div class="form-group">
<strong>Role:</strong>
{!! Form::select('roles[]', $roles, $userRole, array('class' => 'form-control form','multiple')) !!}
</div>
</div>
Outputs my list with the values in a non ordered fashion.
It is not possible to order the list because it is essentially an select list with options, which makes it impossible to order automatically based in value.
Your select is populated with data from $roles variable, I think that you should have ordered your list in that variable before render the template.
I want to use a list element for drop-down select menu but it implemented everywhere with model. I use Spring I want the user to select items from a static list.
There are some use like
<form:select path="...." items=$(......)>
but it needs a model for items as I understood. Also I don't want to post anything I just need the value of the select menu and I will do everything with JS. How can I achieve this?
My List element:
private static String[] lang = {"en","fr","tr","es","de"};
I tried to use List like that but didn't work. I mean every form elements gone.
<form:form commandName="TranslateService">
<div class="form-group col-sm-6">
<label class="control-label" for="first-name">Target Languages<span class="required">*</span>
</label>
<div>
<form:select path="lang" items="${lang}"></form:select>
</div>
</div>
</form:form>
it's a hard way to solve your question. instead of this you can create a model for form.
Im trying to use this package " dannyvankooten/laravel-vat" to load a select menu with the countries and then validate the vat number inserted in the input type text.
So I have this in a form:
<div class="form-group font-size-sm">
<select class="form-control" name="country" id="country">
#foreach($countries as $country)
<option value="{{$country}}">{{$country}}</option>
#endforeach
</select>
</div>
<div class="form-group font-size-sm">
<label for="vat" class="text-gray">VAT</label>
<input type="text" id="vat" name="vat" class="form-control" value="">
</div>
In the RegistrationController I have in a method this to return the $countries to the view to the select menu:
$countries = Countries::all();
But it appears:
Non-static method DvK\Laravel\Vat\Countries::all() should not be called statically
Do you know why?
In your specific case (laravel & facades), it's because you have imported the wrong class in your controller.
You need to replace
use DvK\Laravel\Vat\Countries;
with
use DvK\Laravel\Vat\Facades\Countries;
like shown in the readme # https://github.com/dannyvankooten/laravel-vat
The facade is what provides the static accessor e.g. Countries::all()
all is not a static method in the Countries class. You should first create an instance of Countries and then call its all method:
$countries = new Countries();
$allCountries = $countries->all();
return view('congress.registration', ['countries' => $allCountries]);
I have the following HTML snippet:
<input type="text" id="manufacturer" list="manufacturers" placeholder="Search by manufacturer name or supplier code" class="form-control form-control-2-3" value="" name="manufacturer">
<datalist id="manufacturers">
<select>
<div>
<option value="Jaguar">AA</option>
<div></div>
</div>
<div>
<option value="Audi">AB</option>
<div></div>
</div>
<div>
<option value="Mercedes">AC</option>
<div></div>
</div>
</select>
</datalist>
It's a dropdown menu and I want to select one of the options. No matter what I try with any find command or select function. I always get the same error:
Selenium::WebDriver::Error::ElementNotVisibleError: element not visible: Element is not currently visible and may not be manipulated
Does anyone have any suggestions on how to scope to those options and select one?
Thanks.
What you're trying to do isn't currently possible because it's not actually a dropdown select element. The <datalist> option elements are never actually visible on the page because the standard states "In the rendering, the datalist element represents nothing and it, along with its children, should be hidden." - https://html.spec.whatwg.org/dev/form-elements.html#the-datalist-element . Instead any <option> elements in the datalist are just used as autofill suggestions for the input element (but don't actually restrict the value a user can input in any way). Because of this and since the datalist user can just type anything they want into the input element you can set the input value like any other text input.
fill_in("manufacturer", with: 'Jaguar')