I'm manually using the configs and classes for a migration built on migrate_plus from Commerce 1.x > 2.x

My product migrations were failing because the reference to the new product variation wasn't mapping correctly. I determined that this is likely caused by hardcoding product_id:product_id in the migration config which will attempt to set the product id to be the same as 1.x's id.

I see two ways to solve this:

1) remove id mappings and let migrate do it's thing

2) update the product variation migration to map `variation_id: product_id` instead of `product_id: product_id1`

Comments

andyg5000 created an issue. See original summary.

andyg5000’s picture

Status: Active » Needs review
StatusFileSize
new1.1 KB

Status: Needs review » Needs work
andyg5000’s picture

StatusFileSize
new448 bytes

Let's try option 2 which is actually what I ended up using on my migration.

heddn’s picture

Is this the same thing as the failing test I found over in #2899321: Refactor Commerce Product and ProfileBilling tests? In there, I suggested we use migration_lookup and transform to the actual id. If this is better, fine. But I'd still like to see a failing test too, which we have over there.

quietone’s picture

Status: Needs work » Needs review
StatusFileSize
new4.83 KB

@andyg5000, glad you found something that worked for you.

I agree with heddn that a migration_lookup is desirable. Though I don't see the path yet on that because of the back referencing going on. Somewhere else mglaman suggested that a post event subscriber was needed to handle this problem, similar to the existing one for orders. After mulling it over, I see that as the way to do this. I have made a initial patch with that in mind and added comments in the migrations to caution that the product id in the product variation is not correct after running the product variation migration. It is a start.

Status: Needs review » Needs work

The last submitted patch, 6: 2899426-6.patch, failed testing. View results

quietone’s picture

Status: Needs work » Needs review
StatusFileSize
new4.82 KB
new640 bytes

Only run the post event MigrateProduct when the migration id is 'd7_product_displa'.

quietone’s picture

StatusFileSize
new4.84 KB
new1.7 KB

Now, add in the changes in patch #4. changing the destination from product_id to variation_id in the product variation migration (d7_product.yml). There is now a variation_id that we can use with migration_lookup in the product migration (d7_product_display.yml).

Status: Needs review » Needs work

The last submitted patch, 9: 2899426-9.patch, failed testing. View results

quietone’s picture

Status: Needs work » Needs review
StatusFileSize
new7.03 KB
new2.04 KB

Modify the test since all product_ids in the product variation migration are now NULL, reflecting that the product has not yet been migrated.

heddn’s picture

Status: Needs review » Needs work
Issue tags: +Needs reroll

Unfortunately, needs a re-roll.

  1. +++ b/commerce_migrate.services.yml
    @@ -7,3 +7,7 @@ services:
    \ No newline at end of file
    

    Nit: missing new-line.

  2. +++ b/modules/commerce/migration_templates/d7_product.yml
    @@ -6,7 +6,13 @@ migration_tags:
    +  # migrated in the product migration, d7_product_display,
    

    This was recently re-named.

  3. +++ b/modules/commerce/tests/src/Kernel/Migrate/d7/ProductTest.php
    @@ -54,7 +54,13 @@ class ProductTest extends Commerce1TestBase {
    +    $this->assertProductVariationEntity($variation_id, '0', 'TOT1-GRN-OS', '16.000000', 'USD', '15', 'Tote Bag 1', 'default');
    
    +++ b/modules/commerce/tests/src/Kernel/Migrate/d7/ProductVariationTest.php
    @@ -42,13 +42,13 @@ class ProductVariationTest extends Commerce1TestBase {
    +    $this->assertProductVariationEntity(1, '0', 'TOT1-GRN-OS', '16.000000', 'USD', NULL, 'Tote Bag 1', 'default');
    

    So, if I get this right, it is NULL in the variation test, but now its accurate in the ProductTest? Great. That's what I'd expect.

quietone’s picture

Status: Needs work » Needs review
StatusFileSize
new7.08 KB
new1.21 KB

Rerolled. 1 and 2 fixed.

Is there something to do for #3. It looks like you answered your own question.

Status: Needs review » Needs work

The last submitted patch, 13: 2899426-13.patch, failed testing. View results

quietone’s picture

Status: Needs work » Needs review
StatusFileSize
new7.1 KB
new1.11 KB

Missed renaming some migrations.

quietone’s picture

Component: Code » Drupal Commerce 1.x

Changing component since this is really only for Drupal Commerce 1 sources.

quietone’s picture

Issue tags: -Needs reroll

And doesn't need a reroll.

mglaman’s picture

Thoughts:

* We should replicate the AddToCartForm submit method in a test to help verify products can be added to a cart.
* Saving a Product will automatically populate it's variations back references, see https://github.com/mglaman/commerce/blob/8.x-2.x/modules/product/src/Ent... line 314. That should simplify the event subscriber

heddn’s picture

Status: Needs review » Needs work

Seems like some work to me. Back to NW for #19.

quietone’s picture

Status: Needs work » Needs review
StatusFileSize
new6.86 KB
new1.08 KB

#19.1 I think that is out of scope. All for testing that functionality, but lets do that in #2899153: Cannot add variation to cart, due to failed store detection. Worst case is the we keep adding modules and tests here. I think we have fixed the problem in the IS.

#19.2 The event subscriber has been simplified.

mglaman’s picture

Status: Needs review » Fixed

That's fine, we can add the test elsewhere.

Fix looks good to me, event subscriber simplified and tests pass!

quietone’s picture

Status: Fixed » Needs review
StatusFileSize
new6.85 KB
new302 bytes

Oh. This hasn't been committed!

Went to commit it and there is an extra line in the patch in #21. Let's fix that first

  • quietone committed cd62287 on 8.x-2.x
    Issue #2899426 by quietone, andyg5000: Product and variation id mapping...
quietone’s picture

Status: Needs review » Fixed

Now set as fixed.

In hindsight, hope no one minds. After all it is a blocker and the whitespace was not a code change.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.