I'm pretty sure we'll need to bring over customer payment history if we can.

Comments

rfay’s picture

Title: Capture customer payment history » Capture customer purchase/payment history
mariagwyn’s picture

Is there any planned movement on this?
Maria

rfay’s picture

Orders and customer profiles are brought over, but payments are not.

No, there is no current active work here.

rfay’s picture

Project: Commerce Migrate » Commerce Migrate Ubercart
Component: Commerce Migrate Ubercart » Code
marcus178’s picture

Has anyone had any luck with sorting this out. Is it a case of mapping uc_payment_receipts to commerce_payment_transaction or is it more complicated than that?

andyg5000’s picture

Status: Active » Needs review
StatusFileSize
new3.23 KB

Here's a patch that adds a Payment Transaction migration class to this module. It will create a successful payment transaction on the source order with the amount, data array, message, created/updated date and uid (if source exists). The method of the transaction will show up as unknown, but you can extend the class to provide the current instance id of your configured Commerce payment method.

torgospizza’s picture

Awesome, Andyg. I'll test this out ASAP.

Anonymous’s picture

Priority: Normal » Major
Issue summary: View changes

This is something I would like to add to the 2.x branch. Setting it as a high priority.

If anyone wants to test with 2.x please do and then update the version string with your notes.

mrconnerton’s picture

Version: 7.x-1.x-dev » 7.x-2.0

The patch doesn't apply to 2.x. I'm working on it now. It should convert pretty easy.

Anonymous’s picture

Excellent, if you have any troubles let me know. Please post it when you can! I will make it a priority to update the module.

mrconnerton’s picture

Here is an updated patch. I'm sure this can be improved but its a good starting point.

kenorb’s picture

Some other example:

// File: example_migrate_ubercart.module
/**
 * Implements hook_flush_caches().
 */
function example_migrate_ubercart_flush_caches() {
  Migration::registerMigration('CommerceMigrateUbercartTransaction', 'CommerceMigrateUbercartTransaction');
}
// File: example_migrate_ubercart.migrate.inc
class CommerceMigrateUbercartTransaction extends MigrateExampleMigration {
  public function __construct(array $arguments) {
    parent::__construct($arguments);
    $this->description = t('Import payment transactions from Ubercart.');
    $this->orderSourceMigration = 'CommerceMigrateUbercartOrder';
    $this->dependencies = array('CommerceMigrateUbercartOrder');

    // Create a map object for tracking the relationships between source rows
    $this->map = new MigrateSQLMap($this->machineName,
        array(
          'receipt_id' => array(
            'type' => 'int',
            'unsigned' => TRUE,
            'not null' => TRUE,
            'description' => 'Ubercart receipt ID',
          ),
        ),
        MigrateDestinationEntityAPI::getKeySchema('commerce_payment_transaction')
      );

    // Create a MigrateSource object, which manages retrieving the input data.
    $query =
      Database::getConnection('default', 'migrate')
      ->select('uc_payment_receipts', 'r')
      ->fields('r', array(
        'receipt_id',
        'order_id',
        'method',
        'amount',
        'uid',
        'data',
        'comment',
        'received',
      ));

    $query->innerJoin('uc_orders', 'uo', 'uo.order_id = r.order_id');
    $query->fields('uo', array(
        'currency',
        'payment_method',
        'order_status',
      ))
      ->condition('uo.order_status', 'in_checkout', '<>');

    // $query->condition('uo.order_id', 10000100, '<'); // Debug: Test small amount first.


    $this->source      = new MigrateSourceSQL($query, array(), NULL, array('map_joinable' => FALSE));
    $this->destination = new MigrateDestinationEntityAPI('commerce_payment_transaction', 'payment');

    // Add field mapping
    $this->addFieldMapping('uid', 'uid')->sourceMigration('ExampleUser');
    $this->addFieldMapping('order_id', 'order_id');
    $this->addFieldMapping('message_variables', 'message_variables');
    $this->addFieldMapping('message', 'comment');
    $this->addFieldMapping('amount', 'amount');
    $this->addFieldMapping('status', 'status');
    $this->addFieldMapping('created', 'received');
    $this->addFieldMapping('changed', 'received');
    $this->addFieldMapping('data', 'data');
    // Order related fields
    $this->addFieldMapping('currency_code', 'uo.currency');
    $this->addFieldMapping('payment_method', 'payment_method');

    // @NOTE: Cannot map this fields.
    $this->addUnmigratedDestinations(array(
      'transaction_id',
      'instance_id',
      'remote_id',
      'remote_status',
      'payload',
    ));

    // Temporary disable consumer key and secret to prevent Salesforce module of pushing any data into SFDC during the migration.
    if (module_exists('salesforce_push')) {
      global $conf;
      $conf['salesforce_consumer_key'] = '';
      $conf['salesforce_consumer_secret'] = '';
    }
  }

  public function prepareRow($row) {
    if (parent::prepareRow($row) === FALSE) {
      watchdog('Migrate', 'Skipped import due to FALSE return at prepareRow(): @row', array('@row' => json_encode($row)), WATCHDOG_ERROR);
      return FALSE;
    }

    // The sourceMigration returns order_id and revions_id. We only need the
    // order id, so we call the source migration manually.
    $order = $this->handleSourceMigration($this->orderSourceMigration, $row->order_id);

    // Don't create a transaction if we can't load the order.
    if (empty($order['destid1'])) {
      watchdog('Migrate', 'Skipped import due to missing order @id: @row', array('@id' => $row->order_id, '@row' => json_encode($row)), WATCHDOG_ERROR);
      return FALSE;
    }

    $row->order_id = $order['destid1'];
  }

  public function prepare($transaction, stdClass $row) {
    $transaction->amount            = commerce_currency_decimal_to_amount($row->amount, commerce_default_currency());
    $transaction->status            = COMMERCE_PAYMENT_STATUS_SUCCESS;
    $transaction->data              = unserialize($row->data);
    $transaction->message           = $row->comment;
    $transaction->message_variables = array();
    switch ($row->payment_method) { // See: drush eval "var_dump(array_keys(commerce_payment_methods()));"
      case 'uc_test_payment':
        $transaction->payment_method = 'commerce_payment_example'; // Demonstrates credit card payment during checkout and serves as a development example.
        break;
      case 'free_order':
        $transaction->payment_method = 'payment_commerce_2'; // No payment required (testing purposes only) (Payment)
        break;
      case 'uc_sagepayserver':
        $transaction->payment_method = 'commerce_sagepay_server'; // SagePay (also: commerce_sagepay_direct)
        break;
    }
  }
}

Hope it could be useful.

Anonymous’s picture

Status: Needs review » Fixed

Works pretty well, thank you! I committed it to the dev branch today at DrupalCon!

I went with @mrconnerton's patch as it was ready to go and seemed to work OK. If there are additional details to deal with, or additional things from @kenorb's code, please create a new issue and ideally roll a patch against the dev branch. Thanks folks, I'm really happy to have finally committed this!

  • Commit c7f0c25 on 7.x-2.x authored by mrconnerton, committed by Ryan Weal:
    Issue #1211024 by mrconnerton: Capture customer purchase/payment history
    

Status: Fixed » Closed (fixed)

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

webdrips’s picture

Status: Closed (fixed) » Active

It would appear the patch above never actually made it into the dev branch.

kenorb’s picture

Status: Active » Needs review
mrconnerton’s picture

Status: Needs review » Closed (fixed)