dhruba Posted August 22, 2013 Posted August 22, 2013 Hi I got some strange problem need help. I have two template order and customer , order has customer FieldTypePage. When I want to retrieve the customer information ............... $orders = $pages->get('/orders/'); foreach($orders as $order){ $c = $order->customer; $cp = $pages->get($c); echo $c.'/'.$cp->title.'</br>'; } output................ 1042/Home 1043/Home but when I put $pages->get(1042); I got correct ans. Thanks............
adrian Posted August 22, 2013 Posted August 22, 2013 Depending on the setup of your customer field, you'll need either: $c = $quotation->customer->first()->title; or just $c = $quotation->customer->title;
dhruba Posted August 22, 2013 Author Posted August 22, 2013 This also doesn't work.................. $c = $order->customer; echo $c.', '.$c->title.', '.gettype($c->title).', '.gettype($c); output.............. 1024, , NULL, Object may be this is a bug;
adrian Posted August 22, 2013 Posted August 22, 2013 I am not sure on your page structure, but looking at your code in more detail, do you need to do something like: $orders = $pages->get('/orders/')->children(); or if this code is in the orders page template, then you could just do: $orders = $page->children(); At the moment your ->get will only return one page - the orders parent. Also, did you try the ->first()->title option? 1
dhruba Posted August 22, 2013 Author Posted August 22, 2013 ->first() This works but I don't Understand why. $orders = $page->children(); foreach($orders as $order){$c = $order->customer; //$c = $order->customer->first(); works $order->customer why return pagearray I have only one page linkd$cp = $pages->get($c);echo $cp->title.'</br>';}
adrian Posted August 22, 2013 Posted August 22, 2013 Because in the details tab of the customer field you must have it set to "Multiple Pages". Change it to a single option and you won't need first() anymore. You should only have it set to multiple if you want multiple customers assigned to each order. 1
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now