Created
April 16, 2019 08:35
-
-
Save Elendev/ba5aa84ce7cef8daf0f71ac4901959de to your computer and use it in GitHub Desktop.
Sylius - add an On Hold state
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # file config/packages/_sylius.yaml | |
| winzou_state_machine: | |
| sylius_order: | |
| states: | |
| on_hold: ~ | |
| transitions: | |
| hold: | |
| from: [new] | |
| to: on_hold | |
| unhold: | |
| from: [on_hold] | |
| to: new | |
| unhold_fulfill: | |
| from: [on_hold] | |
| to: fulfilled | |
| callbacks: | |
| guard: | |
| guard_on_unhold: | |
| on: unhold | |
| do: ['App\StateMachine\OnHoldGuard', 'canUnhold'] | |
| args: ['object'] | |
| guard_unhold_fulfill: | |
| on: unhold_fulfill | |
| do: ['App\StateMachine\OnHoldGuard', 'canUnholdFulfill'] | |
| args: ['object'] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # file translations/messages.en.yaml | |
| sylius: | |
| ui: | |
| hold: Hold | |
| unhold: Unhold | |
| unhold_fulfill: Unhold and fulfill the order |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| // file src/StateMachine/OnHoldGuard.php | |
| namespace App\StateMachine; | |
| use App\Entity\Order\Order; | |
| use Sylius\Component\Core\OrderPaymentStates; | |
| use Sylius\Component\Core\OrderShippingStates; | |
| class OnHoldGuard | |
| { | |
| public static function canUnhold(Order $order) : bool { | |
| return $order->getShippingState() !== OrderShippingStates::STATE_SHIPPED || | |
| $order->getPaymentState() !== OrderPaymentStates::STATE_PAID; | |
| } | |
| public static function canUnholdFulfill(Order $order) : bool { | |
| return !self::canUnhold($order); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # file config/routes/sylius_admin.yaml | |
| sylius_admin: | |
| resource: "@SyliusAdminBundle/Resources/config/routing.yml" | |
| prefix: /admin | |
| sylius_admin_order_hold: | |
| path: /orders/{id}/hold | |
| methods: [PUT] | |
| defaults: | |
| _controller: sylius.controller.order:applyStateMachineTransitionAction | |
| _sylius: | |
| permission: true | |
| state_machine: | |
| graph: sylius_order | |
| transition: hold | |
| redirect: referer | |
| sylius_admin_order_unhold: | |
| path: /orders/{id}/unhold | |
| methods: [PUT] | |
| defaults: | |
| _controller: sylius.controller.order:applyStateMachineTransitionAction | |
| _sylius: | |
| permission: true | |
| state_machine: | |
| graph: sylius_order | |
| transition: unhold | |
| redirect: referer | |
| sylius_admin_order_unhold_fulfill: | |
| path: /orders/{id}/unhold-fulfill | |
| methods: [PUT] | |
| defaults: | |
| _controller: sylius.controller.order:applyStateMachineTransitionAction | |
| _sylius: | |
| permission: true | |
| state_machine: | |
| graph: sylius_order | |
| transition: unhold_fulfill | |
| redirect: referer |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment