This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.
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.
Is that what you're looking for? If not, please give more details exactly what you are calling and from where...
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.
You still don't explain precisely in which call (or partial?) you want to pass the client id.
Why do you want to add the client to the OrderItems if the parent Order already has the information?
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.
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)
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
I tried with storing my model in a Session.
public function setClientAttribute($value) { Session::put('session_client_id', $value); $this->client_id = $value; }
1-15 of 15