Problem/Motivation
Currently only order products are coming over but line items (shipping, tax, etc) do not. The line item test should also be updated for this result.
Shipping line items are problematic. mg;aman summarized in #52, "We need shipping line items to migrate to a shipment entity; which will cause the shipping adjustment to populate. Otherwise, if the order is refreshed, all adjustments not "custom" will be removed." This will need some other migrations to run first probably best to move to a separate issue.
Proposed resolution
This issue will migrate all lines items except shipping, that will be done separately.
Add a new generic process plugin, commerce_adjustments, which accepts a nested array of adjustment information and returns a nested array of CommerceAdjusment objects.
Remaining tasks
Review
Commit
Comment | File | Size | Author |
---|---|---|---|
#82 | interdiff.txt | 1.36 KB | quietone |
#82 | 2766679-82.patch | 19.17 KB | quietone |
#80 | 2766679-80.patch | 17.68 KB | quietone |
#76 | interdiff.txt | 1.28 KB | quietone |
#76 | 2766679-76.patch | 18.51 KB | quietone |
Comments
Comment #2
quietone CreditAttribution: quietone commentedComment #3
quietone CreditAttribution: quietone commentedThis looks like the adjustments field on the destination commerce_order_item entity.
And on the source, uc_order_line_items.
Comment #4
quietone CreditAttribution: quietone commentedSo, I created a new migration with a new source and destination plugin. Ran it and get 'shipping is an invalid adjustment type'. That's right there isn't a shipping adjustment type. Should adjustment types that don't match the existing ones be given type 'Custom' or something else?
Comment #5
mglamanLet's check if commerce_shipping is enabled. If it is, let's use `shipping` adjustment type (http://cgit.drupalcode.org/commerce_shipping/tree/commerce_shipping.comm...). Otherwise, yeah let's make it custom.
Comment #6
quietone CreditAttribution: quietone commentedHaving some success with this.
TODO: All the source orders have a shipping line item. It would be prudent to test an order that does not include shipping.
There needs to be a test with commerce_shipping enabled. But when I try that locally I get an exception
'The "physical_measurement" plugin does not exist.'
. What needs to happen so that plugin is found?Comment #8
mglamanCommerce Shipping requires Physical module
Comment #9
quietone CreditAttribution: quietone commented@mglaman, thx. I should've seen that.
Patch now with expanded tests and a new test for testing orders with the shipping modules enabled.
Comment #10
quietone CreditAttribution: quietone commentedThe patch helps.
Comment #12
quietone CreditAttribution: quietone commentedThis moves the creation of the Adjustment and Price to a new destination plugin, since that isn't really a transform operation. There are few things to address, such as the currency is hard coded and maybe the test for the presence of commerce_shipping can be moved to a sub-module as suggested in #2871241: Offer submodules that enforce configuration to match specific sources.
Comment #14
quietone CreditAttribution: quietone commentedTry again.
Comment #15
mglamanAwesome! One concern
This is forcing a currency code which is not the store default, or existing possible currency code.
Comment #16
quietone CreditAttribution: quietone commentedComment #17
quietone CreditAttribution: quietone commentedThanks, I completely forgot to go back and fix the currency.
The interdiff failed, but I added a diff since it was small.
Comment #18
quietone CreditAttribution: quietone commentedRight something has changed, the failing tests have nothing to do with this patch. I was working off core 8.3 and these test pass. But they fail with core 8.4, without this patch.
Comment #19
quietone CreditAttribution: quietone commentedMoving the patch from #6 in #2888764: Process plugin for default store currency to here.
Comment #20
quietone CreditAttribution: quietone commentedA possible problem here is that this will conflict with a custom currency migration. Maybe that is only relevant if multiple currencies are in use.
This is simple enough that a new method isn't needed.
Comment #21
willeaton CreditAttribution: willeaton commentedIn Drupal 6 I think it was very difficult to achieve multiple currencies unless you had multisites (as one of my sites does). As D6 ubercart did not save currencies in the order, or store, but in the site variables I think its safe to load it from D6 variables which I believe is what this line is doing (correct me if Im wrong)...
Not sure I understand, are you saying that we shouldn't add it or that we can reuse the same method from elsewhere?
Please note that some of my changes seem to be removed from the patch 2888764-6.patch. In getAdjustmentData() I added a freach on teh adjustments to add the missing currency. The order save was throwing up loads of errors in Price.php because we are not passing the currency. Maybe this is staying in the other case...? https://www.drupal.org/node/2888764
Comment #22
quietone CreditAttribution: quietone commentedAssigning to myself for review.
Comment #23
quietone CreditAttribution: quietone at Acro Commerce commented@willeaton, thanks for the information about Ubercart currencies. That keeps things simple.
Re the VariableGet, I mean we can put the VariableGet in prepareRow(). Which I have done in this patch. Also, there is a bit of renaming and the source plugin extends from DrupalSqlBase instead of SqlBase.
I have restored the setting of the currency_code in prepareRow. To be consistent we should, ideally, get the currency from the currency migration, which this is dependent on. But, as explained in #21, that isn't necessary in this case.
Comment #24
heddnI think some of my feedback would be address with a re-roll now that #2894123: Move commerce to submodule has landed.
Shouldn't this be called simply Order and not be placed in a uc6 sub-folder? This is the destination and we want the destinations to be re-usable.
I wondered here for a moment if it made sense to tie the source data so closely to what the destination order is expected. But after looking at it, I think it makes sense.
OK, I take that back now. Why don't we just do everything in the process plugin for adjustments. Why do we need the altered destination and pre-import stuff.
This @TODO isn't clear what is needed to be done.
This seems out of place here. Or at least a comment could help explain why we need the boolean.
Comment #25
quietone CreditAttribution: quietone at Acro Commerce commented1. Destination plugin gone.
2. Moved the creation of the Price and Adjustment to the process plugin.
3. The TODO was actually a note to myself, not meant to be left in the code.
4. Comment added. And thanks, this lead me to realize that the code using the commerce_shipping source value was missing. It is restored now and a test added to check the adjustment type is 'shipping' when commerce_shipping is enabled on the source.
Comment #27
quietone CreditAttribution: quietone at Acro Commerce commentedAdded '@requires module' to the annotation in the test.
Comment #29
quietone CreditAttribution: quietone at Acro Commerce commentedReroll. Including moving some files to the newish ubercart submodule.
Comment #31
quietone CreditAttribution: quietone at Acro Commerce commentedFailure is
But the @requires is there.
Note the test passes locally, where the required modules are present.
Comment #32
quietone CreditAttribution: quietone at Acro Commerce commentedThe @requires doesn't appear to do anything. I looked at there is https://www.drupal.org/node/2728579, https://www.drupal.org/node/1273478 and a draft CR https://www.drupal.org/node/2857979 (which isn't very clear to me) All up, no indication of what to do now with such a test. Asked in #drupal-contribute, larowlan wasn't sure either.
So, I decided to put it into a submodule. It works locally.
Comment #34
mglamanPer #31 I'd like to talk to the PHPUnit people or Mixologic.
Comment #35
yogeshmpawarupdated patch as per proposed solution in https://www.drupal.org/node/2728579. maybe it will clear test fails.
Comment #37
mglamanHere is an attempt to add require-dev. it's proven that
@require
does not work, and when talking to dawehner definingtest_dependency
will not work until we tag a release.Comment #38
mglamanI'm fine adding this as a dev dependency. This is really just a development module, anyways.
Comment #39
willeaton CreditAttribution: willeaton commentedReal life test seems to work. I see custom line items imported without issues! Ready for dev?
Comment #40
heddnNit: probably should be ^ instead of ~.
Nit: could this use a data provider?
Why are we testing this in two places? Isn't a single place enough?
Comment #41
quietone CreditAttribution: quietone at Acro Commerce commented1.Fixed
2. No, don't think so. Discussed this on IRC and we agree that dataproviders are useful, and preferred, but the don't really suite the migration environment and will make it difficult to find what item is causing the error. However, we should have a follow up to add the adjustments and cc_data to the assertOrder method. The adjusments aren't tested in commerce, so we can deal with all that in the followup.
3. Because 'test all the things'. And, the fixtures change over time, we should continue to confirm that the adjusment is correct.
Comment #42
quietone CreditAttribution: quietone at Acro Commerce commentedFollow up added, #2901409: Add adjustments and data to assertOrder test
Comment #43
heddnThat's a little strange. Back in #37, there's a testOrder method. But it isn't there in #41. Did we drop something?
Comment #44
quietone CreditAttribution: quietone at Acro Commerce commentedWe didn't drop anything. The original OrderTest::testOrder is still there and so is the new on OrderShippingTest::testOrder. I double checked and applied the patch.
Comment #45
heddnA comment about why if commerce shipping is installed we assume that the line item is a shipping would be helpful. There are non-shipping line items too, so documenting why we can safely assume all line items are shipping would be good. Or even better, do it in both places and improve the comment in Order::prepareRow().
I see why I didn't see the testOrder method. Git thought this was a copy.
I don't see this module listed as a test dependency in composer.json
I see this coming through in the fixture, but I don't see where we test the default currency code of USD coming from . I don't see test coverage of this. All the scenarios use NZD.
Comment #46
quietone CreditAttribution: quietone at Acro Commerce commented1. Not really sure about this. I implement what @mglaman suggested in #5
2. Oh yes, I copied it.
3. It is a dependency of commerce_shipping, doesn't composer pick that up from the commerce_shipping composer.json?
4. To test the default currency the source db needs to be modified. Is this necessary? I don't recall this being done in core for all the variable defaults.
Comment #47
heddnHmm, so what if our process plugin to create the adjustment also accepted the adjustment type? Then in the source we set the type to shipping or custom. Then the process plugin is more reusable.
Comment #48
quietone CreditAttribution: quietone at Acro Commerce commentedStart with a reroll.
Comment #49
quietone CreditAttribution: quietone at Acro Commerce commentedImplemented suggested changes in #47.
Comment #50
heddnSo, we have
'type', 'title', 'amount', 'currency_code'
in a nested array. If we want to make this process plugin re-usable for any and all line items, not just uc6, are those the best key names? They seem ok to me.So, the last thing then is to move this up to commerce_migrate as a re-usable process plugin. Naming... what about 'commerce_adjustments' / CommerceAdjustments? Plural because it seems to return an array of adjustments.
Some type of comment to the effect that by default the destination has custom adjustments in core and shipping if shipping module is enabled. But other adjustment types are possible, just not bundled with the vanilla migration. Maybe @mglaman can comment here with some better wording. For example from the IS, tax are also an adjustment. Are we just mapping them to custom? That seems strange.
Comment #51
mglamanYes, here are the keys defined for adjustment value object: https://github.com/drupalcommerce/commerce/blob/8.x-2.x/modules/order/sr...
Adjustment mapping:
Taxes were never line items in 1.x; not sure Ubercart. In Ubercart and 1.x shipping is a line item, which we can and should migrate to
shipping
adjustment type. Anythign non-product should be custom for now. People can run alters to say "fee" or whatever else.Comment #52
mglamanActually. There's a new curveball here for shipping line items.
We need shipping line items to migrate to a shipment entity; which will cause the shipping adjustment to populate. Otherwise, if the order is refreshed, all adjustments not "custom" will be removed.
Confirmed with bojanz.
I'm not sure where to go. Perhaps we need a deriver which creates migrations per line item type discovered? Like the Node migration does. And have shipping line items go off and create shipment entities. This is where I'm not sure.
Comment #53
quietone CreditAttribution: quietone at Acro Commerce commentedFinally, getting back to this.
I think that means that that each line item where the type and title form a unique set get migrated to a 'something'. I say 'something' because if type = 'shipping' then I am guessing it will always (?) be migrated to a shipping method. Then if type = 'tax' then it gets migrated to a tax type?, not sure about that.
I don't think this will work. Let's use shipping as the example. The uc_order_line_item contains the type (shipping) and the title (Acme transport). That isn't sufficient to determine the shipping plugin to use. At least this is true for Flat Rate service, which is the only shipping service I've explored. Maybe this is doable for many 'standard' services where perhaps a static map could be used to determine the plugin? Would that work? Possibly not as both the type field and title field are alterable by the user.
In the meantime, I've made migrations for the Flat Rate service for both Ubercart 6 and Commerce 1. I've yet to try them out with the patch here which surely needs a reroll.
Comment #54
quietone CreditAttribution: quietone at Acro Commerce commentedRerolled but it will fail tests.
Comment #56
quietone CreditAttribution: quietone at Acro Commerce commentedTried that anyway and turns out the shipment needs the order_id and it is a required field.
Required shipment field "order_id" is empty.
So, migrate the non shipping line items, then migrate the order, and the migrate shipping line items? Or can the shipping information be included in the order migration and will that automatically create the shipment entity?
Comment #57
quietone CreditAttribution: quietone at Acro Commerce commentedHow does this happen in Commerce 2? What does one due to create a shipment entity? I was thinking this might happen if a flat rate service was to be applied to all orders but the shipping is never applied to the order. The order type is 'default' and set to shippable as are all the product variations.
Comment #58
joachim CreditAttribution: joachim at Torchbox commented> How does this happen in Commerce 2? What does one due to create a shipment entity? I
That is a really good question!
I've just spent 5-10 minutes going through the code of the Commerce Shipping module, and I can't find where the shipment entities are actually created! The only call to create() I can see is in PackManager::packToShipments(), but that gets the shipments already in the order... I suspect that the first time that's called, the shipments array from the order is empty, and it's designed so that subsequent calls re-pack the order.
In which case, the creation of shipments is done when the ShippingInformation pane form is loaded.
If that doesn't happen (because we're migrating orders so the checkout UI isn't loaded), the subsequent order refresh calls to ShipmentOrderProcessor will have no effect, because that has a guard clause to check whether the order has any shipments at all.
So I reckon that during a migration, no shipment entities will be created.
Comment #59
heddnThe code to add a shipment is scattered all over. I had to pull it all together over in #2961463: Multiple destination shipping though, so you should see a manual way to pull it all together. Specifically,
MultipleDestinationsForm:submitForm()
. One thing of note, the ShippingOrderProcessor hasshouldRepack()
. This checks if 'owned_by_packer' is set. I think in our case, we don't want it set, but we do want to make sure payments are added on re-processing. We just don't want the packer to do it.Comment #60
quietone CreditAttribution: quietone at Acro Commerce commentedNeeded a reroll.
Comment #62
quietone CreditAttribution: quietone at Acro Commerce commentedThis was all about getting the test to pass. The adjustments array has been removed for assertOrder since the adjustment is an object containing another object as well, the price, the assertSame didn't like it. Asserting the adjustments is done separately now. Since the assertion on the adjustment has been removed from assertOrder the other usages needed to be changed as well.
Comment #64
quietone CreditAttribution: quietone at Acro Commerce commentedRework the way the adjustment type is chosen in the source plugin and then updated the source plugin accordingly. The source plugin now gets the status of commerce_shipping module once and then only tests if 'shipping' needs to be changed to custom if the type is 'shipping'.
Also removed OrderShippingTest, it appears to be the start of a test to check just shipping and that idea isn't needed, we can test the adjustments in the order.
Comment #65
quietone CreditAttribution: quietone at Acro Commerce commentedinsert a blank line
I don't think the points in #50 and #51 have been addressed.
Comment #66
heddnBack to NW for #50/#51/#59
Comment #67
quietone CreditAttribution: quietone at Acro Commerce commentedThe addresses #50 and #51. The process plugin has been moved to commerce_migrate and comment slightly improved in the Order source plugin.
Comment #69
quietone CreditAttribution: quietone at Acro Commerce commentedStarting over, beginning with a reroll of the patch in #64.
Comment #71
quietone CreditAttribution: quietone at Acro Commerce commentedOdd, that one line didn't get updated in the reroll process.
Comment #72
quietone CreditAttribution: quietone at Acro Commerce commentedReapply the fixes for #50 and #51 from #67.
Comment #73
quietone CreditAttribution: quietone at Acro Commerce commentedThe interdiff for the above patch
Comment #74
quietone CreditAttribution: quietone at Acro Commerce commentedUpdate the IS
Comment #75
quietone CreditAttribution: quietone at Acro Commerce commentedNow address #59 by suggesting that shipping be done in a follow up.
This patch adds tax line items and a 'service charge' line item and migrates them as part of the order. The order tests are updated to test these adjustments.
Comment #76
quietone CreditAttribution: quietone at Acro Commerce commentedSome cleanup.
Comment #77
quietone CreditAttribution: quietone at Acro Commerce commentedFollow up made to handle shipping line items. #2992272: Migrate shipping line items to order adjustments
Comment #78
heddnLooks good now.
Comment #79
quietone CreditAttribution: quietone at Acro Commerce commentedSweet! 'Tis a day when some good news is needed too, extra bonus for that.
Comment #80
quietone CreditAttribution: quietone at Acro Commerce commentedNeeds reroll
Comment #82
quietone CreditAttribution: quietone at Acro Commerce commentedLooks like I missed a file in that patch.
Comment #83
quietone CreditAttribution: quietone at Acro Commerce commentedTests passing, since this was just a reroll setting back to RTBC.
Comment #85
quietone CreditAttribution: quietone at Acro Commerce commentedThanks everyone!