Build Basket Session from $_POST["sku"] & $_POST["qty"] - centos8

I'm really struggling here so any help would be greatly appreciated.
I have a list of products on a page, each product has a form which posts two fields to a basket-controller.php
can somebody please show me how to create a session called basket-items with each post creating a separate sub array? I want to be able to work with the arrays via the sku value to then add other info from the db etc. thanks

figured it out
$_SESSION['basket'][$_POST['add-to-basket-sku']]['name'] = $_POST['add-to-basket-name'];
$_SESSION['basket'][$_POST['add-to-basket-sku']]['price'] = $_POST['add-to-basket-price'];
$_SESSION['basket'][$_POST['add-to-basket-sku']]['qty'] = $_POST['add-to-basket-qty'];

Related

Filter records based on groups [Odoo]

I am trying to filter the records based on their group id. I have written a domain filter in menu action like this
[('pending_approver','in',[g.id for g in user.groups_id])]
pending_approver is a Many2one field with res.groups
Have a look on this for more clarification.
def _default_approver(self):
obj = self.env['approval_heirarchy.approval_rules'].search([('id', '=', 1)], limit=1)
if obj.x_approver_ids:
val = obj.x_approver_ids[0].x_user_ids
return obj.x_approver_ids[0].x_user_ids.id
pending_approver = fields.Many2one('res.groups', string="Pending Approver", readonly=True,default=_default_approver)
Whenever run the application prompt an Odoo Client Error:
Uncaught Error: Expected "]", got "(name)"
I've searched a lot but didn't find any solution.
Any help will be a great regard for me. Thanks in Advance!
if self.user_has_groups('sales_team.group_sale_manager') is True:
code part...
this code may help you.....any queries please free to ask

How to Get a data from a table and insert another table in YII form

I am newbe in YII. Apologies for simple and stupid question.
I messed up my system. In that Case I need your help to clear the concept :: my question is :::
How to Get a data from a table and insert another table in YII form ::::
means---> I want to get data and view in form field --> how can I do that ??
please help me out
Generate a model using gii. It will do all what you need and hopefully you can get the code for that.
localhost:2010/index.php?r=gii
Use Above changing your host and port to see Gii.
You have to Enable Gii in the Config file before doing this
$modelA = ModelA:;model()->find('somecondition');
$modelB= new ModelB();
$modelB->attribute1 = $modelA->attribute1;
$modelB->attribute2 = $modelA->attribute2;
$modelB->attribute3 = $modelA->attribute3;
$modelB->attribute4 = $modelA->attribute4;
$modelB->attribute5 = $modelA->attribute5;
$modelB->save();
Try this..

Linq query results to List

I have the following....
Dim ProjectToDelete As Project2Host = dc.Project2Hosts.Single(Function(p) p.Host = tb_Host.Text)
dc.Projects2Hosts.DeleteOnSubmit(ProjectToDelete)
dc.SubmitChanges
This worked fine as there was only ever one Project associated to a Host.
The rules have now changed and there can be more than one Project per Host. I now need to create a List of ProjectsToDelete and populate that with a Linq query and then do a DeleteAllOnSubmit(ProjectsToDelete).
How do I create the list? I've beem trying .SelectMany but with no joy.
Any help appreciated.
How about:
For Each item in dc.Project2Hosts.Where(Function(p) p.Host = tb_Host.Text)
dc.Projects2Hosts.DeleteOnSubmit(item)
Next
dc.SubmitChanges()
OR:
dc.Project2Hosts.DeleteAllOnSubmit(dc.Project2Hosts.Where(Function(p) p.Host = tb_Host.Text))
dc.SubmitChanges()

Add data from one table to another in ruby on rails

In my current project, I have to get some data in a column of one table and put them to the 2nd table. The first table data have been saved as hash as follows:
---
- werweqr
- test
- B1
- B2
- B3
- xvxczv
I write the following code in the migration file to add the data from the first table to the 2nd table. But the data are not sending from the first to second.
#scenario_response = ScenarioResponse.where("selected_barriers != ?", "");
#scenario_response.each do |p|
p.selected_barriers.each do |barrier|
Settings.test = barrier
# SelectedBarriers.create(:scenario_response_id => p.id, :barrier => barrier)
end
end
Can anyone please let me know if there's something wrong in my code.
If so how to fix it?
Thanks a lot
I don't think you need to call "each" on p.selected_barriers.Try removing the each and doing this:
Settings.test=p.selected_barriers.
I'm new to RoR too..According to me,the scenario_response is a collection that returns all instances that have the selected_barriers as "". Since you are doing an each on the collection, you will just have one selected_barriers item for each of them.
Please try this and let me know if I'm wrong.
Also you are not doing update_attributes.
Try doing Settings.update_attributes(params[:test]) after Settings.test = barrier .

How do I use Linq-to-sql to iterate db records?

I asked on SO a few days ago what was the simplest quickest way to build a wrapper around a recently completed database. I took the advice and used sqlmetal to build linq classes around my database design.
Now I am having two problems. One, I don't know LINQ. And, two, I have been shocked to realize how hard it is to learn. I have a book on LINQ (Linq In Action by Manning) and it has helped some but at the end of the day it is going to take me a couple of weeks to get traction and I need to make some progress on my project today.
So, I am looking for some help getting started.
Click HERE To see my simple database schema.
Click HERE to see the vb class that was generated for the schema.
My needs are simple. I have a console app. The main table is the SupplyModel table. Most of the other tables are child tables of the SupplyModel table.
I want to iterate through each of Supply Model records. I want to grab the data for a supply model and then DoStuff with the data. And I also need to iterate through the child records, for each supply model, for example the NumberedInventories and DoStuff with that as well.
I need help doing this in VB rather than C# if possible. I am not looking for the whole solution...if you can supply a couple of code-snippets to get me on my way that would be great.
Thanks for your help.
EDIT
For the record I have already written the following code...
Dim _dataContext As DataContext = New DataContext(ConnectionStrings("SupplyModelDB").ConnectionString)
Dim SMs As Table(Of Data.SupplyModels) = _dataContext.GetTable(Of Data.SupplyModels)()
Dim query = From sm In SMs Where sm.SupplyModelID = 1 Select sm
This code is working...I have a query object and I can use ObjectDumper to enumerate and dump the data...but I still can't figure it out...because ObjectDumper uses reflection and other language constructs I don't get. It DOES enumerate both the parent and child data just like I want (when level=2).
PLEASE HELP...I'M stuck. Help!
Seth
in C# it would be:
var result = from s in _dataContent.SupplyModels where s.SupplyModelID==1 select s;
foreach(SupplyModel item in result)
{
// do stuff
foreach(SupplyModelChild child in item.SupplyModelChilds)
{
//do more stuff on the child
}
}
and a VB.NET version (from the Telerik code converter)
Dim result As var = From s In _dataContent.SupplyModels _
Where s.SupplyModelID = 1 _
Select s
For Each item As SupplyModel In result
' do stuff
'do more stuff on the child
For Each child As SupplyModelChild In item.SupplyModelChilds
Next
Next