You can set all orders with selected internal statuses to be automatically cancelled past their “Do Not Ship Later Than” date. By default OroCommerce cancel all orders which has not null ship Until field or the current date grant than this field .
So How you can customize this atomization for example the order which created before 60 days and still open cancel it .
OroCommerce system us Processes (processes.yml) which provide the possibility to automate tasks related to entity management. They use the main doctrine events to perform described tasks at the right time. Each process can be performed immediately or after a timeout. Processes use the OroMessageQueue component and the bundle to provide the possibility of delayed execution.
You can find processes.yml responsible for auto cancellation inside path :
/vendor/oro/commerce/src/Oro/Bundle/OrderBundle/Resources/config/oro/processes.yml
processes: definitions: expire_orders: label: 'Cancel old Orders' enabled: true entity: Oro\Bundle\OrderBundle\Entity\Order preconditions: '@is_system_config_equal': ['oro_order.order_automation_enable_cancellation', true] actions_configuration: - '@call_service_method': attribute: $.applicableStatuses service: oro_order.provider.configuration method: getApplicableInternalStatuses - '@call_service_method': attribute: $.targetStatusId service: oro_order.provider.configuration method: getTargetInternalStatus - '@tree': conditions: '@and': - '@not_empty': $.targetStatusId - '@not_empty': $.applicableStatuses actions: - '@request_enum_entity': enum_code: 'order_internal_status' attribute: $.targetStatus identifier: $.targetStatusId - '@create_datetime': attribute: $.date #should be start of the day, to avoid cancellation of orders with today's DNSL time: '00:00:00' - '@find_entities': class: Oro\Bundle\OrderBundle\Entity\Order attribute: $.orders where: and: - e.shipUntil IS NOT NULL - e.shipUntil < :date - NOT IDENTITY(e.internal_status) = :targetStatus - IDENTITY(e.internal_status) IN (:statuses) query_parameters: date: $.date targetStatus: $.targetStatusId statuses: $.applicableStatuses - '@foreach': array: $.orders value: $.order actions: - '@assign_value': [$.order.internalStatus, $.targetStatus] triggers: expire_orders: - cron: '10 * * * *'
The id definitions is expire_orders the first conditions is testing if the feature is enabled from global configuration:
preconditions: '@is_system_config_equal': ['oro_order.order_automation_enable_cancellation', true]
you can change from:
To configure automatic order cancellation globally:
- Navigate to System > Configuration in the main menu.
- Select Commerce > Orders > Order Automation in the menu to the left.
The next is to find all status enabled and target cancel status :
actions_configuration: - '@call_service_method': attribute: $.applicableStatuses service: oro_order.provider.configuration method: getApplicableInternalStatuses - '@call_service_method': attribute: $.targetStatusId service: oro_order.provider.configuration method: getTargetInternalStatus
they will start the query to find all entities from filter:
where: and: - e.shipUntil IS NOT NULL - e.shipUntil < :date - NOT IDENTITY(e.internal_status) = :targetStatus - IDENTITY(e.internal_status) IN (:statuses) query_parameters: date: $.date targetStatus: $.targetStatusId statuses: $.applicableStatuses
$date is affected before by time: '00:00:00' .
after that you will change all status of orders result to cancel status:
- '@foreach': array: $.orders value: $.order actions: - '@assign_value': [$.order.internalStatus, $.targetStatus]
you can add filter to query for example copy past processes.yml in your bundle MyCompany/Bundle/OverrideBundle/Resources/config/oro/processes.yml and fill with the content of default file and you can change to:
- '@find_entities': class: Oro\Bundle\OrderBundle\Entity\Order attribute: $.orders where: and: - e.shipUntil IS NOT NULL - e.shipUntil < :date - NOT IDENTITY(e.internal_status) = :targetStatus - IDENTITY(e.internal_status) IN (:statuses) or: - e. createdAt > :dateBetween - IDENTITY(e.internal_status) = :openStatus - IDENTITY(e.internal_status) IN (:statuses) query_parameters: date: $.date targetStatus: $.targetStatusId statuses: $.applicableStatuses openStatus: ‘open’ dateBetween: ‘<dateBetween("-60 days", "now")>’
Here you have add an Or clause to cancel all orders which has internal status open and passed 60 days from day of creation of order . That all Thanks .
Comments