Skip to content

Config step conditions

Can I join the Hyvä Checkout Beta?

Would you like to join the list of Beta participants?
Existing Hyvä customers and service integrators can contact us in Slack or email

Step conditions can be used in two ways:

  • In a <condition if="..."> attribute
  • In a <update if="..."> attribute

The value of the if attribute is either a step condition identifier or a condition class name.
If multiple <condition if="..."> nodes exist on a step, the step will only be shown if all conditions are true.

<step name="example-step">
    <!-- Only include the "update_handle" layout XML if the "is_physical" condition is true -->
    <update handle="example_handle" if="is_physical"/>

    <!-- Only show the "example-step" step if the "is_customer" condition is true -->
    <condition name="guest_login" if="is_customer"/>

Some common conditions are available out of the box:

  • is_always_allow
  • is_customer
  • is_guest
  • is_physical
  • is_virtual
  • is_device

Step condition identifiers

The condition identifiers exist for readability and are mapped to class names via etc/frontend/di.xml.
The default conditions are declared in vendor/hyva-themes/checkout-core/src/etc/frontend/di.xml.

<type name="Hyva\CheckoutCore\Model\CustomConditionFactory">
        <argument name="customConditionTypes" xsi:type="array">
            <item name="is_always_allow" xsi:type="string">Hyva\CheckoutCore\Model\CustomCondition\IsAlwaysAllow</item>
            <item name="is_customer" xsi:type="string">Hyva\CheckoutCore\Model\CustomCondition\IsCustomer</item>
            <item name="is_guest" xsi:type="string">Hyva\CheckoutCore\Model\CustomCondition\IsGuest</item>
            <item name="is_physical" xsi:type="string">Hyva\CheckoutCore\Model\CustomCondition\IsPhysical</item>
            <item name="is_virtual" xsi:type="string">Hyva\CheckoutCore\Model\CustomCondition\IsVirtual</item>
            <item name="is_device" xsi:type="string">Hyva\CheckoutCore\Model\CustomCondition\IsDevice</item>

Custom conditions can be added to the array using di.xml, but unless a condition will be reused a lot, it is better to use the class name directly as the value of the if attribute:

<step name="example-step">
    <update handle="example_handle" if="My\Module\Model\Checkout\StepCondition\ExampleStepCondition"/>
    <condition name="show_if_valid" if="My\Module\Model\Checkout\StepCondition\ExampleStepCondition"/>

Step condition classes

Condition classes have to implement the interface Hyva\CheckoutCore\Model\CustomConditionInterface.
The interface declares only a single method: public function validate(): bool

In the case of a <condition ...> node an accompanying attribute method can be specified to use a non-default validation method name.
This can be convenient to group variations of a condition within a single class to avoid code duplication.

<condition name="show_login" if="is_customer" method="required"/>

If no method is specified, the default method validate will be used.