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 Section to a Custom Checkout Based on the Single Page Checkout Workflow (Example)

Agreements Section

As an illustration, we are going to add the Agreements section to acme_demo_checkout_single_page. Extend save_state and create_order with the customerConsents attribute field in order to display the section.

 1 workflows:
 2     acme_demo_checkout_single_page:
 3         transitions:
 4             # ...
 5             save_state:
 6                 # ...
 7                 form_options:
 8                     # ...
 9                     attribute_fields:
10                         # ...
11                         customerConsents:
12                             form_type: Oro\Bundle\ConsentBundle\Form\Type\ConsentAcceptanceType
13                             options:
14                                 required: true
15                                 property_path: customerConsents
16                         # ...
17             # ...
18             create_order:
19                 # ...
20                 form_options:
21                     # ...
22                     attribute_fields:
23                         # ...
24                         customerConsents:
25                             form_type: Oro\Bundle\ConsentBundle\Form\Type\ConsentAcceptanceType
26                             options:
27                                 required: true
28                                 property_path: customerConsents
29                        # ...

Next, add the transition definitions that save consents and check that all mandatory consents are accepted.

 1 workflows:
 2     acme_demo_checkout_single_page:
 3         transition_definitions:
 4             # ...
 5             save_state_definition:
 6                   # ...
 7                   - '@assign_value':
 8                       conditions:
 9                           '@not':
10                               - '@is_consents_accepted':
11                                   acceptedConsents: $customerConsents
12                       parameters: [$consents_available, true]
13
14                   - '@save_accepted_consents':
15                       acceptedConsents: $customerConsents
16                   # ...
17             # ...
18             create_order_transition_definition:
19                 # ...
20                 conditions:
21                     '@and':
22                         # ...
23                         - '@is_consents_accepted':
24                             acceptedConsents: $customerConsents
25                             message: oro.checkout.workflow.condition.required_consents_should_be_checked_on_single_page_checkout.message
26                             type: 'warning'
27                         # ...
28                 # ...
29                 actions:
30                     # ...
31                     - '@save_accepted_consents':
32                         acceptedConsents: $customerConsents
33                     # ...

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         -
     5             id: oro_consent_items
     6             namespace: checkout
     7             root: checkout_consent_container
     8     actions:
     9         # ...
    10         - '@add':
    11            id: checkout_consent_container
    12            blockType: container
    13            parentId: checkout_order_summary_totals_container
    14            siblingId: checkout_order_summary_totals_sticky_container
    15            prepend: true
    16
    17         - '@add':
    18            id: checkout_consent_message
    19            blockType: consent_acceptance_choice
    20            parentId: checkout_consent_container
    
  2. Customize the templates, as illustrated below.

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