Jump to content

Recommended Posts

Posted

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............

Posted

Depending on the setup of your customer field, you'll need either:

$c = $quotation->customer->first()->title;

or just

$c = $quotation->customer->title;

Posted

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;

Posted

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?

  • Like 1
Posted

->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>';
}

Posted

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.

  • Like 1

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...