},
getCartContent: function () {
+ if (this.getItemsNumbers() == 0) {
+ return '<div class="cart-empty">' + this.fluidbook.l10n.__('your cart is empty') + '</div>';
+ }
var $this = this;
var content = '<table class="cart-items">';
+ var totalht = 0;
+ var totalttc = 0;
$.each(this.items, function (ref, quantity) {
var item = $this.getItemData(ref);
+ var ht = item.price * quantity;
+ var ttc = ht * (1 + item.tax);
content += '<tr>';
content += '<td class="name">' + item.name + '</td>';
content += '<td class="quantity"><input name="' + ref + '" class="cartqty" type="number" min="0" max="100" value="' + quantity + '" step="1" /></td>';
content += '<td class="price_unit">' + $this.formatPrice(item.price, 'HT') + '</td>';
- content += '<td class="price_excluding_taxes">' + $this.formatPrice(item.price * quantity, 'HT') + '</td>';
- content += '<td class="price">' + $this.formatPrice((item.price * quantity) * (1 + item.tax), 'TTC') + '</td>';
- content += '<td class="delete"><a href="#" data-cart-delete="' + ref + '"></a></td>';
+ content += '<td class="price_excluding_taxes">' + $this.formatPrice(ht, 'HT') + '</td>';
+ content += '<td class="price">' + $this.formatPrice(ttc, 'TTC') + '</td>';
+ content += '<td class="delete"><a href="#" data-cart-delete="' + ref + '">' + getSpriteIcon('interface-close') + '</a></td>';
content += '</tr>';
+
+ totalht += ht;
+ totalttc += ttc;
});
+
+ var fpv = 0;
+ var fp = 'OFFERTS';
+
+ if (totalht <= 99) {
+ fpv = 8.3;
+ fp = $this.formatPrice(fpv, 'HT');
+ }
+ var htfp = totalht + fpv;
+ var totalttcfp = totalttc + (fpv * 1.2);
+ var tva = totalttcfp - htfp;
+
+ content += '</table>';
+ content += '<table class="cart-totals">';
+ content += '<tr><td>Total HT</td><td>' + $this.formatPrice(totalht, 'HT') + '</td></tr>';
+ content += '<tr><td>Frais de port</td><td>' + fp + '</td></tr>';
+ content += '<tr><td>TVA</td><td>' + $this.formatPrice(tva) + '</td></tr>';
+ content += '<tr><td colspan="2" class="hr"></td></tr>';
+ content += '<tr class="total"><td>Total TTC</td><td>' + $this.formatPrice(totalttcfp, 'TTC') + '</td></tr>';
content += '</table>';
return content;
},
- updateCart: function () {
+ updateCart: function (getQtyFromField) {
+ if (getQtyFromField == undefined) {
+ getQtyFromField = true;
+ }
var $this = this;
- $(".cartqty").each(function () {
- $this.setQuantity($(this).attr('name'), parseInt($(this).val()), 'set');
- });
+ if (getQtyFromField) {
+ $(".cartqty").each(function () {
+ $this.setQuantity($(this).attr('name'), parseInt($(this).val()), 'set');
+ });
+ }
+ $('[data-menu="cart"] .content').html(this.getCartContent());
+ $('input[type="number"]').inputNumber();
+ resize();
},
formatPrice: function (price, suffix) {
this.enabled = true;
this.instance = this.createInstance();
+ $(document).on('click', '[data-cart-delete]', function () {
+ $this.instance.removeFromCart($(this).data('cart-delete'));
+ $this.instance.updateCart(false);
+ return false;
+ });
+
$(document).on('click', '[data-cart-ref]', function () {
$this.instance.addToCart($(this).data('cart-ref'));
$this.fluidbook.tooltip.displayTooltip($this.fluidbook.l10n.__("the item has been added to your cart"));