Important

You are browsing the documentation for version 4.1 of OroCommerce, OroCRM and OroPlatform, which is no longer maintained. Read version 5.1 (the latest LTS version) of the Oro documentation to get up-to-date information.

See our Release Process documentation for more information on the currently supported and upcoming releases.

Add the Agreements Step to a Custom Checkout Based on the Default Checkout Workflow (Example)

Add the Agreements step to the acme_demo_checkout workflow with the customer_consents name and the continue_to_billing_address allowed transition. For all other steps, add the verify_customer_consents allowed transition. verify_customer_consents helps to redirect to the customer_consents step if some consents were not accepted.

 1 workflows:
 2     acme_demo_checkout:
 3         steps:
 4             # ...
 5             customer_consents:
 6                 order: 20
 7                 allowed_transitions:
 8                     - continue_to_billing_address
 9             enter_billing_address:
10                 order: 30
11                 allowed_transitions:
12                     - verify_customer_consents
13                     # ...
14             enter_shipping_address:
15                 order: 40
16                 allowed_transitions:
17                     - verify_customer_consents
18                     # ...
19             # ...

Transitions

Next, add the continue_to_billing_address transition to the Agreements page and the verify_customer_consents transition that check that all mandatory consents are accepted. The stop_propagation option enables you to check the required consents before every step and transit the workflow to the customer_consents step.

 1 workflows:
 2     acme_demo_checkout:
 3         transitions:
 4             # ...
 5             continue_to_billing_address:
 6                 step_to: enter_billing_address
 7                 transition_definition: continue_to_billing_address_definition
 8                 display_type: page
 9                 frontend_options:
10                     is_checkout_continue: true
11                     is_checkout_show_errors: true
12                 form_options:
13                     attribute_fields:
14                         customerConsents:
15                             form_type: Oro\Bundle\ConsentBundle\Form\Type\ConsentAcceptanceType
16                             options:
17                                 mapped: false
18                                 required: true
19                                 property_path: customerConsents
20             # ...
21             verify_customer_consents:
22                 step_to: customer_consents
23                 transition_definition: verify_customer_consents_definition
24                 is_hidden: true
25                 frontend_options:
26                     stop_propagation: true
27             # ...

Transition Definitions

For the above transitions, add transition definitions that save consents and check that all required consents are accepted.

 1 orkflows:
 2    acme_demo_checkout:
 3        transition_definitions:
 4            # ...
 5            continue_to_billing_address_definition:
 6                preactions:
 7                    - '@assign_value': [$consents_available, true]
 8                actions:
 9                    - '@save_accepted_consents':
10                            acceptedConsents: $customerConsents
11            # ...
12            verify_customer_consents_definition:
13                preconditions:
14                    '@not':
15                        - '@is_consents_accepted':
16                            acceptedConsents: $customerConsents
17                preactions:
18                    - '@flash_message':
19                        conditions:
20                            '@and':
21                                - '@not':
22                                    - '@is_consents_accepted':
23                                        acceptedConsents: $customerConsents
24                                - '@equal': [$consents_available, true]
25                        message: oro.checkout.workflow.condition.required_consents_should_be_checked.message
26                        type: 'warning'
27            # ...

Template

To show a block with the consent items:

  1. Import a layout with the consent items and configure it.

 1 layout:
 2     imports:
 3         -
 4             id: oro_consent_items
 5             namespace: checkout
 6             root: checkout_consent_container
 7
 8     actions:
 9         - '@setBlockTheme':
10             themes: 'consents.html.twig'
11
12         - '@add':
13             id: checkout_consent_container
14             blockType: container
15             parentId: checkout_form
16             prepend: true
17
18         - '@add':
19             id: checkout_consent_message
20             blockType: consent_acceptance_choice
21             parentId: checkout_consent_container
  1. Customize the templates, as illustrated below.

 1{% block _checkout_form_fields_widget %}
 2    {% if form.customerConsents is defined %}{{ form_widget(form.customerConsents) }}{% endif %}
 3{% endblock %}
 4
 5{% block _checkout_consent_container_widget %}
 6    <div {{ block('block_attributes') }}>
 7        <div class="grid__column">
 8            {{ parent_block_widget(block) }}
 9        </div>
10    </div>
11{% endblock %}
12
13{% block _checkout_consent_message_widget %}
14    {% set attr = layout_attr_defaults(attr, {
15        'class': 'notification notification--success'
16    }) %}
17
18    {% if consents is empty %}
19        <div {{ block('block_attributes') }}>
20            <span class="notification__item">
21                <i class="fa-check"></i> {{ 'oro.consent.frontend.checkout.form.messages.all_agreements_accepted'|trans }}
22            </span>
23        </div>
24    {% endif %}
25{% endblock %}