2015-01-23 13:09:30 +00:00
|
|
|
|
2015-02-01 03:21:54 +00:00
|
|
|
Vn.Basket = new Class
|
2015-01-23 13:09:30 +00:00
|
|
|
({
|
|
|
|
Extends: Vn.Module
|
|
|
|
|
|
|
|
,orderId: null
|
|
|
|
|
|
|
|
,activate: function ()
|
2015-02-01 03:21:54 +00:00
|
|
|
{
|
2015-01-23 13:09:30 +00:00
|
|
|
// Connecting buttons events
|
|
|
|
|
2015-03-06 23:33:54 +00:00
|
|
|
this.$('go-catalog').addEventListener ('click', this.catalogClicked.bind (this));
|
|
|
|
this.$('checkout-button').addEventListener ('click', this.checkoutClicked.bind (this));
|
2015-02-01 03:21:54 +00:00
|
|
|
|
2015-01-23 13:09:30 +00:00
|
|
|
// Loading order
|
|
|
|
|
2015-03-06 23:33:54 +00:00
|
|
|
this.orderId = this.$('order-id');
|
2015-01-23 13:09:30 +00:00
|
|
|
|
|
|
|
if (!this.orderId.value)
|
|
|
|
{
|
|
|
|
var orderId = Vn.Cookie.getInt ('order');
|
|
|
|
|
|
|
|
if (!orderId)
|
|
|
|
{
|
|
|
|
var sql = 'INSERT INTO order_view (date_send) VALUES (CURDATE());'
|
|
|
|
+'SELECT LAST_INSERT_ID();';
|
|
|
|
this.conn.execQuery (sql, this.orderCreated.bind (this));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
this.orderId.value = orderId;
|
|
|
|
}
|
2015-02-01 03:21:54 +00:00
|
|
|
|
|
|
|
// Configuring columns
|
|
|
|
|
2015-03-06 23:33:54 +00:00
|
|
|
var amount = this.$('column-amount');
|
2015-02-01 03:21:54 +00:00
|
|
|
amount.on ('changed', this.amountChanged.bind (this));
|
|
|
|
amount.renderer = this.amountRender;
|
|
|
|
|
2015-03-06 23:33:54 +00:00
|
|
|
this.$('column-subtotal').renderer = this.subtotalRender.bind (this);
|
|
|
|
this.$('stems').renderer = this.stemsRender.bind (this);
|
|
|
|
this.$('order-total').func = this.subtotal;
|
2015-02-01 03:21:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
,catalogClicked: function ()
|
|
|
|
{
|
|
|
|
Vn.Cookie.set ('order', this.orderId.value);
|
|
|
|
this.hash.set ({'form': 'ecomerce/catalog'});
|
|
|
|
}
|
|
|
|
|
|
|
|
,checkoutClicked: function ()
|
|
|
|
{
|
|
|
|
this.hash.set ({
|
|
|
|
'form': 'ecomerce/checkout',
|
|
|
|
'order': this.orderId.value
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
,orderCreated: function (resultSet)
|
|
|
|
{
|
|
|
|
var insertOk = resultSet.fetchResult ();
|
|
|
|
var orderId = resultSet.fetchValue ();
|
2015-01-23 13:09:30 +00:00
|
|
|
|
2015-02-01 03:21:54 +00:00
|
|
|
if (insertOk && orderId)
|
|
|
|
{
|
|
|
|
this.orderId.value = orderId;
|
|
|
|
Vn.Cookie.set ('order', orderId);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
this.hash.set ({'form': 'ecomerce/orders'});
|
2015-01-23 13:09:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
,amountRender: function (renderer, form)
|
|
|
|
{
|
|
|
|
var amount = form.get ('amount');
|
|
|
|
var grouping = form.get ('grouping');
|
|
|
|
|
|
|
|
if (amount && grouping)
|
|
|
|
renderer.value = amount / grouping;
|
|
|
|
else
|
|
|
|
renderer.value = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
,amountChanged: function (renderer, row, newValue)
|
|
|
|
{
|
2015-03-06 23:33:54 +00:00
|
|
|
var model = this.$('order-rows');
|
2015-01-23 13:09:30 +00:00
|
|
|
model.set (row, 'amount', newValue * model.get (row, 'grouping'));
|
|
|
|
}
|
|
|
|
|
|
|
|
,stemsRender: function (renderer, form)
|
|
|
|
{
|
|
|
|
if (form.get ('amount') > form.get ('available'))
|
|
|
|
renderer.td.className = 'available-exceeded';
|
|
|
|
else
|
|
|
|
renderer.td.className = '';
|
|
|
|
}
|
|
|
|
|
|
|
|
,subtotalRender: function (renderer, form)
|
|
|
|
{
|
|
|
|
renderer.value = this.subtotal (form);
|
|
|
|
}
|
|
|
|
|
|
|
|
,subtotal: function (form)
|
|
|
|
{
|
|
|
|
return form.get ('amount') * form.get ('price')
|
|
|
|
* ((100 - form.get ('discount')) / 100);
|
|
|
|
}
|
|
|
|
|
|
|
|
,availableRender: function (renderer, form)
|
|
|
|
{
|
|
|
|
if (form.get ('amount') > form.get ('avail'))
|
|
|
|
renderer.value = 'unavailable';
|
|
|
|
else
|
|
|
|
renderer.value = 'invisible';
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|