Skip to content

Commit

Permalink
Renable auto scroll on applying discount code.
Browse files Browse the repository at this point in the history
  • Loading branch information
vidya-ram committed May 24, 2018
1 parent e68b3d7 commit d95d053
Showing 1 changed file with 43 additions and 45 deletions.
88 changes: 43 additions & 45 deletions boxoffice/templates/boxoffice.js
Original file line number Diff line number Diff line change
Expand Up @@ -322,55 +322,53 @@ $(function() {
},
preApplyDiscount: function(discount_coupons) {
//Ask server for the corresponding line_item for the discount coupon. Add one quantity of that line_item
if (boxoffice.ractive.get('order.line_items') > 0) {
$.post({
url: boxoffice.config.resources.kharcha.urlFor(),
crossDomain: true,
dataType: 'json',
headers: {'X-Requested-With': 'XMLHttpRequest'},
contentType: 'application/json',
data: JSON.stringify({
line_items: boxoffice.ractive.get('order.line_items').map(function(line_item) {
return {
quantity: 1,
item_id: line_item.item_id
};
}),
discount_coupons: discount_coupons
$.post({
url: boxoffice.config.resources.kharcha.urlFor(),
crossDomain: true,
dataType: 'json',
headers: {'X-Requested-With': 'XMLHttpRequest'},
contentType: 'application/json',
data: JSON.stringify({
line_items: boxoffice.ractive.get('order.line_items').map(function(line_item) {
return {
quantity: 1,
item_id: line_item.item_id
};
}),
timeout: 5000,
retries: 5,
retryInterval: 5000,
success: function(data) {
var discount_applicable = false;
var line_items = boxoffice.ractive.get('order.line_items');
line_items.forEach(function(line_item) {
if (data.line_items.hasOwnProperty(line_item.item_id)) {
if (data.line_items[line_item.item_id].discounted_amount && line_item.quantity_available > 0) {
discount_applicable = true;
line_item.unit_final_amount = data.line_items[line_item.item_id].final_amount;
line_item.discount_policies.forEach(function(discount_policy){
if (data.line_items[line_item.item_id].discount_policy_ids.indexOf(discount_policy.id) >= 0) {
discount_policy.pre_applied = true;
}
});
}
discount_coupons: discount_coupons
}),
timeout: 5000,
retries: 5,
retryInterval: 5000,
success: function(data) {
var discount_applicable = false;
var line_items = boxoffice.ractive.get('order.line_items');
line_items.forEach(function(line_item) {
if (data.line_items.hasOwnProperty(line_item.item_id)) {
if (data.line_items[line_item.item_id].discounted_amount && line_item.quantity_available > 0) {
discount_applicable = true;
line_item.unit_final_amount = data.line_items[line_item.item_id].final_amount;
line_item.discount_policies.forEach(function(discount_policy){
if (data.line_items[line_item.item_id].discount_policy_ids.indexOf(discount_policy.id) >= 0) {
discount_policy.pre_applied = true;
}
});
}
});

if (discount_applicable) {
boxoffice.ractive.set('order.line_items',line_items);
// Scroll to the top of the widget when a discount is pre-applied
boxoffice.ractive.scrollTop();
}
},
error: function(response) {
var ajaxLoad = this;
ajaxLoad.retries -= 1;
boxoffice.ractive.xhrRetry(ajaxLoad, response);
});

if (discount_applicable) {
boxoffice.ractive.set('order.line_items',line_items);
// Scroll to the top of the widget when a discount is pre-applied
boxoffice.ractive.scrollTop();
}
});
}
},
error: function(response) {
var ajaxLoad = this;
ajaxLoad.retries -= 1;
boxoffice.ractive.xhrRetry(ajaxLoad, response);
}
});
},
updateOrder: function(event, item_name, quantityAvailable, increment) {
// Increments or decrements a line item's quantity
Expand Down

0 comments on commit d95d053

Please sign in to comment.