I'm in the process of creating a migrate example. The first version is attached, but it's not quite ready for review, as it doesn't create product display nodes yet. I hope to do that tomorrow.

This example takes a CSV file and populates products with it. It can handle images that are either external or local.

The file handling is actually placed in the main module (it's cribbed from Feeds). I think we can probably use it more generally.

Comments

bojanz’s picture

The custom file function, does it do anything that the MigrateFileFieldHandler class doesn't?
I only glanced at this, so they actually might be doing two completely different things, but it's worth checking out.

I've given you commit access to the project.

rfay’s picture

Here's the working version that does products and display nodes.

The intention is to teach, not to provide a useful migration.

I am absolutely certain that something better can be done with the file stuff. And since I didn't even know about MigrateFileFieldHandler I'll have to learn something :-)

What kind of sucker do you think I am, just giving me commit access :-)

bojanz’s picture

What kind of sucker do you think I am, just giving me commit access :-)

Just didn't want you to be blocked by my lack of time for this project :)

I'll try to do an indepth review as soon as possible.

rfay’s picture

:-)

I'm well aware of the key places you're taking care of far more significant modules than this one, and it's *very* much appreciated.

joachim’s picture

Status: Needs review » Needs work
+++ b/commerce_migrate_example/commerce_migrate_example.migrate.inc
@@ -0,0 +1,175 @@
+      // Rather than specifying the type directly here, we would probably use
+      // arguments, but instead this just specifies the 'product' product type
+      // to make it obvious what's going on.
+      MigrateDestinationNode::getKeySchema()

Comment doesn't match up with code here.

Also, 'type' destination should be set on the product entity, as Migrate will complain it's not mapped to -- not sure what to though, see here: #1650850: product entity has superflous destination fields.

adrupaler’s picture

I have some custom fields in my "product" type. how should I add them in the columns of the CSV file?
I will really appreciate for some help or advice on mapping custom fields of "product" type. maybe one solution is use of PrepareRow or Prepare function.

mglaman’s picture

Issue summary: View changes
Issue tags: +Commerce Sprint
smccabe’s picture

StatusFileSize
new10.68 KB

Did a bunch of cleanup and some additional work on this. Still needs more work but this is a bunch farther along.

smccabe’s picture

StatusFileSize
new11.26 KB

Aight, the example works now, nothing flashy but it will link up the product and product display, set the pricing, etc.

smccabe’s picture

Status: Needs work » Needs review
StatusFileSize
new12.04 KB

Same as above but with some sample images setup, not sure which way is preferred.

mglaman’s picture

Status: Needs review » Reviewed & tested by the community

Looks good. This example should help others along the way. I had to base my examples off of CK2, nice to have a simpler one.

EDIT: smccabe will need to upload patch with --binary in order to properly commit, FYI.

smccabe’s picture

StatusFileSize
new304.02 KB

Binary version attached

mglaman’s picture

Status: Reviewed & tested by the community » Fixed

w00t committed.

  • mglaman committed fb880f0 on 7.x-1.x authored by smccabe
    Issue #1202010 by smccabe, rfay, bojanz, mglaman: Create Commerce...

Status: Fixed » Closed (fixed)

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

firfin’s picture

Is there an example (or documentation) how to create a custom migration (into commerce 2) for drupal 8 using yaml files?

bojanz’s picture

firfin’s picture

Thanks @bojanz, but that link was more a tutorial on a custom migration. Not very specific to commerce IMHO.
I found this one more informative https://github.com/mglaman/commerce_demo/tree/master/migrations
But most important was the realization, that you have to migrate the variations first and the products second, still seems strange to me. Wish I knew that hours ago ;-)