Problem/Motivation
I have a site that was upgraded from Drupal 6 (Ubercart) to Drupal 7 (Commerce) and now to Drupal 9 (Commerce).
The Drupal 7 source for commerce_payment_transaction
has historical records from Drupal 6 with payment methods like "Credit card" (uc_authorizenet, pnref?), "Check", "PayPal".
commerce1_payment does not handle this situation and hard crashes the migration.
Error: Call to a member function getCurrencyCode() on null in /var/www/html/webroot/modules/commerce/modules/payment/src/Entity/Payment.php on line 334
#0 /var/www/html/webroot/core/lib/Drupal/Core/Entity/EntityStorageBase.php(566): Drupal\commerce_payment\Entity\Payment->preSave(Object(Drupal\commerce_payment\PaymentStorage))
#1 /var/www/html/webroot/core/lib/Drupal/Core/Entity/ContentEntityStorageBase.php(754): Drupal\Core\Entity\EntityStorageBase->doPreSave(Object(Drupal\commerce_payment\Entity\Payment))
#2 /var/www/html/webroot/core/lib/Drupal/Core/Entity/EntityStorageBase.php(521): Drupal\Core\Entity\ContentEntityStorageBase->doPreSave(Object(Drupal\commerce_payment\Entity\Payment))
#3 /var/www/html/webroot/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php(802): Drupal\Core\Entity\EntityStorageBase->save(Object(Drupal\commerce_payment\Entity\Payment))
#4 /var/www/html/webroot/core/lib/Drupal/Core/Entity/EntityBase.php(339): Drupal\Core\Entity\Sql\SqlContentEntityStorage->save(Object(Drupal\commerce_payment\Entity\Payment))
#5 /var/www/html/webroot/core/modules/migrate/src/Plugin/migrate/destination/EntityContentBase.php(247): Drupal\Core\Entity\EntityBase->save()
#6 /var/www/html/webroot/core/modules/migrate/src/Plugin/migrate/destination/EntityContentBase.php(186): Drupal\migrate\Plugin\migrate\destination\EntityContentBase->save(Object(Drupal\commerce_payment\Entity\Payment), Array)
#7 /var/www/html/webroot/core/modules/migrate/src/MigrateExecutable.php(248): Drupal\migrate\Plugin\migrate\destination\EntityContentBase->import(Object(Drupal\migrate\Row), Array)
#8 /var/www/html/vendor/drush/drush/includes/drush.inc(206): Drupal\migrate\MigrateExecutable->import()
Steps to reproduce
- Replicate drupal 6 -> drupal 7 data from old payment providers ("Credit card", "Check", "PayPal") where a transaction row contains currency_code of an empty string
- Generate a migration configuration
- Run migration. commerce1_payment crashes.
Proposed resolution
- A non-code single-currency store workaround is to add the default_value plugin with the preferred default_value.
- A simple resolution would be to add the "default_value" to both amount/currency_code and refunded_amount/currency_code process chains in the commerce1_payment migration (template). This could use a static value defined at the top of that migration that could be changed.
- A complex resolution would be to create a lookup plugin for the default currency code and update the migration (template) above accordingly to use it. There may not be a way to get the most accurate value in a multi-currency store though for an empty record. This might fit a >80% scenario though.
Remaining tasks
User interface changes
API changes
Data model changes
Migration (template) configuration changes