4

Background

I am working on a module that replaces the shipping address, shipping method, and payment steps during checkout with an external iframe solution. This is basically a replacement for checkout, however I am trying to do it in a way that is minimalistic in what I rewrite (why re-invent the wheel for things I don't really need to re-invent?) When address information is updated in the iframe, a call-back POST hits a custom controller where I update the address and shipping method on the quote.

Question

  • Is there a way I can tell the frontend that it needs to refresh its copy of the data with what is actually in the database?

Things I've tried already

  • I have tried firing off the appropriate JS functions to set the billing/shipping address and shipping method on the quote. In fact, I am doing this now as it seemed to be the only way to get the shipping subtotal to populate. However, this has problems of its own:
    • Since I don't know the correct region_id, I either have to do custom AJAX calls to look it up or load some massive JS object to iterate over looking for the appropriate ID (I'm currently doing the AJAX thing as it seemed less intesive on the browser)
    • There are race conditions that occur that cause address changes to get overwritten by the previous address (not to mention all the extra DB traffic that is happening because of this)
    • Even though sales tax has been calculated correctly in the database, it is still not showing in the subtotals or grand total on the frontend (this is actually the real problem I am trying to solve here, however I feel the current setup I have is overly complicated and would be cleaner if Magento would just refresh its data from the database)
  • I have tried loadSection calls. But those seem to only update the mini-cart or the sidebar totals

Things I cannot change

  • I cannot change the callback POSTs (that is, I can't stop them from happening). They must occur in order for the iframe to get updated information from Magento (eg, sales tax, shipping rates, etc..)
  • For reasons I won't go into here, I need to reuse as much of the existing checkout as possible (see background section where I mentioned trying to be as minimalistic as possible)
  • I cannot change anything on the form inside the iframe (eg, I can't pass it region ids to include in the region/state dropdown). It is intentionally generic as it is used with other ecommerce platforms.

1 Answer 1

1

I believe I have solved this. Here is what I did:

I added Magento_Checkout/js/action/get-totals to the define section of my JS file. This allowed me to call getTotals([]) to get the sidebar to update after the callback posts occur (I happen to have JS events that fire letting me know the callbacks have been triggered)

After all this, I was able to remove all of my other JS updates to set billing/shipping addresses and shipping method as these were no longer needed.

6
  • I will wait a few days before accepting this answer in case someone provides a better way of doing this (though honestly I think this IS the way of doing it unless I want to endure the unending torture of interacting with all of the various JS calls required to operate checkout completely on the frontend) Sep 1, 2016 at 23:04
  • can you tell me how can I called getTotals([]) methods in select-payment-method.js file using overiding js file in extension.
    – user41152
    Nov 15, 2016 at 3:42
  • Can tell me how can I do this, because I have same problem.
    – user41152
    Nov 16, 2016 at 6:58
  • hi! where you added this js file ? Jan 24, 2017 at 10:13
  • 1
    Can you please how to update shipping also ? When i m updating cart by ajax it's adding shipping charge 0 to totals.
    – Magecode
    Aug 30, 2017 at 11:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.