Sha256: 8162177273621b16e741c216ea60acc41e0d6680d36397666c5c7e3ec15592bf

Contents?: true

Size: 1.78 KB

Versions: 34

Compression:

Stored size: 1.78 KB

Contents

/* global accounting */
function ShippingTotalManager (input1) {
  this.input = input1
  this.shippingMethods = this.input.shippingMethods
  this.shipmentTotal = this.input.shipmentTotal
  this.orderTotal = this.input.orderTotal
  this.formatOptions = {
    symbol: this.shipmentTotal.data('currency'),
    decimal: this.shipmentTotal.attr('decimal-mark'),
    thousand: this.shipmentTotal.attr('thousands-separator'),
    precision: 2
  }
}

ShippingTotalManager.prototype.calculateShipmentTotal = function () {
  var checked = $(this.shippingMethods).filter(':checked')
  this.sum = 0
  $.each(checked, function (idx, shippingMethod) {
    this.sum += this.parseCurrencyToFloat($(shippingMethod).data('cost'))
  }.bind(this))
  return this.readjustSummarySection(this.parseCurrencyToFloat(this.orderTotal.html()), this.sum, this.parseCurrencyToFloat(this.shipmentTotal.html()))
}

ShippingTotalManager.prototype.parseCurrencyToFloat = function (input) {
  return accounting.unformat(input, this.formatOptions.decimal)
}

ShippingTotalManager.prototype.readjustSummarySection = function (orderTotal, newShipmentTotal, oldShipmentTotal) {
  var newOrderTotal = orderTotal + (newShipmentTotal - oldShipmentTotal)
  this.shipmentTotal.html(accounting.formatMoney(newShipmentTotal, this.formatOptions))
  return this.orderTotal.html(accounting.formatMoney(newOrderTotal, this.formatOptions))
}

ShippingTotalManager.prototype.bindEvent = function () {
  this.shippingMethods.change(function () {
    return this.calculateShipmentTotal()
  }.bind(this))
}

Spree.ready(function ($) {
  var input = {
    orderTotal: $('#summary-order-total'),
    shipmentTotal: $('[data-hook="shipping-total"]'),
    shippingMethods: $('input[data-behavior="shipping-method-selector"]')
  }
  return new ShippingTotalManager(input).bindEvent()
})

Version data entries

34 entries across 34 versions & 1 rubygems

Version Path
spree_frontend-4.0.9 app/assets/javascripts/spree/frontend/checkout/shipment.js
spree_frontend-4.0.8 app/assets/javascripts/spree/frontend/checkout/shipment.js
spree_frontend-3.7.14.1 app/assets/javascripts/spree/frontend/checkout/shipment.js
spree_frontend-4.0.7.1 app/assets/javascripts/spree/frontend/checkout/shipment.js
spree_frontend-4.0.7 app/assets/javascripts/spree/frontend/checkout/shipment.js
spree_frontend-3.7.14 app/assets/javascripts/spree/frontend/checkout/shipment.js
spree_frontend-4.0.6 app/assets/javascripts/spree/frontend/checkout/shipment.js
spree_frontend-3.7.13 app/assets/javascripts/spree/frontend/checkout/shipment.js
spree_frontend-4.0.5 app/assets/javascripts/spree/frontend/checkout/shipment.js
spree_frontend-3.7.12 app/assets/javascripts/spree/frontend/checkout/shipment.js
spree_frontend-4.0.4 app/assets/javascripts/spree/frontend/checkout/shipment.js
spree_frontend-3.7.11 app/assets/javascripts/spree/frontend/checkout/shipment.js
spree_frontend-3.7.10 app/assets/javascripts/spree/frontend/checkout/shipment.js
spree_frontend-4.0.3 app/assets/javascripts/spree/frontend/checkout/shipment.js
spree_frontend-3.7.9 app/assets/javascripts/spree/frontend/checkout/shipment.js
spree_frontend-4.0.2 app/assets/javascripts/spree/frontend/checkout/shipment.js
spree_frontend-3.7.8 app/assets/javascripts/spree/frontend/checkout/shipment.js
spree_frontend-4.0.1 app/assets/javascripts/spree/frontend/checkout/shipment.js
spree_frontend-3.7.7 app/assets/javascripts/spree/frontend/checkout/shipment.js
spree_frontend-4.0.0 app/assets/javascripts/spree/frontend/checkout/shipment.js