Chrome browsers sort the properties, but Firefox leaves them as defined. Changed the code to put the elements in an simple array (json array) instead of associative arrays (json objects) so that the elments are not reordered. * forces the export for the categories, dishes and options, to be added as a regular array of items, not as an associative array with the id as key * added dockblock to help the IDE with the return elements for the exports
56 lines
1.1 KiB
PHP
56 lines
1.1 KiB
PHP
<?php
|
|
|
|
class Crunchbutton_Option extends Cana_Table {
|
|
|
|
/**
|
|
* Returns the dish options with it's prices
|
|
*
|
|
* @see Cana_Table::exports()
|
|
*
|
|
* @return Crunchbutton_Option[]
|
|
*
|
|
* @todo Should the prices be stored ordered by id?
|
|
*/
|
|
public function exports() {
|
|
$out = $this->properties();
|
|
$out['price'] = number_format($out['price'],2);
|
|
$out['prices'] = [];
|
|
foreach ($this->prices() as $price) {
|
|
$out['prices'][$price->id_option_price] = $price->exports();
|
|
}
|
|
|
|
return $out;
|
|
}
|
|
|
|
public function prices() {
|
|
if (!isset($this->_prices)) {
|
|
$this->_prices = Option_Price::q('select * from option_price where id_option="'.$this->id_option.'"');
|
|
}
|
|
return $this->_prices;
|
|
}
|
|
|
|
public function optionPrice($options) {
|
|
return $this->price;
|
|
$price = $this->price;
|
|
return $price;
|
|
print_r($options);
|
|
print_r($price);
|
|
print_r($this->prices());
|
|
exit;
|
|
foreach ($this->prices() as $price) {
|
|
if (in_array($price->id_option_parent, $options)) {
|
|
$price += $price->price;
|
|
}
|
|
}
|
|
|
|
return $price;
|
|
}
|
|
|
|
public function __construct($id = null) {
|
|
parent::__construct();
|
|
$this
|
|
->table('option')
|
|
->idVar('id_option')
|
|
->load($id);
|
|
}
|
|
} |