most of #67
This commit is contained in:
parent
0e34c4c24f
commit
4b6fda5b4a
@ -1,23 +1,6 @@
|
||||
<?php
|
||||
|
||||
class Crunchbutton_Dish_Option extends Cana_Table {
|
||||
public function exports() {
|
||||
$out = $this->properties();
|
||||
|
||||
foreach ($this->prices() as $price) {
|
||||
$out['prices'][$price->id_dish_option_price] = $price->exports();
|
||||
}
|
||||
|
||||
return $out;
|
||||
}
|
||||
|
||||
public function prices() {
|
||||
if (!isset($this->_prices)) {
|
||||
$this->_prices = Dish_Option_Price::q('select * from dish_option_price where id_option="'.$this->id_option.'"');
|
||||
}
|
||||
return $this->_prices;
|
||||
}
|
||||
|
||||
public function __construct($id = null) {
|
||||
parent::__construct();
|
||||
$this
|
||||
|
||||
@ -1,11 +0,0 @@
|
||||
<?php
|
||||
|
||||
class Crunchbutton_Dish_Option_Price extends Cana_Table {
|
||||
public function __construct($id = null) {
|
||||
parent::__construct();
|
||||
$this
|
||||
->table('dish_option_price')
|
||||
->idVar('id_dish_option_price')
|
||||
->load($id);
|
||||
}
|
||||
}
|
||||
@ -4,9 +4,21 @@ class Crunchbutton_Option extends Cana_Table {
|
||||
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 __construct($id = null) {
|
||||
parent::__construct();
|
||||
$this
|
||||
|
||||
11
include/library/Crunchbutton/Option/Price.php
Normal file
11
include/library/Crunchbutton/Option/Price.php
Normal file
@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
class Crunchbutton_Option_Price extends Cana_Table {
|
||||
public function __construct($id = null) {
|
||||
parent::__construct();
|
||||
$this
|
||||
->table('option_price')
|
||||
->idVar('id_option_price')
|
||||
->load($id);
|
||||
}
|
||||
}
|
||||
@ -735,6 +735,19 @@ App.cart = {
|
||||
|
||||
$('.cart-summary-items').html(text.substr(0,text.length-13));
|
||||
|
||||
$('.cart-item-customize-price').each(function() {
|
||||
var dish = $(this).closest('.cart-item-customize').attr('data-id_cart_item'),
|
||||
option = $(this).closest('.cart-item-customize-item').attr('data-id_option'),
|
||||
cartitem = App.cart.items[dish],
|
||||
opt = App.cached['Option'][option],
|
||||
price = opt.optionPrice(cartitem.options);
|
||||
|
||||
$(this).html(App.cart.customizeItemPrice(price));
|
||||
});
|
||||
|
||||
},
|
||||
customizeItemPrice: function(price) {
|
||||
return price != '0.00' ? ' ($' + price + ')' : '';
|
||||
},
|
||||
customize: function(item) {
|
||||
var
|
||||
@ -755,6 +768,8 @@ App.cart = {
|
||||
continue;
|
||||
}
|
||||
if (opt[x].type == 'check') {
|
||||
|
||||
var price = opt[x].optionPrice(cartitem.options);
|
||||
var check = $('<input type="checkbox" class="cart-customize-check">');
|
||||
|
||||
if ($.inArray(opt[x].id_option, cartitem.options) !== -1) {
|
||||
@ -762,18 +777,16 @@ App.cart = {
|
||||
}
|
||||
var option = $('<div class="cart-item-customize-item" data-id_option="' + opt[x].id_option + '"></div>')
|
||||
.append(check)
|
||||
.append('<label class="cart-item-customize-name">' + opt[x].name + (opt[x].description || '') + '</label><label class="cart-item-customize-price">' + (opt[x].price != '0.00' ? ' ($' + opt[x].price + ')' : '') + '</label>');
|
||||
.append('<label class="cart-item-customize-name">' + opt[x].name + (opt[x].description || '') + '</label><label class="cart-item-customize-price">' + App.cart.customizeItemPrice(price) + '</label>');
|
||||
el.append(option);
|
||||
|
||||
} else if (opt[x].type == 'select') {
|
||||
|
||||
var select = $('<select class="cart-customize-select">');
|
||||
for (var i in opt) {
|
||||
|
||||
if (opt[i].id_option_parent == opt[x].id_option) {
|
||||
|
||||
|
||||
|
||||
|
||||
var option = $('<option value="' + opt[i].id_option + '">' + opt[i].name + (opt[i].description || '') + (opt[i].price != '0.00' || opt[x].price_linked == '1' ? (' ($' + (parseFloat(opt[i].price) + parseFloat(obj.price)).toFixed(2) + ')') : '') + '</option>');
|
||||
if ($.inArray(opt[i].id_option, cartitem.options) !== -1) {
|
||||
option.attr('selected','selected');
|
||||
@ -992,7 +1005,7 @@ App.cart = {
|
||||
options = App.cart.items[x].options;
|
||||
|
||||
for (var xx in options) {
|
||||
total += parseFloat(App.cached['Option'][options[xx]].price);
|
||||
total += parseFloat(App.cached['Option'][options[xx]].optionPrice(options));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -1,6 +1,18 @@
|
||||
var Option = function(id) {
|
||||
this.type = 'Option';
|
||||
var self = this;
|
||||
|
||||
self.optionPrice = function(options) {
|
||||
var price = parseFloat(self.price);
|
||||
|
||||
for (var x in self.prices) {
|
||||
if (options.indexOf(self.prices[x].id_option_parent) !== -1) {
|
||||
price += parseFloat(self.prices[x].price);
|
||||
}
|
||||
}
|
||||
|
||||
return price;
|
||||
}
|
||||
|
||||
if (typeof(id) == 'object') {
|
||||
for (x in id) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user