parameters:
    oro_order.entity.order.class: Oro\Bundle\OrderBundle\Entity\Order
    oro_order.entity.order_address.class: Oro\Bundle\OrderBundle\Entity\OrderAddress
    oro_order.entity.order_line_item.class: Oro\Bundle\OrderBundle\Entity\OrderLineItem
    oro_order.entity.order_discount_item.class: Oro\Bundle\OrderBundle\Entity\OrderDiscount
    oro_payment.entity.payment_transaction.class: Oro\Bundle\PaymentBundle\Entity\PaymentTransaction
    oro_payment.entity.payment_status.class: Oro\Bundle\PaymentBundle\Entity\PaymentStatus

services:
    oro_order.order.manager.api:
        class: 'Oro\Bundle\SoapBundle\Entity\Manager\ApiEntityManager'
        parent: oro_soap.manager.entity_manager.abstract
        arguments:
            - '%oro_order.entity.order.class%'
            - '@doctrine.orm.entity_manager'

    oro_order.order.entity.id_generator:
        class: 'Oro\Bundle\OrderBundle\Doctrine\ORM\Id\SimpleEntityAwareGenerator'
        public: false

    oro_order.order.listener.orm.order_listener:
        class: 'Oro\Bundle\OrderBundle\EventListener\ORM\OrderListener'
        public: false
        arguments:
            - '@oro_order.order.entity.id_generator'
        tags:
            - { name: doctrine.orm.entity_listener, entity: '%oro_order.entity.order.class%', event: postPersist}

    oro_order.provider.shipping_cost_subtotal:
        class: 'Oro\Bundle\OrderBundle\Provider\ShippingCostSubtotalProvider'
        public: false
        arguments:
            - '@translator'
            - '@oro_currency.rounding.price_rounding_service'
            - '@oro_pricing.user_currency_manager'
        tags:
            - { name: oro_pricing.subtotal_provider, priority: 20 }

    oro_order.provider.discount_subtotal:
        class: 'Oro\Bundle\OrderBundle\Provider\DiscountSubtotalProvider'
        public: false
        arguments:
            - '@translator'
            - '@oro_currency.rounding.price_rounding_service'
            - '@oro_pricing.subtotal_processor.provider.subtotal_line_item'
            - '@oro_security.security_facade'
            - '@oro_pricing.user_currency_manager'
        tags:
            - { name: oro_pricing.subtotal_provider, priority: 10 }

    oro_order.order.provider.order_address:
        class: 'Oro\Bundle\OrderBundle\Provider\OrderAddressProvider'
        public: false
        arguments:
            - '@oro_security.security_facade'
            - '@doctrine'
            - '@oro_security.acl_helper'
            - '%oro_account.entity.account_address.class%'
            - '%oro_account.entity.account_user_address.class%'

    oro_order.order.provider.order_address_security:
        class: 'Oro\Bundle\OrderBundle\Provider\OrderAddressSecurityProvider'
        arguments:
            - '@oro_security.security_facade'
            - '@oro_order.order.provider.order_address'
            - '%oro_account.entity.account_address.class%'
            - '%oro_account.entity.account_user_address.class%'

    oro_order.manager.order_address:
        class: 'Oro\Bundle\OrderBundle\Manager\OrderAddressManager'
        public: false
        arguments:
            - '@oro_order.order.provider.order_address'
            - '@doctrine'
            - '%oro_order.entity.order_address.class%'
        calls:
            - [addEntity, ['a', '%oro_account.entity.account_address.class%']]
            - [addEntity, ['au', '%oro_account.entity.account_user_address.class%']]

    oro_order.request_handler.order_request_handler:
        class: 'Oro\Bundle\OrderBundle\RequestHandler\OrderRequestHandler'
        arguments:
            - '@doctrine'
            - '@request_stack'
            - '%oro_account.entity.account.class%'
            - '%oro_account.entity.account_user.class%'

    oro_order.request_handler.frontend_order_data_handler:
        class: 'Oro\Bundle\OrderBundle\RequestHandler\FrontendOrderDataHandler'
        arguments:
            - '@doctrine'
            - '@request_stack'
            - '@oro_security.security_facade'
            - '@oro_payment.provider.payment_term'

    oro_order.handler.order_currency_handler:
        class: 'Oro\Bundle\OrderBundle\Handler\OrderCurrencyHandler'
        arguments:
            - '@oro_locale.settings'

    oro_order.handler.order_totals_handler:
        class: 'Oro\Bundle\OrderBundle\Handler\OrderTotalsHandler'
        arguments:
            - '@oro_pricing.subtotal_processor.total_processor_provider'
            - '@oro_pricing.subtotal_processor.provider.subtotal_line_item'

    oro_order.event_listener.form_view:
        class: 'Oro\Bundle\OrderBundle\EventListener\FormViewListener'
        arguments:
            - '@translator'
            - '@oro_entity.doctrine_helper'
            - '@request_stack'
        tags:
            - { name: kernel.event_listener, event: oro_ui.scroll_data.before.account-user-view, method: onAccountUserView }
            - { name: kernel.event_listener, event: oro_ui.scroll_data.before.account-view, method: onAccountView }

    oro_order.event_listener.product_select_db_query:
        class: '%oro_product.event_listener.scoped_product_select_db_query.common_class%'
        parent: oro_product.event_listener.abstract_product_select_db_query
        calls:
            - [setScope, ['order']]
            - [setFrontendSystemConfigurationPath, ['oro_order.frontend_product_visibility']]
            - [setBackendSystemConfigurationPath, ['oro_order.backend_product_visibility']]
        tags:
            - { name: kernel.event_listener, event: oro_product.product_select.db.query, method: onDBQuery }

    oro_order.event_listener.order.total:
        class: 'Oro\Bundle\OrderBundle\EventListener\Order\OrderTotalEventListener'
        arguments:
            - '@oro_pricing.subtotal_processor.total_processor_provider'
        tags:
            - { name: kernel.event_listener, event: oro_order.order, method: onOrderEvent, priority: -255 }

    oro_order.event_listener.order.address:
        class: 'Oro\Bundle\OrderBundle\EventListener\Order\OrderAddressEventListener'
        arguments:
            - '@templating'
            - '@form.factory'
        tags:
            - { name: kernel.event_listener, event: oro_order.order, method: onOrderEvent }

    oro_order.event_listener.order.payment_term:
        class: 'Oro\Bundle\OrderBundle\EventListener\Order\OrderPaymentTermEventListener'
        arguments:
            - '@oro_payment.provider.payment_term'
        tags:
            - { name: kernel.event_listener, event: oro_order.order, method: onOrderEvent }

    oro_order.event_listener.order.matching_price:
        class: 'Oro\Bundle\OrderBundle\EventListener\Order\MatchingPriceEventListener'
        arguments:
            - '@oro_order.pricing.price_matcher'
        tags:
            - { name: kernel.event_listener, event: oro_order.order, method: onOrderEvent }

    oro_order.event_listener.order.tier_prices:
        class: 'Oro\Bundle\OrderBundle\EventListener\Order\TierPriceEventListener'
        arguments:
            - '@oro_pricing.provider.combined_product_price'
            - '@oro_pricing.model.price_list_tree_handler'
        tags:
            - { name: kernel.event_listener, event: oro_order.order, method: onOrderEvent }

    oro_order.event_listener.payment_shipping_surcharge:
        class: 'Oro\Bundle\PaymentBundle\EventListener\PaymentShippingSurchargeListener'
        arguments:
            - '@oro_order.provider.shipping_cost_subtotal'
        tags:
            - { name: kernel.event_listener, event: oro_payment.event.collect_surcharge, method: onCollectSurcharge }

# TODO: Uncomment and apply in BB-4834
#    oro_order.event_listener.payment_discount_surcharge:
#        class: 'Oro\Bundle\PaymentBundle\EventListener\PaymentDiscountSurchargeListener'
#        arguments:
#            - '@oro_order.provider.discount_subtotal'
#        tags:
#            - { name: kernel.event_listener, event: oro_payment.event.collect_surcharge, method: onCollectSurcharge }

    oro_order.twig.order:
        class: 'Oro\Bundle\OrderBundle\Twig\OrderExtension'
        public: false
        arguments:
            - '@oro_order.formatter.source_document'
        tags:
            - { name: twig.extension }

    oro_order.formatter.source_document:
        class: 'Oro\Bundle\OrderBundle\Formatter\SourceDocumentFormatter'
        public: false
        arguments:
            - '@oro_entity.entity_class_name_provider'

    oro_order.order.listener.total_calculate_listener:
        class: 'Oro\Bundle\OrderBundle\EventListener\TotalCalculateListener'
        arguments:
            - '@form.factory'
            - '@oro_action.helper.applications'
        tags:
            - { name: kernel.event_listener, event: oro_pricing.total_calculate_before_event, method: onBeforeTotalCalculate }

    oro_order.validator.checkout_address:
        class: 'Oro\Bundle\OrderBundle\Validator\Constraints\OrderAddressValidator'
        arguments:
            - '@validator'
        tags:
            - { name: validator.constraint_validator, alias: oro_order_address_validator }

    oro_order.pricing.price_matcher:
        class: 'Oro\Bundle\OrderBundle\Pricing\PriceMatcher'
        public: false
        arguments:
            - '@oro_pricing.provider.matching_price'
            - '@oro_pricing.model.price_list_tree_handler'

    oro_order.order.total.total_helper:
        class: 'Oro\Bundle\OrderBundle\Total\TotalHelper'
        public: false
        arguments:
            - '@oro_pricing.subtotal_processor.total_processor_provider'
            - '@oro_pricing.subtotal_processor.provider.subtotal_line_item'
            - '@oro_order.provider.discount_subtotal'

    oro_order.layout.provider.order_payment_status:
        class: 'Oro\Bundle\OrderBundle\Layout\DataProvider\OrderPaymentStatusProvider'
        arguments:
            - '@oro_payment.provider.payment_status'
        tags:
            - { name: layout.data_provider, alias: oro_order_frontend_payment_status_provider }

    oro_order.event_listener.order_datagrid:
        class: 'Oro\Bundle\OrderBundle\EventListener\OrderDatagridListener'
        arguments:
            - '@oro_entity.doctrine_helper'
            - '@oro_payment.formatter.payment_method_label'
        tags:
            - { name: kernel.event_listener, event: oro_datagrid.orm_datasource.result.after.orders-grid, method: onResultAfter }

    oro_order.event_listener.frontend_order_datagrid:
        class: 'Oro\Bundle\OrderBundle\EventListener\OrderDatagridListener'
        arguments:
            - '@oro_entity.doctrine_helper'
            - '@oro_payment.formatter.payment_method_label'
        tags:
            - { name: kernel.event_listener, event: oro_datagrid.orm_datasource.result.after.frontend-orders-grid, method: onResultAfter }

    oro_order.layout.provider.order_shipping_method:
        class: 'Oro\Bundle\OrderBundle\Layout\DataProvider\OrderShippingMethodProvider'
        arguments:
            - '@oro_shipping.formatter.shipping_method_label'
        tags:
            - { name: layout.data_provider, alias: oro_order_frontend_shipping_method_provider }

    oro_order.provider.privilege_category_provider:
        class: 'Oro\Bundle\OrderBundle\Provider\PrivilegeCategoryProvider'
        tags:
            - { name: oro_user.privilege_category}

    oro_order.layout.provider.top_selling_items:
        parent: oro_product.layout.data_provider.featured_products
        tags:
            - { name: layout.data_provider, alias: top_selling_items }

    oro_order.event_listener.extract_line_item_options:
        class: 'Oro\Bundle\OrderBundle\EventListener\ExtractLineItemPaymentOptionsListener'
        tags:
            - { name: kernel.event_listener, event: oro_payment.event.extract_line_item_options, method: onExtractLineItemPaymentOptions }

    oro_order.event_listener.extract_address_options.orderaddress:
        class: 'Oro\Bundle\OrderBundle\EventListener\ExtractAddressOptionsListener'
        tags:
            - { name: kernel.event_listener, event: oro_payment.event.extract_address_options.orderaddress, method: onExtractShippingAddressOptions }
