|
@@ -20,6 +20,8 @@ class MigrateAsteriaOrdersCommandTest extends BagistoApiTestCase
|
|
|
|
|
|
|
|
private string $connection = 'asteria_test';
|
|
private string $connection = 'asteria_test';
|
|
|
|
|
|
|
|
|
|
+ private const MID = 881900000;
|
|
|
|
|
+
|
|
|
public function setUp(): void
|
|
public function setUp(): void
|
|
|
{
|
|
{
|
|
|
parent::setUp();
|
|
parent::setUp();
|
|
@@ -29,6 +31,7 @@ class MigrateAsteriaOrdersCommandTest extends BagistoApiTestCase
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
$this->seedRequiredData();
|
|
$this->seedRequiredData();
|
|
|
|
|
+ $this->forgetLeakedAsteriaOrders();
|
|
|
Cache::forget('migrate_asteria_orders_last_id');
|
|
Cache::forget('migrate_asteria_orders_last_id');
|
|
|
|
|
|
|
|
$this->sqlitePath = sys_get_temp_dir().'/asteria_order_cmd_'.uniqid('', true).'.sqlite';
|
|
$this->sqlitePath = sys_get_temp_dir().'/asteria_order_cmd_'.uniqid('', true).'.sqlite';
|
|
@@ -59,12 +62,12 @@ class MigrateAsteriaOrdersCommandTest extends BagistoApiTestCase
|
|
|
public function test_it_migrates_an_order_with_items_addresses_and_payment(): void
|
|
public function test_it_migrates_an_order_with_items_addresses_and_payment(): void
|
|
|
{
|
|
{
|
|
|
$customer = $this->createCustomer([
|
|
$customer = $this->createCustomer([
|
|
|
- 'email' => 'jane@example.com',
|
|
|
|
|
|
|
+ 'email' => 'mig-pk-jane@example.test',
|
|
|
'first_name' => 'Jane',
|
|
'first_name' => 'Jane',
|
|
|
'last_name' => 'Doe',
|
|
'last_name' => 'Doe',
|
|
|
- 'migrated_from_asteria_id' => 10,
|
|
|
|
|
|
|
+ 'migrated_from_asteria_id' => self::MID + 10,
|
|
|
]);
|
|
]);
|
|
|
- $product = $this->createSimpleProduct('WIG-001');
|
|
|
|
|
|
|
+ $product = $this->createSimpleProduct('AST-TEST-WIG-001');
|
|
|
|
|
|
|
|
$this->seedCompleteMagentoOrder();
|
|
$this->seedCompleteMagentoOrder();
|
|
|
|
|
|
|
@@ -73,13 +76,15 @@ class MigrateAsteriaOrdersCommandTest extends BagistoApiTestCase
|
|
|
'--reset-progress' => true,
|
|
'--reset-progress' => true,
|
|
|
])->assertSuccessful();
|
|
])->assertSuccessful();
|
|
|
|
|
|
|
|
- $order = Order::query()->where('increment_id', '100000010')->first();
|
|
|
|
|
|
|
+ $order = Order::query()->where('increment_id', 'T881900010')->first();
|
|
|
$this->assertNotNull($order);
|
|
$this->assertNotNull($order);
|
|
|
- $this->assertSame(10, (int) $order->migrated_from_asteria_id);
|
|
|
|
|
|
|
+ $this->assertSame(self::MID + 10, (int) $order->id);
|
|
|
|
|
+ $this->assertSame(self::MID + 10, (int) $order->migrated_from_asteria_id);
|
|
|
|
|
+ $this->assertSame((int) $order->id, (int) $order->migrated_from_asteria_id);
|
|
|
$this->assertSame(Order::STATUS_COMPLETED, $order->status);
|
|
$this->assertSame(Order::STATUS_COMPLETED, $order->status);
|
|
|
$this->assertSame((int) $customer->id, (int) $order->customer_id);
|
|
$this->assertSame((int) $customer->id, (int) $order->customer_id);
|
|
|
$this->assertSame(0, (int) $order->is_guest);
|
|
$this->assertSame(0, (int) $order->is_guest);
|
|
|
- $this->assertSame('jane@example.com', $order->customer_email);
|
|
|
|
|
|
|
+ $this->assertSame('mig-pk-jane@example.test', $order->customer_email);
|
|
|
$this->assertEquals(110, (float) $order->grand_total);
|
|
$this->assertEquals(110, (float) $order->grand_total);
|
|
|
$this->assertEquals(100, (float) $order->sub_total);
|
|
$this->assertEquals(100, (float) $order->sub_total);
|
|
|
$this->assertEquals(10, (float) $order->shipping_amount);
|
|
$this->assertEquals(10, (float) $order->shipping_amount);
|
|
@@ -87,7 +92,7 @@ class MigrateAsteriaOrdersCommandTest extends BagistoApiTestCase
|
|
|
|
|
|
|
|
$item = OrderItem::query()->where('order_id', $order->id)->first();
|
|
$item = OrderItem::query()->where('order_id', $order->id)->first();
|
|
|
$this->assertNotNull($item);
|
|
$this->assertNotNull($item);
|
|
|
- $this->assertSame('WIG-001', $item->sku);
|
|
|
|
|
|
|
+ $this->assertSame('AST-TEST-WIG-001', $item->sku);
|
|
|
$this->assertSame('Lace Wig', $item->name);
|
|
$this->assertSame('Lace Wig', $item->name);
|
|
|
$this->assertSame((int) $product->id, (int) $item->product_id);
|
|
$this->assertSame((int) $product->id, (int) $item->product_id);
|
|
|
$this->assertSame('simple', $item->type);
|
|
$this->assertSame('simple', $item->type);
|
|
@@ -120,8 +125,8 @@ class MigrateAsteriaOrdersCommandTest extends BagistoApiTestCase
|
|
|
public function test_dry_run_does_not_write_orders(): void
|
|
public function test_dry_run_does_not_write_orders(): void
|
|
|
{
|
|
{
|
|
|
MagentoSchema::seedOrder($this->connection, [
|
|
MagentoSchema::seedOrder($this->connection, [
|
|
|
- 'entity_id' => 10,
|
|
|
|
|
- 'increment_id' => '100000010',
|
|
|
|
|
|
|
+ 'entity_id' => self::MID + 10,
|
|
|
|
|
+ 'increment_id' => 'T881900010',
|
|
|
'customer_email' => 'dry-run@example.com',
|
|
'customer_email' => 'dry-run@example.com',
|
|
|
]);
|
|
]);
|
|
|
|
|
|
|
@@ -134,15 +139,15 @@ class MigrateAsteriaOrdersCommandTest extends BagistoApiTestCase
|
|
|
])->assertSuccessful();
|
|
])->assertSuccessful();
|
|
|
|
|
|
|
|
$this->assertSame($before, Order::query()->count());
|
|
$this->assertSame($before, Order::query()->count());
|
|
|
- $this->assertNull(Order::query()->where('increment_id', '100000010')->first());
|
|
|
|
|
|
|
+ $this->assertNull(Order::query()->where('increment_id', 'T881900010')->first());
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public function test_it_is_idempotent_on_a_second_run(): void
|
|
public function test_it_is_idempotent_on_a_second_run(): void
|
|
|
{
|
|
{
|
|
|
MagentoSchema::seedOrder($this->connection, [
|
|
MagentoSchema::seedOrder($this->connection, [
|
|
|
- 'entity_id' => 80,
|
|
|
|
|
- 'increment_id' => '100000080',
|
|
|
|
|
- 'customer_email' => 'once@example.com',
|
|
|
|
|
|
|
+ 'entity_id' => self::MID + 80,
|
|
|
|
|
+ 'increment_id' => 'T881900080',
|
|
|
|
|
+ 'customer_email' => 'mig-pk-once@example.test',
|
|
|
'items' => [
|
|
'items' => [
|
|
|
['item_id' => 801, 'sku' => 'ONCE-1', 'name' => 'Once'],
|
|
['item_id' => 801, 'sku' => 'ONCE-1', 'name' => 'Once'],
|
|
|
],
|
|
],
|
|
@@ -163,8 +168,10 @@ class MigrateAsteriaOrdersCommandTest extends BagistoApiTestCase
|
|
|
$this->artisan('orders:migrate-asteria', $options)->assertSuccessful();
|
|
$this->artisan('orders:migrate-asteria', $options)->assertSuccessful();
|
|
|
$this->artisan('orders:migrate-asteria', $options)->assertSuccessful();
|
|
$this->artisan('orders:migrate-asteria', $options)->assertSuccessful();
|
|
|
|
|
|
|
|
- $this->assertSame(1, Order::query()->where('increment_id', '100000080')->count());
|
|
|
|
|
- $order = Order::query()->where('increment_id', '100000080')->first();
|
|
|
|
|
|
|
+ $this->assertSame(1, Order::query()->where('increment_id', 'T881900080')->count());
|
|
|
|
|
+ $order = Order::query()->where('increment_id', 'T881900080')->first();
|
|
|
|
|
+ $this->assertSame(self::MID + 80, (int) $order->id);
|
|
|
|
|
+ $this->assertSame(self::MID + 80, (int) $order->migrated_from_asteria_id);
|
|
|
$this->assertSame(1, OrderItem::query()->where('order_id', $order->id)->count());
|
|
$this->assertSame(1, OrderItem::query()->where('order_id', $order->id)->count());
|
|
|
$this->assertSame(1, OrderAddress::query()->where('order_id', $order->id)->count());
|
|
$this->assertSame(1, OrderAddress::query()->where('order_id', $order->id)->count());
|
|
|
$this->assertSame(1, OrderPayment::query()->where('order_id', $order->id)->count());
|
|
$this->assertSame(1, OrderPayment::query()->where('order_id', $order->id)->count());
|
|
@@ -174,15 +181,15 @@ class MigrateAsteriaOrdersCommandTest extends BagistoApiTestCase
|
|
|
public function test_it_links_a_customer_by_asteria_id(): void
|
|
public function test_it_links_a_customer_by_asteria_id(): void
|
|
|
{
|
|
{
|
|
|
$customer = $this->createCustomer([
|
|
$customer = $this->createCustomer([
|
|
|
- 'email' => 'linked@example.com',
|
|
|
|
|
- 'migrated_from_asteria_id' => 44,
|
|
|
|
|
|
|
+ 'email' => 'mig-pk-linked@example.test',
|
|
|
|
|
+ 'migrated_from_asteria_id' => self::MID + 44,
|
|
|
]);
|
|
]);
|
|
|
|
|
|
|
|
MagentoSchema::seedOrder($this->connection, [
|
|
MagentoSchema::seedOrder($this->connection, [
|
|
|
- 'entity_id' => 90,
|
|
|
|
|
- 'increment_id' => '100000090',
|
|
|
|
|
- 'customer_id' => 44,
|
|
|
|
|
- 'customer_email' => 'other-address@example.com',
|
|
|
|
|
|
|
+ 'entity_id' => self::MID + 90,
|
|
|
|
|
+ 'increment_id' => 'T881900090',
|
|
|
|
|
+ 'customer_id' => self::MID + 44,
|
|
|
|
|
+ 'customer_email' => 'mig-pk-other-address@example.test',
|
|
|
'items' => [
|
|
'items' => [
|
|
|
['item_id' => 901, 'sku' => 'LINK-1'],
|
|
['item_id' => 901, 'sku' => 'LINK-1'],
|
|
|
],
|
|
],
|
|
@@ -194,7 +201,7 @@ class MigrateAsteriaOrdersCommandTest extends BagistoApiTestCase
|
|
|
'--reset-progress' => true,
|
|
'--reset-progress' => true,
|
|
|
])->assertSuccessful();
|
|
])->assertSuccessful();
|
|
|
|
|
|
|
|
- $order = Order::query()->where('increment_id', '100000090')->first();
|
|
|
|
|
|
|
+ $order = Order::query()->where('increment_id', 'T881900090')->first();
|
|
|
$this->assertNotNull($order);
|
|
$this->assertNotNull($order);
|
|
|
$this->assertSame((int) $customer->id, (int) $order->customer_id);
|
|
$this->assertSame((int) $customer->id, (int) $order->customer_id);
|
|
|
$this->assertSame(0, (int) $order->is_guest);
|
|
$this->assertSame(0, (int) $order->is_guest);
|
|
@@ -203,10 +210,10 @@ class MigrateAsteriaOrdersCommandTest extends BagistoApiTestCase
|
|
|
public function test_it_creates_a_guest_order_when_the_customer_is_missing(): void
|
|
public function test_it_creates_a_guest_order_when_the_customer_is_missing(): void
|
|
|
{
|
|
{
|
|
|
MagentoSchema::seedOrder($this->connection, [
|
|
MagentoSchema::seedOrder($this->connection, [
|
|
|
- 'entity_id' => 91,
|
|
|
|
|
- 'increment_id' => '100000091',
|
|
|
|
|
- 'customer_id' => 9999,
|
|
|
|
|
- 'customer_email' => 'nobody@example.com',
|
|
|
|
|
|
|
+ 'entity_id' => self::MID + 91,
|
|
|
|
|
+ 'increment_id' => 'T881900091',
|
|
|
|
|
+ 'customer_id' => self::MID + 9999,
|
|
|
|
|
+ 'customer_email' => 'mig-pk-nobody@example.test',
|
|
|
'customer_firstname' => 'Guest',
|
|
'customer_firstname' => 'Guest',
|
|
|
'customer_lastname' => 'Buyer',
|
|
'customer_lastname' => 'Buyer',
|
|
|
'customer_is_guest' => 1,
|
|
'customer_is_guest' => 1,
|
|
@@ -221,11 +228,11 @@ class MigrateAsteriaOrdersCommandTest extends BagistoApiTestCase
|
|
|
'--reset-progress' => true,
|
|
'--reset-progress' => true,
|
|
|
])->assertSuccessful();
|
|
])->assertSuccessful();
|
|
|
|
|
|
|
|
- $order = Order::query()->where('increment_id', '100000091')->first();
|
|
|
|
|
|
|
+ $order = Order::query()->where('increment_id', 'T881900091')->first();
|
|
|
$this->assertNotNull($order);
|
|
$this->assertNotNull($order);
|
|
|
$this->assertNull($order->customer_id);
|
|
$this->assertNull($order->customer_id);
|
|
|
$this->assertSame(1, (int) $order->is_guest);
|
|
$this->assertSame(1, (int) $order->is_guest);
|
|
|
- $this->assertSame('nobody@example.com', $order->customer_email);
|
|
|
|
|
|
|
+ $this->assertSame('mig-pk-nobody@example.test', $order->customer_email);
|
|
|
$this->assertSame('Guest', $order->customer_first_name);
|
|
$this->assertSame('Guest', $order->customer_first_name);
|
|
|
$this->assertSame('cashondelivery', $order->payment->method);
|
|
$this->assertSame('cashondelivery', $order->payment->method);
|
|
|
}
|
|
}
|
|
@@ -233,8 +240,8 @@ class MigrateAsteriaOrdersCommandTest extends BagistoApiTestCase
|
|
|
public function test_it_imports_unmatched_sku_items_without_a_product_id(): void
|
|
public function test_it_imports_unmatched_sku_items_without_a_product_id(): void
|
|
|
{
|
|
{
|
|
|
MagentoSchema::seedOrder($this->connection, [
|
|
MagentoSchema::seedOrder($this->connection, [
|
|
|
- 'entity_id' => 92,
|
|
|
|
|
- 'increment_id' => '100000092',
|
|
|
|
|
|
|
+ 'entity_id' => self::MID + 92,
|
|
|
|
|
+ 'increment_id' => 'T881900092',
|
|
|
'items' => [
|
|
'items' => [
|
|
|
[
|
|
[
|
|
|
'item_id' => 921,
|
|
'item_id' => 921,
|
|
@@ -251,7 +258,7 @@ class MigrateAsteriaOrdersCommandTest extends BagistoApiTestCase
|
|
|
'--reset-progress' => true,
|
|
'--reset-progress' => true,
|
|
|
])->assertSuccessful();
|
|
])->assertSuccessful();
|
|
|
|
|
|
|
|
- $order = Order::query()->where('increment_id', '100000092')->first();
|
|
|
|
|
|
|
+ $order = Order::query()->where('increment_id', 'T881900092')->first();
|
|
|
$this->assertNotNull($order);
|
|
$this->assertNotNull($order);
|
|
|
$item = OrderItem::query()->where('order_id', $order->id)->first();
|
|
$item = OrderItem::query()->where('order_id', $order->id)->first();
|
|
|
$this->assertSame('MISSING-SKU', $item->sku);
|
|
$this->assertSame('MISSING-SKU', $item->sku);
|
|
@@ -264,18 +271,19 @@ class MigrateAsteriaOrdersCommandTest extends BagistoApiTestCase
|
|
|
public function test_it_skips_when_increment_id_already_exists(): void
|
|
public function test_it_skips_when_increment_id_already_exists(): void
|
|
|
{
|
|
{
|
|
|
$channel = Channel::query()->first();
|
|
$channel = Channel::query()->first();
|
|
|
- Order::factory()->create([
|
|
|
|
|
- 'increment_id' => '100000099',
|
|
|
|
|
|
|
+ $native = Order::factory()->create([
|
|
|
|
|
+ 'increment_id' => 'T881900099',
|
|
|
'channel_id' => $channel?->id,
|
|
'channel_id' => $channel?->id,
|
|
|
'channel_type' => Channel::class,
|
|
'channel_type' => Channel::class,
|
|
|
'customer_id' => null,
|
|
'customer_id' => null,
|
|
|
'is_guest' => 1,
|
|
'is_guest' => 1,
|
|
|
'customer_email'=> 'native@example.com',
|
|
'customer_email'=> 'native@example.com',
|
|
|
]);
|
|
]);
|
|
|
|
|
+ $bagistoId = (int) $native->id;
|
|
|
|
|
|
|
|
MagentoSchema::seedOrder($this->connection, [
|
|
MagentoSchema::seedOrder($this->connection, [
|
|
|
- 'entity_id' => 99,
|
|
|
|
|
- 'increment_id' => '100000099',
|
|
|
|
|
|
|
+ 'entity_id' => self::MID + 99,
|
|
|
|
|
+ 'increment_id' => 'T881900099',
|
|
|
'customer_email' => 'asteria@example.com',
|
|
'customer_email' => 'asteria@example.com',
|
|
|
'items' => [
|
|
'items' => [
|
|
|
['item_id' => 991, 'sku' => 'SKIP-1'],
|
|
['item_id' => 991, 'sku' => 'SKIP-1'],
|
|
@@ -288,19 +296,20 @@ class MigrateAsteriaOrdersCommandTest extends BagistoApiTestCase
|
|
|
'--reset-progress' => true,
|
|
'--reset-progress' => true,
|
|
|
])->assertSuccessful();
|
|
])->assertSuccessful();
|
|
|
|
|
|
|
|
- $this->assertSame(1, Order::query()->where('increment_id', '100000099')->count());
|
|
|
|
|
- $existing = Order::query()->where('increment_id', '100000099')->first();
|
|
|
|
|
|
|
+ $this->assertSame(1, Order::query()->where('increment_id', 'T881900099')->count());
|
|
|
|
|
+ $existing = Order::query()->where('increment_id', 'T881900099')->first();
|
|
|
$this->assertNull($existing->migrated_from_asteria_id);
|
|
$this->assertNull($existing->migrated_from_asteria_id);
|
|
|
$this->assertSame('native@example.com', $existing->customer_email);
|
|
$this->assertSame('native@example.com', $existing->customer_email);
|
|
|
|
|
+ $this->assertSame($bagistoId, (int) $existing->id);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
private function seedCompleteMagentoOrder(): void
|
|
private function seedCompleteMagentoOrder(): void
|
|
|
{
|
|
{
|
|
|
MagentoSchema::seedOrder($this->connection, [
|
|
MagentoSchema::seedOrder($this->connection, [
|
|
|
- 'entity_id' => 10,
|
|
|
|
|
- 'increment_id' => '100000010',
|
|
|
|
|
- 'customer_id' => 10,
|
|
|
|
|
- 'customer_email' => 'jane@example.com',
|
|
|
|
|
|
|
+ 'entity_id' => self::MID + 10,
|
|
|
|
|
+ 'increment_id' => 'T881900010',
|
|
|
|
|
+ 'customer_id' => self::MID + 10,
|
|
|
|
|
+ 'customer_email' => 'mig-pk-jane@example.test',
|
|
|
'customer_firstname' => 'Jane',
|
|
'customer_firstname' => 'Jane',
|
|
|
'customer_lastname' => 'Doe',
|
|
'customer_lastname' => 'Doe',
|
|
|
'status' => 'complete',
|
|
'status' => 'complete',
|
|
@@ -312,7 +321,7 @@ class MigrateAsteriaOrdersCommandTest extends BagistoApiTestCase
|
|
|
'items' => [
|
|
'items' => [
|
|
|
[
|
|
[
|
|
|
'item_id' => 101,
|
|
'item_id' => 101,
|
|
|
- 'sku' => 'WIG-001',
|
|
|
|
|
|
|
+ 'sku' => 'AST-TEST-WIG-001',
|
|
|
'name' => 'Lace Wig',
|
|
'name' => 'Lace Wig',
|
|
|
'qty_ordered'=> 1,
|
|
'qty_ordered'=> 1,
|
|
|
'price' => 100,
|
|
'price' => 100,
|
|
@@ -357,4 +366,28 @@ class MigrateAsteriaOrdersCommandTest extends BagistoApiTestCase
|
|
|
'attribute_family_id' => $attributeFamilyId,
|
|
'attribute_family_id' => $attributeFamilyId,
|
|
|
]);
|
|
]);
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ private function forgetLeakedAsteriaOrders(): void
|
|
|
|
|
+ {
|
|
|
|
|
+ $orderIds = Order::query()
|
|
|
|
|
+ ->where('increment_id', 'like', 'T8819%')
|
|
|
|
|
+ ->pluck('id');
|
|
|
|
|
+
|
|
|
|
|
+ if ($orderIds->isNotEmpty()) {
|
|
|
|
|
+ OrderItem::query()->whereIn('order_id', $orderIds)->delete();
|
|
|
|
|
+ OrderAddress::query()->whereIn('order_id', $orderIds)->delete();
|
|
|
|
|
+ OrderPayment::query()->whereIn('order_id', $orderIds)->delete();
|
|
|
|
|
+ Order::query()->whereIn('id', $orderIds)->delete();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ $customerIds = Customer::query()
|
|
|
|
|
+ ->where('email', 'like', 'mig-pk-%')
|
|
|
|
|
+ ->pluck('id');
|
|
|
|
|
+
|
|
|
|
|
+ if ($customerIds->isNotEmpty()) {
|
|
|
|
|
+ Customer::query()->whereIn('id', $customerIds)->delete();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ Product::query()->where('sku', 'like', 'AST-TEST-%')->delete();
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|