title: IWD one page checkout extension Magento: review refresh
body: <p>I want to use the onepagecheckout (one step checkout) extension from IWD, and use it with the Cash On Delivery extension from Phoenix.</p>
  
  <p>I modified the code so it shows the Cash On Delivery Fee correctly, but it takes 3 loading times to correctly show the total costs in the review part. Is there a way to beautify this so it only shows "loading" once, and three times in the background (otherwise the fee won't show correctly)?</p>
  
  <p>This is what I did:</p>
  
  <p>I've added this to the template in /template/onepagecheckout/onepagecheckout.phtml:</p>
  
  <pre><code> &lt;script type="text/javascript" &gt;
  $j(function($) {
  $j('input[name*="payment[method]"]').live('click', function() {
  checkout.update2({
  'review': 1,
  'payment-method': 1
  });
  });
  $j('input[name*="shipping_method"]').live('click', function() {
  checkout.update({
  'review': 1
  ,'payment-method': 1
  });
  setTimeout(function(){
  checkout.update({
  'review': 1,
  });
  }, 500);
  });
  });
  &lt;/script&gt; 
  </code></pre>
  
  <p>So it loads the review, and payment section extra when another delivery method has been selected (I only use cash on delivery with one shipping method).</p>
  
  <p>In onepagecheckout.js I've added two pieces of code I've found on magentoproblems and on the magento-connect page of IWD</p>
  
  <p>Above </p>
  
  <pre><code> setResponse: function (response) { 
  </code></pre>
  
  <p>I've added</p>
  
  <pre><code>     update2: function (params) {
  if (this.loadWaiting != false) {
  return
  }
  if (this.s_code == '') return this.opcdis();
  var parameters = $(this.form).serialize(true);
  for (var i in params) {
  if (!params[i]) {
  continue
  }
  var obj = $('checkout-' + i + '-load');
  if (obj != null) {
  var size = obj.getDimensions();
  obj.setStyle({
  'width': size.width + 'px',
  'height': size.height + 'px'
  }).update('').addClassName('loading');
  parameters[i] = params[i]
  }
  }
  checkout.setLoadWaiting(true);
  var request = new Ajax.Request(this.updateUrl, {
  method: 'post',
  onSuccess: this.setResponse2.bind(this),
  onFailure: this.ajaxFailure.bind(this),
  parameters: parameters
  })
  },
  setResponse2: function (response) {
  response = response.responseText.evalJSON();
  if (response.redirect) {
  location.href = check_secure_url(response.redirect);
  return true
  }
  checkout.setLoadWaiting(false);
  if (response.order_created) {
  $('onepagecheckout_orderform').action = this.successUrl;
  $('opc_submit_form').click();
  return true
  } else if (response.error_messages) {
  var msg = response.error_messages;
  if (typeof (msg) == 'object') {
  msg = msg.join("\n")
  }
  alert(msg)
  }
  $('review-please-wait').hide();
  if (response.update_section) {
  for (var i in response.update_section) {
  ch_obj = $('checkout-' + i + '-load');
  if (ch_obj != null) {
  ch_obj.setStyle({
  'width': 'auto',
  'height': 'auto'
  }).update(response.update_section[i]).setOpacity(1).removeClassName('loading');
  if (i === 'shipping-method') {
  shippingMethod.addObservers()
  }
  }
  }
  }
  if (response.duplicateBillingInfo) {
  shipping.syncWithBilling()
  }
  if (!response.reload_totals) {
  checkout.update({
  'review': 1
  })
  }
  return false
  }, 
  </code></pre>
  
  <p>and I've replaced </p>
  
  <pre><code> this.currentMethod = method; // This code was here before
  </code></pre>
  
  <p>with</p>
  
  <pre><code>this.currentMethod = method; // This code was here before
  var shippingMethods = document.getElementsByName('shipping_method');
  if (shippingMethods.length != 0) {
  for (var i = 0; i &lt; shippingMethods.length; i++) {
  if (shippingMethods[i].checked) {
  checkout.update({'review': 1});
  }
  }
  } 
  </code></pre>
  
  <p>When the shipping method changes, the payment-section refreshes visibly twice, removes the Cash On delivery option (this is correct), and refreshes the review section three times, so the fee is either way added, or removed from the review/totals section.</p>
  
  <p>Thanks in advance</p>