Problem/Motivation
We have some data where amount does not get split properly so $amount is an integer.
Error: Call to a member function getNumber() on integer in commerce_migrate/modules/commerce/src/Plugin/migrate/process/commerce1/OrderItemDiscountAdjustment.php on line 235 #0 commerce_migrate/modules/commerce/src/Plugin/migrate/process/commerce1/OrderItemDiscountAdjustment.php(156): Drupal\commerce_migrate_commerce\Plugin\migrate\process\commerce1\OrderItemDiscountAdjustment->getAdjustment(Array, Object(Drupal\migrate_tools\MigrateExecutable), Object(Drupal\migrate\Row))
Attached patch throws an exception if method isn't found.
Proposed resolution
Add a dependency on commerce_price, which has the getNumber method.
Check the value of the returned value from $this->spilt before processing it.
Add tests!
Comments
Comment #2
grahlComment #3
brightboldApplying the patch in #2 to RC1 resulted in the offending order item being ignored and the following message was logged: "Invalid amount extraction for line item '44950'." Without the patch,
drush migrate-importvomited up the above error and accompanying callstack and terminated abnormally. Thanks for solving that, @grahl!From a functional standpoint, this patch behaved as promised. But I can't mark as RTBC since it's now failing tests, so it probably needs to be rerolled.
Comment #4
quietone commentedgetNumber is provided by commerce_price. So this will be a dependency issue.
Comment #5
quietone commentedThere is also the problem that the returned value from $this->spilt is not checked to determine if it is empty before using it. For that just an "if ($amount)" will fix it.
Not sure why checking if the getNumber method exists solves the problem in the IS. The error shows that getNumber is indeed being called but with an integer and not a string.
This patches adds a test for the commerce1 orderitemadjustment process plugin and applies fixes to that plugin and similar to the ubercart version. And adds a dependency on commerce_price.
Comment #6
quietone commentedAdding more testing.
Comment #7
quietone commentedComment #8
quietone commentedSelf review, I don't see anything to prevent this from going in. That assumes the tests are robust and I haven't missed a case.
Comment #9
quietone commentedRetested
Comment #10
quietone commentedRetesting
Comment #11
quietone commentedIs anyone using the latest patch here? Having any problems with it?
Comment #12
quietone commentedNeeds a reroll. Some of the changes here sneaked in in #3178923: Add OrderItemAdjustment test process plugin. Removing changes here that are for Ubercart - that should be in a separate issue.
Comment #13
damienmckennaThis conflicts with #3150733: Drupal 9 compatibility fixes for Commerce Migrate.
Comment #14
damienmckennaRerolled.
Comment #16
quietone commentedI am not sure about that reroll. The patch in #12 still applies and I just re-ran the tests and they pass.
Back to NR for the patch in #12.
Comment #17
damienmckennaYeah, let's skip #14, not sure what I did there :-\
Comment #18
quietone commentedIs anyone using the patch in #12? If so, what were the results?
Comment #19
damienmckennaI'm using #12 but am having other problems with my migration and can't get to the point where I can test it.
Comment #20
tonytheferg commentedI have had #14 applied for sometime, and it seems to be working. Would you like me to try #12 instead to review?14 breaks tax and discount migrations from what I have seen as it removes the adjustment array. #12 is preferred
Comment #21
quietone commentedComment #22
quietone commentedRe-uploading the patch from #12 to rerun tests.
Comment #23
quietone commentedAny reason not to commit this?
Comment #24
damienmckennaLGTM.
Comment #26
quietone commented@DamienMcKenna, thanks!