Problem/Motivation
I am migrating from Drupal 7 + Commerce 1.x to Drupal 9 + Commerce 2.x. All my payments have the decimal point in the wrong place. This is not a problem with prices.
Steps to reproduce
Migrate from Drupal 7 to Drupal 9. Then check the databases.
I need to skip some values that were not migrated. My D7 database:
MySQL [drupal]> SELECT transaction_id, order_id, payment_method, amount
-> FROM commerce_payment_transaction
-> WHERE transaction_id > 171 LIMIT 0,5;
+----------------+----------+----------------+--------+
| transaction_id | order_id | payment_method | amount |
+----------------+----------+----------------+--------+
| 172 | 215 | authnet_aim | 22467 |
| 173 | 219 | authnet_aim | 59500 |
| 174 | 222 | authnet_aim | 18752 |
| 179 | 231 | authnet_aim | 14595 |
| 180 | 231 | authnet_aim | 14595 |
+----------------+----------+----------------+--------+
5 rows in set (0.00 sec)
And my D9 database:
MySQL [default]> SELECT payment_id, order_id, amount__number
-> FROM commerce_payment LIMIT 0,5;
+------------+----------+----------------+
| payment_id | order_id | amount__number |
+------------+----------+----------------+
| 172 | 215 | 22467.0000 |
| 173 | 219 | 59500.000000 |
| 174 | 222 | 18752.000000 |
| 179 | 231 | 14595.000000 |
| 180 | 231 | 14595.000000 |
+------------+----------+----------------+
5 rows in set (0.000 sec)
In Drupal 9, all those values should have two more digits after the decimal point.
Proposed resolution
Divide by 100 in the prepareRow()
method of the migration source.
This works for my use case. We might have to work harder to handle all cases.
Remaining tasks
Add test coverage.
User interface changes
None
API changes
None
Data model changes
None