Postponed on #2977682: Add territory to tax type migration.
When attempting to add a migrated product to a cart, the exception is thrown
Exception: The given entity is not assigned to any store. in Drupal\commerce_cart\Form\AddToCartForm->selectStore() (line 259 of modules/contrib/commerce/modules/cart/src/Form/AddToCartForm.php).
This is due to $stores = $entity->getStores(); returning an empty array.
From \Drupal\commerce\PurchasableEntityInterface::getStores and its implementation in ProductVariation
/**
* {@inheritdoc}
*/
public function getStores() {
$product = $this->getProduct();
return $product ? $product->getStores() : [];
}
I'm assuming the backreference from Product Variation to its Product is broken for 1.x. We'll need to follow the pattern in \Drupal\commerce_migrate\EventSubscriber\MigrateOrderItem for product variations to ensure backreference.
Comments
Comment #2
heddnI think it is broken. See my comment in #2894733-13: Convert Commerce Product and ProfileBilling tests to use CommerceMigrateTestTrait
Comment #3
heddnWe have a failing test in #2899321: Refactor Commerce Product and ProfileBilling tests.
Comment #4
quietone commentedPostponing on #2899426: Product and variation id mapping issues
Comment #5
quietone commented#2899426: Product and variation id mapping issues is in back to active
Comment #6
quietone commentedTested this today. On a fresh install, I used the UI to migrate the test fixture, ck2. After migration, navigated to product/29, clicked add to cart and there was no error. Navigated to /cart and the product is shown.
I reckon this is fixed, so closing.
@mglaman, I'm sure you'll reopen this if it is still a problem.
Comment #7
jphelan commentedI'm having this issue. None of my migrated products will add to the cart.
Here's part of my yml file.
When I look in devel it appears to be set:
But I still get this error when I try to add any migrated product to the cart. If I create a new product it's fine.
Comment #8
jphelan commentedI should also mention I'm migrating from D6 Ubercart.
Comment #9
jphelan commentedI've figured it out. I noticed the product_id backreference in commerce_product_variation_field_data was for a product_id that no longer existed. I’ve done the product migration a number of times and rolled back to make changes and try again but never rolled back the variations migration because they kept being referenced in the product so I thought I didn’t need to. It appears the product_id is only updated correctly after the initial products migration. I'm not sure if there is a solution to this particular issue, it appears they are set to NULL initially is it possible to reset variation's product_id to null when rolling back the product migration? Is this noted somewhere and I missed it? Perhaps it should be noted in the uc6_product_variation.yml file where this is process is explained.
Comment #10
quietone commented@jphelan, Thanks for the tracking down the cause!
So, mglaman's suspicion was correct. And this has to do with how the rollbacks are done.
Yes, it is possible, but is wasn't done because of the performance impact. Clearly, that needs to be looked at agai.
No, you were the first to find this particular problem. The rollback is explained a bit in the Known Issues page, but it doesn't touch on the problem you've found.
The next step is to reproduce the problem in Ubercart since that is the source where jphelan found this problem. Setting the component to Code since this is probably a problem for Commerce 1 as well.
Comment #11
quietone commentedI have been able to reproduce a case where the product variation back reference becomes NULL, though it isn't identical to what jphelan reported. To begin I used the UI to migrate the test fixture, then tried to add a product to the cart, which failed but with a different error that there was a missing property, 'territories'. That has to do with taxes, so I set up a territory and then was able to add a product to the cart. I then removed the product from the cart and started using drush to investigate the problem reported by jphelan.
The back references are now NULL, and the product variations have a new id and so will no match the reference in the product table. The products were not rolled back. It wasn't possible to add a product to the cart here because the 'add to cart' button was not displayed.
To fix this problem rollback the product and re-import them and that will correct the references.
The back references are now correct.
@jphelan, is it possible you encountered this scenario, that is that the product variations were rolled back while the products were still migrated.
Comment #12
quietone commentedSince that has reappeared again maybe there should be a test for adding to cart.
Comment #14
quietone commentedChange the path for a product in Commerce 1 test.
Comment #16
quietone commentedAdd the property.
Comment #18
quietone commentedNow, to follow up on the failure reported in #11. When I tried to add a product after the Ubercart migration I received this error,
The tax type migration is not setting the territories array. To fix that, the source plugin now gets the country code variable, converts it to a 2 character code and puts in on the row. The migration then puts into the territories configuration. This patch include those changes and updates the source plugin, source plugin test and migration test.
Comment #20
jphelan commented@quietone I believe I was migrating the reverse of you. I migrated the product variations first and then the products. I believe the nid backreference should be NULL and commerce_migrate sets it to the new nid when you migrate the products. I was rolling back the products but not the product variations, so the nid backreference was referencing the old products and was not updated to the new ones. It's also odd to me that resaving the product variation does not update the backreference to the correct nid. Seems like either way they both have to be rolled back at the same time right now.
Comment #21
quietone commentedI moved the fixes to the tax type to a new issue, #2977682: Add territory to tax type migration, which in turn means this is postponed on that.
This patch removes the tax type changes. With this patch the adding of a product to the cart post migration works for Commerce 1 but not Ubercart 6.
Comment #22
quietone commentedUbercart needs a default store and that migration is in this issue #2977978: Add default store migration.
This patch works with the territory patch and the default store patch installed. However, after the migration for Commerce 1 and Ubercart 6 an additional drupalGet is needed, otherwise attempting to load the product page results in a 502.
Comment #23
quietone commentedBoth #2977682: Add territory to tax type migration and #2977978: Add default store migration are committed so this is no longer postponed.
Comment #26
quietone commentedThe failure is because core is not validating the file paths. The ubercart migration test was using a source_base_path that did not exist. The source_base_path is now an empty string.#2562845: Validate file path on Credential form.
Comment #27
quietone commentedImprove the summary line for the test classes.
Comment #28
quietone commentedThis is not testing the entity counts of the full migration, so removing the entity counts.
Comment #29
quietone commentedRestesting
Comment #30
quietone commentedOne question, as mentioned in #22. After the migration and before loading a product page another page must be loaded or a 502 occurs. Why is that needed?
In this test access '/about' before a product page.
In this test access an admin page before the product page.
Comment #31
quietone commentedRan the Ubercart 6 test locally without the extra step of loading a page before loading the product and it passed. Trying again with the testbot.
Comment #32
quietone commentedOK, the extra page load appeared in #21, although it is mentioned in the next comment. It should not have been needed, I never investigated why it was needed, but it isn't anymore. So, let's go with it.
Comment #34
quietone commentedWoohoo!