- rand: documentation ( source)
<?php
class product {
public function getData($key){
return ['total' => rand(1,999)];
}
}
class Mage {
public static function getModel($name){
$class = __CLASS__;
return new $class;
}
public function load($id){
return new product;
}
}
class item {
public function getProductId(){
return rand(1, 999);
}
}
class order {
public function getAllItems(){
return [new item, new item, new item];
}
}
$order = new order;
$totalprofit = 0;
foreach($order->getAllItems() as $item):
$product = Mage::getModel('catalog/product')->load($item->getProductId());
$profit = $product->getData('profit');
$totalprofit += $profit['total'];
echo $profit['total'], "\n";
endforeach;
echo $totalprofit, "\n";
?>