I have following code
$products = Product::get()->filter(array("OwnerID" => $this->ParentID))->sort("Name");
And print_r($products->getIterator())
outputs following object
ArrayIterator Object
(
[storage:ArrayIterator:private] => Array
(
[0] => Product Object
(
[destroyed] =>
[model:protected] => DataModel Object
(
[customDataLists:protected] => Array
(
)
)
[record:protected] => Array
(
[ClassName] => Product
[LastEdited] => 2013-06-15 12:19:54
[Created] => 2013-05-07 03:55:23
[Code] => 2348934-SBC-AVL
[Number] => 2348934
[Name] => Sewing Machine
[Model] => SBC-AVL
[ID] => 259
[RecordClassName] => Product
)
)
)
)
Problem
I want to modify product
object of an object $products
while iterating through it. I tried it with following code
<?php
public function getProducts(){
// First return all products by this parent id
$products = Product::get()->filter(array("OwnerID" => $this->ParentID))->sort("Name");
if(!$products->count()) return false;
foreach($products->getIterator() as $product) {
$product->product_name="{$product->Name}";
$product->visible = true;
}
echo "<pre>".print_r($products,true)."</pre>"; exit;
return $products;
}
I wanted to add property product_name
and visible
to the product
object. But not working, if we print $products
it outputs original output.
Question
How to modify product
object in the iteration of $products
and add properties to it. I m expecting final output to be -
ArrayIterator Object
(
[storage:ArrayIterator:private] => Array
(
[0] => Product Object
(
[destroyed] =>
[model:protected] => DataModel Object
(
[customDataLists:protected] => Array
(
)
)
[record:protected] => Array
(
[ClassName] => Product
[LastEdited] => 2013-06-15 12:19:54
[Created] => 2013-05-07 03:55:23
[Code] => 2348934-SBC-AVL
[Number] => 2348934
[Name] => Sewing Machine
[Model] => SBC-AVL
[ID] => 259
[RecordClassName] => Product
[product_name] => Sewing Machine //<--- New property
[visible] => true //<--- New property
)
)
)
)