|
@@ -39,7 +39,18 @@ class Magento1OrderReader
|
|
|
'base_shipping_tax_amount',
|
|
'base_shipping_tax_amount',
|
|
|
'shipping_method',
|
|
'shipping_method',
|
|
|
'shipping_description',
|
|
'shipping_description',
|
|
|
|
|
+ 'shipping_discount_amount',
|
|
|
|
|
+ 'base_shipping_discount_amount',
|
|
|
|
|
+ 'remote_ip',
|
|
|
|
|
+ 'x_forwarded_for',
|
|
|
'coupon_code',
|
|
'coupon_code',
|
|
|
|
|
+ 'giftcard_id',
|
|
|
|
|
+ 'giftcard_amount',
|
|
|
|
|
+ 'base_giftcard_amount',
|
|
|
|
|
+ 'member_amount',
|
|
|
|
|
+ 'base_member_amount',
|
|
|
|
|
+ 'member_free_amount',
|
|
|
|
|
+ 'base_member_free_amount',
|
|
|
'mw_rewardpoint',
|
|
'mw_rewardpoint',
|
|
|
'mw_rewardpoint_discount',
|
|
'mw_rewardpoint_discount',
|
|
|
'mw_rewardpoint_discount_show',
|
|
'mw_rewardpoint_discount_show',
|
|
@@ -100,6 +111,43 @@ class Magento1OrderReader
|
|
|
'discount_percent',
|
|
'discount_percent',
|
|
|
'weight',
|
|
'weight',
|
|
|
'row_weight',
|
|
'row_weight',
|
|
|
|
|
+ 'product_options',
|
|
|
|
|
+ 'created_at',
|
|
|
|
|
+ ];
|
|
|
|
|
+
|
|
|
|
|
+ private const SHIPMENT_COLUMNS = [
|
|
|
|
|
+ 'entity_id',
|
|
|
|
|
+ 'order_id',
|
|
|
|
|
+ 'increment_id',
|
|
|
|
|
+ 'total_qty',
|
|
|
|
|
+ 'total_weight',
|
|
|
|
|
+ 'email_sent',
|
|
|
|
|
+ 'customer_id',
|
|
|
|
|
+ 'created_at',
|
|
|
|
|
+ 'updated_at',
|
|
|
|
|
+ ];
|
|
|
|
|
+
|
|
|
|
|
+ private const SHIPMENT_ITEM_COLUMNS = [
|
|
|
|
|
+ 'entity_id',
|
|
|
|
|
+ 'parent_id',
|
|
|
|
|
+ 'order_item_id',
|
|
|
|
|
+ 'product_id',
|
|
|
|
|
+ 'sku',
|
|
|
|
|
+ 'name',
|
|
|
|
|
+ 'description',
|
|
|
|
|
+ 'qty',
|
|
|
|
|
+ 'weight',
|
|
|
|
|
+ 'price',
|
|
|
|
|
+ 'row_total',
|
|
|
|
|
+ ];
|
|
|
|
|
+
|
|
|
|
|
+ private const SHIPMENT_TRACK_COLUMNS = [
|
|
|
|
|
+ 'entity_id',
|
|
|
|
|
+ 'parent_id',
|
|
|
|
|
+ 'order_id',
|
|
|
|
|
+ 'track_number',
|
|
|
|
|
+ 'title',
|
|
|
|
|
+ 'carrier_code',
|
|
|
'created_at',
|
|
'created_at',
|
|
|
];
|
|
];
|
|
|
|
|
|
|
@@ -128,6 +176,10 @@ class Magento1OrderReader
|
|
|
'cc_last4',
|
|
'cc_last4',
|
|
|
'amount_ordered',
|
|
'amount_ordered',
|
|
|
'base_amount_ordered',
|
|
'base_amount_ordered',
|
|
|
|
|
+ 'additional_information',
|
|
|
|
|
+ 'protection_eligibility',
|
|
|
|
|
+ 'account_status',
|
|
|
|
|
+ 'address_status',
|
|
|
];
|
|
];
|
|
|
|
|
|
|
|
private Magento1Schema $schema;
|
|
private Magento1Schema $schema;
|
|
@@ -186,11 +238,100 @@ class Magento1OrderReader
|
|
|
$item['parent_item_id'] = isset($row->parent_item_id) && $row->parent_item_id !== null && $row->parent_item_id !== ''
|
|
$item['parent_item_id'] = isset($row->parent_item_id) && $row->parent_item_id !== null && $row->parent_item_id !== ''
|
|
|
? (int) $row->parent_item_id
|
|
? (int) $row->parent_item_id
|
|
|
: null;
|
|
: null;
|
|
|
|
|
+ $item['product_id'] = isset($row->product_id) && $row->product_id !== null && $row->product_id !== ''
|
|
|
|
|
+ ? (int) $row->product_id
|
|
|
|
|
+ : null;
|
|
|
|
|
+
|
|
|
|
|
+ return $item;
|
|
|
|
|
+ })->values();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * @param array<int, int> $itemIds
|
|
|
|
|
+ * @return Collection<int, array<string, mixed>>
|
|
|
|
|
+ */
|
|
|
|
|
+ public function fetchItemsByItemIds(array $itemIds): Collection
|
|
|
|
|
+ {
|
|
|
|
|
+ $itemIds = array_values(array_unique(array_filter(array_map('intval', $itemIds))));
|
|
|
|
|
+
|
|
|
|
|
+ if ($itemIds === []) {
|
|
|
|
|
+ return collect();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ $columns = $this->schema->existingColumns('sales_flat_order_item', self::ITEM_COLUMNS);
|
|
|
|
|
+
|
|
|
|
|
+ if ($columns === [] || ! in_array('item_id', $columns, true)) {
|
|
|
|
|
+ return collect();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ $rows = collect();
|
|
|
|
|
+
|
|
|
|
|
+ foreach (array_chunk($itemIds, 500) as $chunk) {
|
|
|
|
|
+ $rows = $rows->concat(
|
|
|
|
|
+ DB::connection($this->connection)
|
|
|
|
|
+ ->table('sales_flat_order_item')
|
|
|
|
|
+ ->whereIn('item_id', $chunk)
|
|
|
|
|
+ ->orderBy('item_id')
|
|
|
|
|
+ ->get($columns)
|
|
|
|
|
+ );
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return $rows->map(function ($row) {
|
|
|
|
|
+ $item = $this->toArray($row, 'item_id');
|
|
|
|
|
+ $item['order_id'] = (int) ($row->order_id ?? 0);
|
|
|
|
|
+ $item['parent_item_id'] = isset($row->parent_item_id) && $row->parent_item_id !== null && $row->parent_item_id !== ''
|
|
|
|
|
+ ? (int) $row->parent_item_id
|
|
|
|
|
+ : null;
|
|
|
|
|
+ $item['product_id'] = isset($row->product_id) && $row->product_id !== null && $row->product_id !== ''
|
|
|
|
|
+ ? (int) $row->product_id
|
|
|
|
|
+ : null;
|
|
|
|
|
|
|
|
return $item;
|
|
return $item;
|
|
|
})->values();
|
|
})->values();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * Magento catalog SKUs keyed by catalog_product_entity.entity_id.
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param array<int, int> $productIds
|
|
|
|
|
+ * @return array<int, string>
|
|
|
|
|
+ */
|
|
|
|
|
+ public function fetchCatalogSkus(array $productIds): array
|
|
|
|
|
+ {
|
|
|
|
|
+ $productIds = array_values(array_unique(array_filter(array_map('intval', $productIds))));
|
|
|
|
|
+
|
|
|
|
|
+ if ($productIds === [] || ! $this->schema->hasTable('catalog_product_entity')) {
|
|
|
|
|
+ return [];
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ $columns = $this->schema->existingColumns('catalog_product_entity', ['entity_id', 'sku']);
|
|
|
|
|
+
|
|
|
|
|
+ if ($columns === [] || ! in_array('entity_id', $columns, true) || ! in_array('sku', $columns, true)) {
|
|
|
|
|
+ return [];
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ $map = [];
|
|
|
|
|
+
|
|
|
|
|
+ foreach (array_chunk($productIds, 500) as $chunk) {
|
|
|
|
|
+ foreach (
|
|
|
|
|
+ DB::connection($this->connection)
|
|
|
|
|
+ ->table('catalog_product_entity')
|
|
|
|
|
+ ->whereIn('entity_id', $chunk)
|
|
|
|
|
+ ->get($columns) as $row
|
|
|
|
|
+ ) {
|
|
|
|
|
+ $sku = trim((string) ($row->sku ?? ''));
|
|
|
|
|
+
|
|
|
|
|
+ if ($sku === '') {
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ $map[(int) $row->entity_id] = $sku;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return $map;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* @param array<int, int> $orderEntityIds
|
|
* @param array<int, int> $orderEntityIds
|
|
|
* @return Collection<int, array<string, mixed>>
|
|
* @return Collection<int, array<string, mixed>>
|
|
@@ -288,6 +429,111 @@ class Magento1OrderReader
|
|
|
})->values();
|
|
})->values();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * @param array<int, int> $orderEntityIds
|
|
|
|
|
+ * @return Collection<int, array<string, mixed>>
|
|
|
|
|
+ */
|
|
|
|
|
+ public function fetchShipments(array $orderEntityIds): Collection
|
|
|
|
|
+ {
|
|
|
|
|
+ if ($orderEntityIds === [] || ! $this->schema->hasTable('sales_flat_shipment')) {
|
|
|
|
|
+ return collect();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ $columns = $this->schema->existingColumns('sales_flat_shipment', self::SHIPMENT_COLUMNS);
|
|
|
|
|
+
|
|
|
|
|
+ if ($columns === [] || ! in_array('order_id', $columns, true)) {
|
|
|
|
|
+ return collect();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ $rows = DB::connection($this->connection)
|
|
|
|
|
+ ->table('sales_flat_shipment')
|
|
|
|
|
+ ->whereIn('order_id', $orderEntityIds)
|
|
|
|
|
+ ->orderBy('entity_id')
|
|
|
|
|
+ ->get($columns);
|
|
|
|
|
+
|
|
|
|
|
+ return $rows->map(function ($row) {
|
|
|
|
|
+ $shipment = $this->toArray($row, 'entity_id');
|
|
|
|
|
+ $shipment['order_id'] = (int) ($row->order_id ?? 0);
|
|
|
|
|
+
|
|
|
|
|
+ return $shipment;
|
|
|
|
|
+ })->values();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * @param array<int, int> $shipmentIds
|
|
|
|
|
+ * @return Collection<int, array<string, mixed>>
|
|
|
|
|
+ */
|
|
|
|
|
+ public function fetchShipmentItems(array $shipmentIds): Collection
|
|
|
|
|
+ {
|
|
|
|
|
+ if ($shipmentIds === [] || ! $this->schema->hasTable('sales_flat_shipment_item')) {
|
|
|
|
|
+ return collect();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ $columns = $this->schema->existingColumns('sales_flat_shipment_item', self::SHIPMENT_ITEM_COLUMNS);
|
|
|
|
|
+
|
|
|
|
|
+ if ($columns === [] || ! in_array('parent_id', $columns, true)) {
|
|
|
|
|
+ return collect();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ $rows = collect();
|
|
|
|
|
+
|
|
|
|
|
+ foreach (array_chunk($shipmentIds, 500) as $chunk) {
|
|
|
|
|
+ $rows = $rows->concat(
|
|
|
|
|
+ DB::connection($this->connection)
|
|
|
|
|
+ ->table('sales_flat_shipment_item')
|
|
|
|
|
+ ->whereIn('parent_id', $chunk)
|
|
|
|
|
+ ->orderBy('entity_id')
|
|
|
|
|
+ ->get($columns)
|
|
|
|
|
+ );
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return $rows->map(function ($row) {
|
|
|
|
|
+ $item = $this->toArray($row, 'entity_id');
|
|
|
|
|
+ $item['parent_id'] = (int) ($row->parent_id ?? 0);
|
|
|
|
|
+ $item['order_item_id'] = isset($row->order_item_id) && $row->order_item_id !== null && $row->order_item_id !== ''
|
|
|
|
|
+ ? (int) $row->order_item_id
|
|
|
|
|
+ : null;
|
|
|
|
|
+
|
|
|
|
|
+ return $item;
|
|
|
|
|
+ })->values();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * @param array<int, int> $shipmentIds
|
|
|
|
|
+ * @return Collection<int, array<string, mixed>>
|
|
|
|
|
+ */
|
|
|
|
|
+ public function fetchShipmentTracks(array $shipmentIds): Collection
|
|
|
|
|
+ {
|
|
|
|
|
+ if ($shipmentIds === [] || ! $this->schema->hasTable('sales_flat_shipment_track')) {
|
|
|
|
|
+ return collect();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ $columns = $this->schema->existingColumns('sales_flat_shipment_track', self::SHIPMENT_TRACK_COLUMNS);
|
|
|
|
|
+
|
|
|
|
|
+ if ($columns === [] || ! in_array('parent_id', $columns, true)) {
|
|
|
|
|
+ return collect();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ $rows = collect();
|
|
|
|
|
+
|
|
|
|
|
+ foreach (array_chunk($shipmentIds, 500) as $chunk) {
|
|
|
|
|
+ $rows = $rows->concat(
|
|
|
|
|
+ DB::connection($this->connection)
|
|
|
|
|
+ ->table('sales_flat_shipment_track')
|
|
|
|
|
+ ->whereIn('parent_id', $chunk)
|
|
|
|
|
+ ->orderBy('entity_id')
|
|
|
|
|
+ ->get($columns)
|
|
|
|
|
+ );
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return $rows->map(function ($row) {
|
|
|
|
|
+ $track = $this->toArray($row, 'entity_id');
|
|
|
|
|
+ $track['parent_id'] = (int) ($row->parent_id ?? 0);
|
|
|
|
|
+
|
|
|
|
|
+ return $track;
|
|
|
|
|
+ })->values();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* @return array<string, mixed>
|
|
* @return array<string, mixed>
|
|
|
*/
|
|
*/
|