Refreshing Magento checkout step

Refreshing Magento checkout step

September 5, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Refreshing Magento checkout step

Refreshing Magento Checkout Step on Address Change

The Magento checkout process is designed to be fluid and efficient for customers. However, there are times when you might need to modify this flow for specific business requirements, such as refreshing the payment method step based on changes to the shipping address.

The Challenge: Refactoring JavaScript Integration

You’ve added functionality to the Payment Method step that requires refreshing every time a change is made to the shipping address. You understand that this data must first be saved before your backend can process it, so you’ve tried adding custom JavaScript after the shipping.save() function in the shipping.phtml file.

However, as you discovered, this approach doesn’t work because the checkout steps are dynamically loaded and rendered by Magento’s JavaScript framework. Your code is being executed in an asynchronous context that overrides the sequential flow managed by Magento.

Understanding Magento’s Checkout Flow

Before we dive into solutions, it’s important to understand how Magento handles the checkout process:

  1. Step Initialization: Each step (like Billing and Shipping) is initialized with a Magento_Checkout/js/step/step.js file.
  2. Dynamic Rendering: The steps are rendered dynamically using AJAX calls when the user moves between them.
  3. Asynchronous Execution: The JavaScript files for each step are executed asynchronously, meaning they don’t interfere with or wait for each other.

Refreshing a Step: A Practical Approach

To refresh the Payment Method step every time the shipping address changes, you’ll need to tap into Magento’s event system and use its built-in methods. Here’s a step-by-step guide:

  1. Trigger an Event: In your custom JavaScript file for the Shipping step (found in frontend/Magento/your_module/js), trigger a custom event every time the address is saved. You can use Magento’s own event system or create a custom one.
// In your shipping.js file

const saveButton = document.querySelector('#shipping-save-button');
saveButton.addEventListener('click', () => {
  // Assuming you have an addressSave function that actually saves the data
  this.addressSave();
  // Trigger a custom event when the address is saved
  const event = new CustomEvent('addressSaved', { detail: this.getAddressData() });
  window.dispatchEvent(event);
});
  1. Listen for the Event: In your Payment Method JavaScript file, listen for this custom event and refresh the step content.
// In your payment.js file

window.addEventListener('addressSaved', (event) => {
  // This is where you trigger a refresh of the Payment Method HTML content
  // You can use Magento's checkoutService to reload the step
  // const checkoutService = new Magento_Checkout/js/checkout-service();
  // checkoutService.loadStep('payment', true);
});
  1. Integrate with Magento Checkout Service: To fully integrate this with Magento, you’ll want to use the Magento_Checkout/js/checkout-service object to programmatically load the Payment Method step.
// In your payment.js file

const checkoutService = new Magento_Checkout/js/checkout-service();
window.addEventListener('addressSaved', (event) => {
  // Refresh the Payment Method HTML content
  checkoutService.loadStep('payment', true);
});

Best Practices for Custom Checkout Enhancements

  1. Use Magento’s Existing Events: Where possible, use Magento’s built-in events to trigger your custom logic. This ensures compatibility with future updates.

  2. Minimize Custom JavaScript: While adding custom JavaScript can be necessary, try to minimize it as much as possible. The less JavaScript you add, the smoother and more predictable the checkout process will be.

  3. Avoid Overriding Core Files: Instead of overriding core files like step.phtml, use Magento’s event system or plugin architecture to extend functionality. This ensures your changes don’t get overwritten during updates.

Final Thoughts

Refreshing a Magento checkout step based on dynamic data requires an understanding of how the JavaScript framework handles these processes. By tapping into Magento’s built-in events and using its service objects, you can achieve the desired behavior without breaking the core functionality.

Remember, Magento’s checkout process is designed with performance in mind. Any customizations should aim to maintain this efficiency while providing the necessary business logic.

For more advanced customizations like this, consider working with a dedicated Magento development agency that specializes in optimizing and extending the Magento platform. They can provide expert guidance on best practices and ensure your changes are compatible with future updates.

Happy coding!

Checkout Themes Admin Customers

Our network