diff --git a/modules/ubercart/src/Plugin/migrate/source/d6/Order.php b/modules/ubercart/src/Plugin/migrate/source/d6/Order.php index 223e8d9..c3ad717 100644 --- a/modules/ubercart/src/Plugin/migrate/source/d6/Order.php +++ b/modules/ubercart/src/Plugin/migrate/source/d6/Order.php @@ -19,16 +19,24 @@ class Order extends DrupalSqlBase { * {@inheritdoc} */ public function query() { - $query = $this->select('uc_orders', 'uo') - ->fields('uo'); - return $query; + return $this->select('uc_orders', 'uo') + ->fields('uo', [ + 'order_id', + 'uid', + 'order_status', + 'primary_email', + 'host', + 'data', + 'created', + 'modified', + ]); } /** * {@inheritdoc} */ public function fields() { - $fields = [ + return [ 'order_id' => $this->t('Order ID'), 'uid' => $this->t('User ID of order'), 'order_status' => $this->t('Order status'), @@ -37,9 +45,8 @@ class Order extends DrupalSqlBase { 'data' => $this->t('Order attributes'), 'created' => $this->t('Date/time of order creation'), 'modified' => $this->t('Date/time of last order modification'), + 'order_item_id' => $this->t('Order item IDs'), ]; - - return $fields; } /** @@ -55,6 +62,7 @@ class Order extends DrupalSqlBase { unset($data['cc_data']); $row->setSourceProperty('data', $data); + // Puts product order ids for this order in the row. $order_id = $row->getSourceProperty('order_id'); $query = $this->select('uc_order_products', 'uop') ->fields('uop', ['order_product_id']) diff --git a/modules/ubercart/tests/src/Kernel/Plugin/migrate/source/d6/OrderTest.php b/modules/ubercart/tests/src/Kernel/Plugin/migrate/source/d6/OrderTest.php new file mode 100644 index 0000000..3dc5db7 --- /dev/null +++ b/modules/ubercart/tests/src/Kernel/Plugin/migrate/source/d6/OrderTest.php @@ -0,0 +1,185 @@ + '1', + 'uid' => '2', + 'order_status' => 'payment_received', + 'order_total' => '22.99000', + 'product_count' => '2', + 'primary_email' => 'f.bar@example.com', + 'delivery_first_name' => '', + 'delivery_last_name' => '', + 'delivery_phone' => '', + 'delivery_company' => '', + 'delivery_street1' => '', + 'delivery_street2' => '', + 'delivery_city' => '', + 'delivery_zone' => '', + 'delivery_postal_code' => '', + 'delivery_country' => '', + 'billing_first_name' => 'Foo', + 'billing_last_name' => 'Bar', + 'billing_phone' => '123-4567', + 'billing_company' => 'Acme', + 'billing_street1' => '1 Coyote Way', + 'billing_street2' => 'Utah', + 'billing_city' => 'Salt Lake', + 'billing_zone' => '58', + 'billing_postal_code' => '11111', + 'billing_country' => '840', + 'payment_method' => 'cod', + 'data' => 'a:0:{}', + 'created' => '1492868907', + 'modified' => '1498620003', + 'host' => '192.168.0.2', + 'currency' => 'USD', + ], + [ + 'order_id' => '2', + 'uid' => '2', + 'order_status' => 'payment_received', + 'order_total' => '22.99000', + 'product_count' => '2', + 'primary_email' => 'f.bar@example.com', + 'delivery_first_name' => '', + 'delivery_last_name' => '', + 'delivery_phone' => '', + 'delivery_company' => '', + 'delivery_street1' => '', + 'delivery_street2' => '', + 'delivery_city' => '', + 'delivery_zone' => '', + 'delivery_postal_code' => '', + 'delivery_country' => '', + 'billing_first_name' => 'Foo', + 'billing_last_name' => 'Bar', + 'billing_phone' => '555-4567', + 'billing_company' => 'Acme', + 'billing_street1' => '1 Coyote Way', + 'billing_street2' => 'Utah', + 'billing_city' => 'Salt Lake', + 'billing_zone' => '58', + 'billing_postal_code' => '11111', + 'billing_country' => '840', + 'payment_method' => 'cod', + 'data' => 'a:0:{}', + 'created' => '1492868907', + 'modified' => '1498630003', + 'host' => '192.168.0.2', + 'currency' => 'USD', + ], + ]; + $tests[0]['source_data']['uc_order_products'] = + [ + [ + 'order_product_id' => '1', + 'order_id' => '1', + 'nid' => '1', + 'title' => 'Product 1', + 'manufacturer' => 'Someone', + 'model' => 'Product 1 - 001', + 'qty' => '2', + 'cost' => '500.00000', + 'price' => '600.00000', + 'weight' => '2', + 'data' => 'a:2:{s:9:"shippable";s:1:"1";s:6:"module";s:10:"uc_product";}', + ], + [ + 'order_product_id' => '3', + 'order_id' => '1', + 'nid' => '4', + 'title' => 'Towel', + 'manufacturer' => 'Acme', + 'model' => 'Towel - 001', + 'qty' => '2', + 'cost' => '500.00000', + 'price' => '600.00000', + 'weight' => '2', + 'data' => 'a:2:{s:9:"shippable";s:1:"1";s:6:"module";s:10:"uc_product";}', + ], + [ + 'order_product_id' => '4', + 'order_id' => '1', + 'nid' => '3', + 'title' => 'Babel fish', + 'manufacturer' => 'Someone', + 'model' => 'Bable fish - 001', + 'qty' => '2', + 'cost' => '500.00000', + 'price' => '600.00000', + 'weight' => '2', + 'data' => 'a:2:{s:9:"shippable";s:1:"1";s:6:"module";s:10:"uc_product";}', + ], + [ + 'order_product_id' => '9', + 'order_id' => '2', + 'nid' => '5', + 'title' => 'Cake', + 'manufacturer' => 'Someone', + 'model' => 'Cake - 001', + 'qty' => '2', + 'cost' => '500.00000', + 'price' => '600.00000', + 'weight' => '2', + 'data' => 'a:2:{s:9:"shippable";s:1:"1";s:6:"module";s:10:"uc_product";}', + ], + ]; + // The expected results. + $tests[0]['expected_data'] = + [ + [ + 'order_id' => '1', + 'uid' => '2', + 'order_status' => 'payment_received', + 'primary_email' => 'f.bar@example.com', + 'data' => [], + 'created' => '1492868907', + 'modified' => '1498620003', + 'host' => '192.168.0.2', + 'order_item_ids' => [1, 3, 4], + ], + [ + 'order_id' => '2', + 'uid' => '2', + 'order_status' => 'payment_received', + 'primary_email' => 'f.bar@example.com', + 'data' => [], + 'created' => '1492868907', + 'modified' => '1498630003', + 'host' => '192.168.0.2', + 'order_item_ids' => [9], + ], + ]; + return $tests; + } + +}