An order can have the following internal statuses:
- Open — The order has been submitted and is being processed. You can cancel, mark as shipped, and close an open order.
- Cancelled — The order that has been submitted but successively canceled. There are many circumstances in which you may need to cancel the order. For example, the order has expired, or your organization cannot fulfill the order for any reasons, or the buyer asked you to do so. The submitted order may be canceled by an administrator or automatically when its ‘do not ship later than’ date is passed.
You can close a canceled order.
Shipped — The order is on the way or delivered to the buyer. You can close a shipped order.
- Closed — The order does not require any further actions: has been successfully delivered, or canceled for some time, etc. You can archive a closed order
- Archived – An old order stored for historical purposes only. No further actions with the order are required (the buyer is not going to send a return request, etc.).
How to add Extra Order Statuses:
In this tutorial I will add Approved internal status:
- Approved — The order has been opened. You can cancel, mark as shipped, and close an approved order.
To see the default order internal statuses you can go to ‘oro_enum_order_internal_status’ table in you db by phpmyadmin.
In this step you need to create an Interface ExtraStatusesProviderInterface.php in Provider folder in our bundle to add our internal status id ‘approved’.
you can add more internal statuses.
<?php namespace Ibnab\Bundle\ExtraOrderStatusesBundle\Provider; interface ExtraStatusesProviderInterface { const INTERNAL_STATUS_APPROVED = 'approved'; //Add More internal statuses }
Load internal status in migrations:
The first step you need to create a php class extends from AbstractEnumFixture
- AbstractEnumFixture is abstract class have two abstract functions getData() and getEnumCode()
getData() Returns an array of possible enum values, where array key is an id and array value is an English translation
getEnumCode() Returns an enum code of an extend entity (in our case it’s Order Entity):
Oro\Bundle\OrderBundle\Entity\Order.php and enm code is: const INTERNAL_STATUS_CODE = 'order_internal_status';
Ibnab\Bundle\ExtraOrderStatusesBundle\Migrations\Data\ORM\LoadInternalStatus.php
<?php namespace Ibnab\Bundle\ExtraOrderStatusesBundle\Migrations\Data\ORM; use Oro\Bundle\EntityExtendBundle\Migration\Fixture\AbstractEnumFixture; use Oro\Bundle\OrderBundle\Entity\Order; use Ibnab\Bundle\ExtraOrderStatusesBundle\Provider\ExtraStatusesProviderInterface; class LoadInternalStatus extends AbstractEnumFixture { /** @var array */ protected static $data = [ ExtraStatusesProviderInterface::INTERNAL_STATUS_APPROVED => 'Approved' //Add More internal statuses ]; /** * {@inheritdoc} */ protected function getData() { return self::$data; } /** * Returns array of data keys * * @return array */ public static function getDataKeys() { } /** * {@inheritdoc} */ protected function getEnumCode() { return Order::INTERNAL_STATUS_CODE; } }
The second step add new php class UpdateOrderStatuses.php to get dependent class and load the new Internal Status
Ibnab\Bundle\ExtraOrderStatusesBundle\Migrations\Data\ORM\UpdateOrderStatuses.php
<?php namespace Ibnab\Bundle\ExtraOrderStatusesBundle\Migrations\Data\ORM; use Doctrine\Common\DataFixtures\AbstractFixture; use Doctrine\Common\DataFixtures\DependentFixtureInterface; use Doctrine\Common\Persistence\ObjectManager; use Doctrine\ORM\EntityManager; use Ibnab\Bundle\ExtraOrderStatusesBundle\Provider\ExtraStatusesProviderInterface; class UpdateOrderStatuses extends AbstractFixture implements DependentFixtureInterface { /** * {@inheritdoc} */ public function getDependencies() { return [LoadInternalStatus::class]; } /** * @var EntityManager $manager * {@inheritdoc} */ public function load(ObjectManager $manager) { $qb = $manager->getConnection()->createQueryBuilder(); $qb->update('oro_order') ->set('internal_status_id', ':status') ->setParameter('status', ExtraStatusesProviderInterface::INTERNAL_STATUS_APPROVED) ->where($qb->expr()->isNull('internal_status_id')) ->execute(); } }
Add Approved operation in Order View in the Back-Office:
Ibnab\Bundle\ExtraOrderStatusesBundle\Resources\config\oro\actions.yml
// Add Approved operation just for opened Order operations: ibnab_order_approved: label: ibnab.order.action.order.approved enabled: true applications: [default] routes: - oro_order_view order: -1 button_options: icon: fa fa-check-circle-o preconditions: '@equal': [$internalStatus.id, 'open'] actions: - '@request_enum_entity': enum_code: 'order_internal_status' attribute: $internalStatus identifier: 'approved' - '@flush_entity': $.data - '@flash_message': message: ibnab.order.action.message.order.approved.success type: 'info' message_parameters: id: $identifier // Add Cancel operation for approved Order ibnab_order_cancel: label: ibnab.order.action.order.cancel enabled: true applications: [default] routes: - oro_order_view order: 1 button_options: icon: fa-close preconditions: '@equal': [$internalStatus.id, 'approved'] actions: - '@request_enum_entity': enum_code: 'order_internal_status' attribute: $internalStatus identifier: 'cancelled' - '@flush_entity': $.data - '@flash_message': message: ibnab.order.action.message.order.cancel.success type: 'info' message_parameters: id: $identifier // Add Close operation for approved Order ibnab_order_close: label: ibnab.order.action.order.close enabled: true applications: [default] routes: - oro_order_view order: 2 button_options: icon: fa-window-close-o preconditions: '@equal': [$internalStatus.id, 'approved'] actions: - '@request_enum_entity': enum_code: 'order_internal_status' attribute: $internalStatus identifier: 'closed' - '@flush_entity': $.data - '@flash_message': message: ibnab.order.action.order.close.success type: 'info' message_parameters: id: $identifier // Add Mark as shipped operation for approved Order ibnab_order_mark_as_shipped: label: ibnab.order.action.order.mark_as_shipped enabled: true applications: [default] routes: - oro_order_view order: 3 button_options: icon: fa-check preconditions: '@equal': [$internalStatus.id, 'approved'] actions: - '@request_enum_entity': enum_code: 'order_internal_status' attribute: $internalStatus identifier: 'shipped' - '@flush_entity': $.data - '@flash_message': message: ibnab.order.action.order.mark_as_shipped.success type: 'info' message_parameters: id: $identifier
Is all Done
Comments