Checkout Emit Messages
Hyva Checkout emits a variety of Magewire messages during the checkout process. Custom Magewire components can listen to these checkout emit messages and re-render when specific checkout events occur. JavaScript listeners can also subscribe to these messages, as described in Listening to Messages in JavaScript.
Each checkout step emits both a general message and a more specific message depending on whether the customer is a guest or a logged-in customer. This lets components react to broad events (like any shipping address being saved) or narrow events (like a guest billing address being submitted).
Shipping Address Emit Messages
Hyva Checkout emits shipping address messages when a customer adds, submits, saves, or selects a shipping address. Each action emits a general message plus a guest-specific or customer-specific variant.
Shipping Address Added
The shipping_address_added messages fire when a new shipping address is first entered into the checkout form.
shipping_address_addedguest_shipping_address_addedcustomer_shipping_address_added
Shipping Address Submitted
The shipping_address_submitted messages fire when the customer submits the shipping address form for validation.
shipping_address_submittedguest_shipping_address_submittedcustomer_shipping_address_submitted
Shipping Address Saved
The shipping_address_saved messages fire after the shipping address has been successfully persisted to the quote.
shipping_address_savedguest_shipping_address_savedcustomer_shipping_address_saved
Shipping Address Selected
The shipping_address_activated message fires when a customer selects an existing shipping address from the address book.
shipping_address_activated
Billing Address Emit Messages
Hyva Checkout emits billing address messages using the same pattern as shipping address messages. Each billing address action emits a general message plus a guest-specific or customer-specific variant.
Billing Address Added
The billing_address_added messages fire when a new billing address is first entered into the checkout form.
billing_address_addedguest_billing_address_addedcustomer_billing_address_added
Billing Address Submitted
The billing_address_submitted messages fire when the customer submits the billing address form for validation.
billing_address_submittedguest_billing_address_submittedcustomer_billing_address_submitted
Billing Address Saved
The billing_address_saved messages fire after the billing address has been successfully persisted to the quote.
billing_address_savedguest_billing_address_savedcustomer_billing_address_saved
Billing Address Selected
The billing_address_activated message fires when a customer selects an existing billing address from the address book.
billing_address_activated
Coupon Code Emit Messages
Hyva Checkout emits coupon code messages when a customer applies or removes a coupon during checkout.
coupon_code_appliedfires when a coupon code is successfully applied to the cart.coupon_code_revokedfires when a previously applied coupon code is removed.
Payment Method Emit Messages
Hyva Checkout emits a payment method message when the customer chooses a payment option.
payment_method_selectedfires when the customer selects a payment method during checkout.
Shipping Method Emit Messages
Hyva Checkout emits a shipping method message when the customer picks a shipping option.
shipping_method_selectedfires when the customer selects a shipping method during checkout.
Updating Component Listeners with Plugins
Common use cases for modifying checkout component listeners include adding a listener for a new event, removing an existing listener, or changing the method that runs when a particular event fires. How you do it depends on the release line.
On Checkout 3.x, change the listeners of a component placement with the magewire:listeners block argument in layout XML. Each item name is an event name and its value is the component method to call:
- Add an item to add a listener.
- Give an existing event a different method to reassign it.
- Set an item to
xsi:type="null"to remove a listener, including one declared in the component's$listenersproperty or with an#[On]attribute.
The following example changes the listeners of the price summary totals component (Hyva\Checkout\Magewire\Checkout\PriceSummary, block price-summary.total-segments). It re-renders the component on a custom my_module_option_changed event and stops it from reacting to payment_method_selected.
<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<referenceBlock name="price-summary.total-segments">
<arguments>
<argument name="magewire:listeners" xsi:type="array">
<!-- Adding a new listener: re-render on the "my_module_option_changed" event -->
<item name="my_module_option_changed" xsi:type="string">$refresh</item>
<!-- Removing a listener: stop reacting to the "payment_method_selected" event -->
<item name="payment_method_selected" xsi:type="null"/>
</argument>
</arguments>
</referenceBlock>
</body>
</page>
In your own components, declare listeners with the Magewirephp\Magewire\Attributes\On attribute on the method instead of the $listeners property:
use Magewirephp\Magewire\Attributes\On;
#[On('shipping_address_saved')]
public function onShippingAddressSaved(): void
{
// React to the event
}
Plugins on getListeners() (the Checkout 1.x approach) still apply to every component while the v1bc module is enabled. Magewire 3 declares getListeners() as protected, so Magento can't intercept it by itself, and v1bc calls the plugins instead. Without v1bc, these plugins don't run.
Every Magewire component in Hyva Checkout can define event listeners using the $listeners property, provided by the Magewire Event trait. The Event trait also exposes a getListeners() method, which makes it straightforward to customize a component's listeners using the Magento plugin system.
Customizing a Magewire component's event listeners requires two steps: defining a plugin in etc/frontend/di.xml and implementing the listener modification logic in a plugin class.
Step 1: Register the plugin in etc/frontend/di.xml. The following example targets a hypothetical Hyva\Checkout\Magewire\Checkout\Foo component.
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<type name="Hyva\Checkout\Magewire\Checkout\Foo">
<plugin name="update_hyva_checkout_foo_component_listeners"
type="Vendor\Module\Plugin\UpdateFooListeners"/>
</type>
</config>
Step 2: Implement the plugin class with an afterGetListeners method. This after-plugin receives the current $listeners array and returns the modified version.
<?php
declare(strict_types=1);
namespace Vendor\Module\Plugin;
class UpdateFooListeners
{
public function afterGetListeners(
\Hyva\Checkout\Magewire\Checkout\Foo $subject,
array $listeners
): array {
// Adding a new listener: re-render on the "foo" event
$listeners['foo'] = 'refresh';
// Removing a listener: stop reacting to the "bar" event
unset($listeners['bar']);
// Updating a listener: call a different method for the "baz" event
$listeners['baz'] = 'someOtherFunction';
return $listeners;
}
}
Tip
When adding listeners for checkout emit messages, use the specific guest or customer variant (for example, guest_shipping_address_saved) if the component should only react for one customer type. Use the general variant (for example, shipping_address_saved) to react regardless of customer type.