OrderPayment.php in Commerce Migrate 3.1.x
File
modules/ubercart/src/Plugin/migrate/source/OrderPayment.php
View source
<?php
namespace Drupal\commerce_migrate_ubercart\Plugin\migrate\source;
use Drupal\migrate\Row;
use Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase;
class OrderPayment extends DrupalSqlBase {
public function query() {
$query = $this
->select('uc_payment_receipts', 'upr')
->fields('upr');
$query
->innerJoin('uc_orders', 'uo', 'upr.order_id = uo.order_id');
$query
->orderBy('received');
$query
->orderBy('receipt_id');
if ($this
->getDatabase()
->schema()
->fieldExists('uc_orders', 'currency')) {
$query
->addField('uo', 'currency');
}
else {
$currency_code = $this
->variableGet('uc_currency_code', 'USD');
$query
->addExpression(':currency_code', 'currency', [
':currency_code' => $currency_code,
]);
}
return $query;
}
public function fields() {
$fields = [
'receipt_id' => $this
->t('Payment receipt ID'),
'order_id' => $this
->t('Order ID'),
'method' => $this
->t('Payment method'),
'amount' => $this
->t('Payment amount'),
'currency' => $this
->t('Currency'),
'refund_amount' => $this
->t('Refunded amount'),
'uid' => $this
->t('User ID of order'),
'data' => $this
->t('Payment data'),
'received' => $this
->t('Date/time of payment was received'),
'state' => $this
->t('State of the order'),
];
return $fields;
}
public function prepareRow(Row $row) {
$row
->setSourceProperty('data', unserialize($row
->getSourceProperty('data')));
}
public function getIds() {
return [
'receipt_id' => [
'type' => 'integer',
'alias' => 'upr',
],
];
}
}