sylius_admin_order:
    resource: |
        alias: sylius.order
        section: admin
        templates: "@SyliusAdmin\\Crud"
        only: ['index']
        grid: sylius_admin_order
        permission: true
        vars:
            all:
                subheader: sylius.ui.process_your_orders
            index:
                icon: cart
    type: sylius.resource

sylius_admin_order_show:
    path: /orders/{id}
    methods: [GET]
    defaults:
        _controller: sylius.controller.order::showAction
        _sylius:
            section: admin
            repository:
              method: findOrderById
              arguments:
                - '$id'
            permission: true
            template: "@SyliusAdmin/Order/show.html.twig"

sylius_admin_order_history:
    path: /orders/{id}/history
    methods: [GET]
    defaults:
        _controller: sylius.controller.order::showAction
        _sylius:
            section: admin
            repository:
              method: findOrderById
              arguments:
                - '$id'
            permission: true
            template: "@SyliusAdmin/Order/history.html.twig"

sylius_admin_order_update:
    path: /orders/{id}/edit
    methods: [GET, PUT]
    defaults:
        _controller: sylius.controller.order::updateAction
        _sylius:
            section: admin
            repository:
              method: findOrderById
              arguments:
                - '$id'
            permission: true
            template: "@SyliusAdmin/Order/update.html.twig"
            form:
                options:
                    validation_groups:
                        - sylius_shipping_address_update

sylius_admin_order_cancel:
    path: /orders/{id}/cancel
    methods: [PUT]
    defaults:
        _controller: sylius.controller.order::applyStateMachineTransitionAction
        _sylius:
            repository:
              method: findOrderById
              arguments:
                - '$id'
            permission: true
            state_machine:
                graph: sylius_order
                transition: cancel
            redirect: referer

sylius_admin_order_payment_complete:
    path: /orders/{orderId}/payments/{id}/complete
    methods: [PUT]
    defaults:
        _controller: sylius.controller.payment::applyStateMachineTransitionAction
        _sylius:
            event: complete
            permission: true
            repository:
                method: findOneByOrderId
                arguments:
                    id: $id
                    orderId: $orderId
            state_machine:
                graph: sylius_payment
                transition: complete
            redirect: referer

sylius_admin_order_payment_refund:
    path: /orders/{orderId}/payments/{id}/refund
    methods: [PUT]
    defaults:
        _controller: sylius.controller.payment::applyStateMachineTransitionAction
        _sylius:
            permission: true
            repository:
                method: findOneByOrderId
                arguments:
                    id: $id
                    orderId: $orderId
            state_machine:
                graph: sylius_payment
                transition: refund
            redirect: referer
            flash: sylius.payment.refunded

sylius_admin_order_shipment_ship:
    path: /orders/{id}/ship
    methods: [PUT]
    defaults:
        _controller: sylius.controller.shipment::updateAction
        _sylius:
            event: ship
            repository:
                method: findOneByOrderId
                arguments:
                    id: $id
                    orderId: $orderId
            state_machine:
                graph: sylius_shipment
                transition: ship
            redirect: referer
            section: admin
            permission: true
            form: Sylius\Bundle\ShippingBundle\Form\Type\ShipmentShipType
            vars:
                route:
                    parameters:
                        orderId: $orderId
                        id: $id

sylius_admin_order_resend_confirmation_email:
    path: /orders/{id}/resend-confirmation-email
    methods: [GET]
    defaults:
        _controller: Sylius\Bundle\AdminBundle\Action\ResendOrderConfirmationEmailAction
