Zen and the art of Commerce Migrations – BADCamp eCommerce Summit 2013 – Analyze Source Data



Zen and the art of Commerce Migrations – BADCamp eCommerce Summit 2013 – Analyze Source Data

0 0


badcamp2013-commerce-migrate


On Github andyg5000 / badcamp2013-commerce-migrate

Zen and the art of Commerce Migrations

BADCamp eCommerce Summit 2013

Pick on Ryan for the cheesy name. (Finding zen in migrations) Talk about boring subject and time Homestretch before beer (or more beer).

Andy Giles

History

  • Web Developer and Systems Administrator
  • Working with Drupal for around 5 years

Blue Oak Interactive

blueoakinteractive.com

  • Working on Drupal exclusively
  • Drupal Commerce custom integrations
Commerce is what got me into contributing back to the community

Commerce Experience

  • Drupal Commerce for 2 years
  • Shipping and payment gateway integrations

Drupal Commerce Migration Experience

  • OSCommerce
  • Ubercart & D2D
  • Flat file
  • MSSQL
Thank Ryan, Josh, and Bojan Z for all of their help in various channels (irc, twitter, etc) Custom modules (Litle payment gateway, Stamps.com) Sandbox is 2 years and 2 days old

Migrate module

Migration base claseses

  • Sources
  • Destinations
  • Field mappings
  • Migration maps
  • Source ID (primary keys)
  • Destination ID (primary keys)

Import/Rollback

Talk about module (made up of a series of inheritable classes.) Source classes (mysql, mssql, oracle) Destination classes (drupal entities) Field mappings Migration Maps

Analyze Source Data

Data objects/tables

  • Tables and relations
    • Users
    • Products
    • Orders
    • Line Items

GO DOWN!

Typical and simplistic (denormalized) source storage. Select the correct tables (ie: UC shipping quotes!) Document the primary keys (LOOK OUT FOR multi-valued keys)

Plan Destination Data

Entities

  • Users
  • Files/Images
  • Products & Display Nodes
  • Profiles
  • Orders
  • Line Items
    • Product
    • Shipping
    • Coupon/Discount
    • Tax
  • Payment Transactions
Explain process... Select chickens and eggs Explain linear dependancy approach that I typically take

Select and Start With Helpers

  • Migrate extras
  • Commerce migrate
  • Date Migrate
  • Commerce Migrate Ubercart
  • Custom source and destination handlers
These modules help extend migrate classes Migrate Extras (field handlers like addressfield) Commerce migrate (field handlers like commerce_price) Date formatting Commerce migrate ubercart as an example and gotchas.

Abstract Base Class

Common settings and logic for all migrations

  • Common field mappings
  • Source conntection
  • Normalization and cleanup functions
  • Datatype conversion
  • Data mapping

GO DOWN!

Into to class structure (base > entity > bundle) Abstract base class defines resources that all migrations will inherit.

Abstract Entity Classes

Settings and logic specific to the entity

  • Common fields on all entities (ie: node->title).
  • Common mappings for entity (ie: product->commerce_price)

GO DOWN!

Abstract entity classes provide specific items like common field mappings

Bundle Class

Settings and logic for this bundle

  • Build migrate map, source, destination, and field mappings
  • Field Mappings
  • Source Migrations
  • Process
    • _construct()
    • prepareRow()
    • prepare()
    • complete()
_construct to set up asource, destintion, and field mappings prepareRow() alters the source data before mappings prepare() before entity is saved complete() after entity is saved

Edge Cases

  • User dedupe and matching
  • Normalization
  • Dealing with raw user input
  • SELECT DISTICT From Source and create maps.
  • ->separator(',')
  • Duplicate source records
  • Files in volume!
  • Dates
Order tables with everything crammed into them (shipping, billing) Data comming in as a CSV row

Commerce Tidbits of Joy and Misery

  • Migrating order entity first resets order total to 0 (@see order.inc)
  • Line items entities and order line item reference fields
  • Load product by SKU
  • Field mappings for commerce customer address (addressfield)
  • includes/iso.inc and _country_get_predefined_list()

GO DOWN!

Common Problems

  • HOOKS! node_update
  • No line items on order
  • $0 order total
  • Compounding line items price on order total
  • Line items without products

Thank You

BOF @ Sports bar to watch TNF