This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.

xyz.qtc63355
xyz.qtc63355

I'm building a system for making orders. Each order has more items. So I created Order Model with its form fields and an Order Items Model with its form fields. Everything works fine. Adding, removing order items etc.

The thing is this: Each order has e client field, and now when adding an order item, I need to pass that client for picking specific prices.

xyz.qtc63355
xyz.qtc63355

Anyone? Basically the question is how can I pass an Id to nested relation forms?

mjauvin
mjauvin

Is that what you're looking for? If not, please give more details exactly what you are calling and from where...

https://octobercms.com/docs/cms/partials#partial-variables

xyz.qtc63355
xyz.qtc63355

Hey mjauvin, thanks for the reply. Not exactly. What I need is this: I'm building a plugin for making orders with items.

So I have an Order Model in which I need to add Items (OrderItem Model) (A simple hasMany relation).

Each order has a field for a client. I need to pass the client to the items.

mjauvin
mjauvin

You still don't explain precisely in which call (or partial?) you want to pass the client id.

xyz.qtc63355
mjauvin
mjauvin

Why do you want to add the client to the OrderItems if the parent Order already has the information?

xyz.qtc63355
xyz.qtc63355

Well each OrderItem has a price. But some products have special prices for some clients and I need to check if there is a special price for the selected client.

That is my question how can I access parent Order client.

mjauvin
mjauvin

I would use the relationExtendManageWidget() method, see doc below:

https://octobercms.com/docs/backend/relations#extend-manage-widget

The 3rd parameter is the parent model (Order in your case)

xyz.qtc63355
xyz.qtc63355

I need to place this in my OrderItem model right?

mjauvin
mjauvin

No, in your Orders controller.

xyz.qtc63355
xyz.qtc63355

Thank you very much!!! It works like a charm.

I placed this in my OrderItem controller class. public function relationExtendManageWidget($widget, $field, $model) { $widget->model->client = $model->client; }

Now, I have only one more question about this. I had to "Create" (Save) the order before trying to pass the client attribute.

How do I catch this change?

Last updated

mjauvin
mjauvin

I don't know that you can until the model has been saved.

xyz.qtc63355
xyz.qtc63355

I tried with storing my model in a Session.

public function setClientAttribute($value) { Session::put('session_client_id', $value); $this->client_id = $value; }

mjauvin
mjauvin

Did it work saving it into the Session?

1-15 of 15

You cannot edit posts or make replies: the forum has moved to talk.octobercms.com.