1

Last year our Previous develepors added suffix to the order number.

Example : If Order number is 10000001 , they added suffix like 10000001-23 as it was 2023 year.

now we want to change to 24 from 23. Currently i do not have database access. Is there any way i can update the suffix of order number Programatically ?

3

2 Answers 2

0

To update the suffix of the order numbers programmatically without direct database access, you can loop through your existing orders and modify the order numbers with the new suffix. Since you want to change the suffix from '23' to '24', you would need to identify the orders with the existing suffix '-23' and replace it with '-24'.

Here is a general approach you can take to accomplish this:

Retrieve Orders: Fetch the list of all orders from your system. This may involve using an API or other method to retrieve the order data.

Identify and Modify: Loop through the orders and identify those with the old suffix ('-23'). Replace the suffix '-23' with '-24' for these orders.

Update Orders: Save the updated orders back to your system using an API or other method available to you.

Here is some example code that demonstrates this approach:

def update_order_suffix(orders): old_suffix = "-23" new_suffix = "-24" updated_orders = []

for order in orders:
    order_number = order['order_number']
    # Check if the order number ends with the old suffix
    if order_number.endswith(old_suffix):
        # Replace the old suffix with the new suffix
        new_order_number = order_number[:-len(old_suffix)] + new_suffix
        order['order_number'] = new_order_number
        updated_orders.append(order)

# Update orders in your system
for updated_order in updated_orders:
    # Assuming you have a function update_order_in_system to update the order
    update_order_in_system(updated_order)

Example usage:

Retrieve your orders using an API or other method

orders = retrieve_orders()

Update order suffix from '-23' to '-24'

update_order_suffix(orders)

0

yes you can use around plugin to achives the same lets try it like this

etc/di.xml

    <?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <type name="Magento\Sales\Model\Order">
        <plugin name="change_order_number" type="Vendor\OrderNumber\Plugin\OrderNumber" sortOrder="10"/>
    </type>
</config>

OrderNumber.php

    <?php
namespace Vendor\OrderNumber\Plugin;

class OrderNumber
{
    public function aroundGetIncrementId(\Magento\Sales\Model\Order $subject, \Closure $proceed)
    {
        $result = $proceed();
        $oldSuffix = '-23'; // Old suffix
        $newSuffix = '-24'; // New suffix
        if (substr($result, -strlen($oldSuffix)) == $oldSuffix) {
            $result = substr($result, 0, -strlen($oldSuffix)); // Remove old suffix
        }
        $result .= $newSuffix; // Add new suffix
        return $result;
    }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.