Skip to content

Commit

Permalink
now handles discount on shipping + minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
iesus committed Oct 3, 2019
1 parent fcf9691 commit 2c9410e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
12 changes: 12 additions & 0 deletions app/code/community/Svea/Checkout/Model/Checkout/Api/BuildOrder.php
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,18 @@ protected function _addShipping($quote, $sveaOrder, $noSave)

$sveaOrder->addFee($shippingFee);

//Add shipping discount
if ((float)$shippingAddress->getShippingDiscountAmount()) {
if (!$vatPercent && ($shippingAddress->getShippingInclTax() != $shippingAddress->getShippingAmount())) {
$vatCalc = $shippingAddress->getShippingInclTax()/$shippingAddress->getShippingAmount();
}
$itemRowDiscount = WebPayItem::fixedDiscount()
->setName(mb_substr(sprintf('discount-%s', $methodTitle ), 0, 40))
->setVatPercent((int)round($vatPercent))
->setAmountIncVat((float)round($shippingAddress->getShippingDiscountAmount()*($vatCalc),2));
$sveaOrder->addDiscount($itemRowDiscount);
}

return $this;
}

Expand Down
13 changes: 10 additions & 3 deletions js/Svea/Checkout/sveacheckout.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,10 @@ SveaCheckout.prototype = {
that.updateCoupon(event);
}
}

if (el.name == 'shipping_method') {
that.updateShipping(event);
}
});

/**
Expand Down Expand Up @@ -370,7 +374,8 @@ SveaCheckout.prototype = {
* Remove loading state
*/
$('sveacheckout-wrapper').removeClassName('loading');
if (typeof window.scoApi !== 'Undefined') {

if (typeof window.scoApi !== 'undefined') {
window.scoApi.setCheckoutEnabled(true);
}
}.bind(this));
Expand Down Expand Up @@ -443,7 +448,7 @@ SveaCheckout.prototype = {
*/
document.addEventListener("startingAjaxFail", function (event) {
$('sveacheckout-wrapper').removeClassName('loading');
if (typeof window.scoApi !== 'Undefined') {
if (typeof window.scoApi !== 'undefined') {
window.scoApi.setCheckoutEnabled(true);
}
}.bind(this));
Expand Down Expand Up @@ -490,7 +495,9 @@ SveaCheckout.prototype = {
if (data.value !== oldValue) {
jQuery('#postcode').val(data.value);
var change = new CustomEvent('change');
document.getElementById('shipping-zip-form').dispatchEvent(change);
var shippingZipForm = document.getElementById('shipping-zip-form');
if (shippingZipForm != null)
document.getElementById('shipping-zip-form').dispatchEvent(change);
}
});
} else {
Expand Down

0 comments on commit 2c9410e

Please sign in to comment.