瀏覽代碼

用户迁移将 Magento source 映射到 customer_source。

Co-authored-by: Cursor <cursoragent@cursor.com>
chengwl 1 天之前
父節點
當前提交
49a0799cbb

+ 2 - 2
app/Console/Commands/MigrateAsteriaCustomers.php

@@ -239,7 +239,7 @@ class MigrateAsteriaCustomers extends Command
                 if ($existing) {
                 if ($existing) {
                     $addressJobs[] = ['customer' => $existing, 'row' => $row];
                     $addressJobs[] = ['customer' => $existing, 'row' => $row];
                     $linked++;
                     $linked++;
-                    $source = $this->mapCustomerSource($row['customer_source'] ?? null);
+                    $source = $this->mapCustomerSource($row['source'] ?? $row['customer_source'] ?? null);
 
 
                     if ($source !== null) {
                     if ($source !== null) {
                         $sourceUpdates[(int) $existing->id] = $source;
                         $sourceUpdates[(int) $existing->id] = $source;
@@ -268,7 +268,7 @@ class MigrateAsteriaCustomers extends Command
                 'api_token'                 => Str::random(80),
                 'api_token'                 => Str::random(80),
                 'customer_group_id'         => $this->groupId,
                 'customer_group_id'         => $this->groupId,
                 'channel_id'                => $this->channelId,
                 'channel_id'                => $this->channelId,
-                'customer_source'           => $this->mapCustomerSource($row['customer_source'] ?? null),
+                'customer_source'           => $this->mapCustomerSource($row['source'] ?? $row['customer_source'] ?? null),
                 'subscribed_to_news_letter' => $this->isMagentoSubscribed($subscriber) ? 1 : 0,
                 'subscribed_to_news_letter' => $this->isMagentoSubscribed($subscriber) ? 1 : 0,
                 'status'                    => ((int) ($row['is_active'] ?? 1)) === 1 ? 1 : 0,
                 'status'                    => ((int) ($row['is_active'] ?? 1)) === 1 ? 1 : 0,
                 'is_verified'               => 1,
                 'is_verified'               => 1,

+ 1 - 0
app/Services/Asteria/Magento1CustomerReader.php

@@ -16,6 +16,7 @@ class Magento1CustomerReader
         'password_hash',
         'password_hash',
         'default_billing',
         'default_billing',
         'default_shipping',
         'default_shipping',
+        'source',
         'customer_source',
         'customer_source',
     ];
     ];
 
 

+ 1 - 1
docs/asteria-migration.md

@@ -114,7 +114,7 @@ php artisan customers:migrate-asteria --reset-progress
 - 手机号与现有用户冲突:新用户 `phone` 置空。
 - 手机号与现有用户冲突:新用户 `phone` 置空。
 - 地址按 `addresses.additional.asteria_address_id` 去重;街道换行压成 `, `。
 - 地址按 `addresses.additional.asteria_address_id` 去重;街道换行压成 `, `。
 - 订阅:Magento `newsletter_subscriber.subscriber_status = 1` 为已订阅,写入 `customers.subscribed_to_news_letter`,并按邮箱幂等写入 `subscribers_list`。已退订(status=3 等)的**注册用户**会写成未订阅并保留 `subscribers_list` 记录;无账号的游客订阅只导入已订阅邮箱。无 `newsletter_subscriber` 表时跳过,不影响用户导入。重复执行会回填已迁用户的订阅状态。
 - 订阅:Magento `newsletter_subscriber.subscriber_status = 1` 为已订阅,写入 `customers.subscribed_to_news_letter`,并按邮箱幂等写入 `subscribers_list`。已退订(status=3 等)的**注册用户**会写成未订阅并保留 `subscribers_list` 记录;无账号的游客订阅只导入已订阅邮箱。无 `newsletter_subscriber` 表时跳过,不影响用户导入。重复执行会回填已迁用户的订阅状态。
-- `customer_source`:从 Magento 客户 EAV(或 `customer_entity` 静态列)写入,表示注册入口数字码。不迁 `source_url`。已迁用户再跑(`--reset-progress`)会按 Magento 值回填。
+- `customer_source`:从 Magento 客户属性 `source` 写入。不迁 `source_url`。已迁用户再跑(`--reset-progress`)会按 Magento 值回填。
 
 
 进度缓存:`migrate_asteria_customers_last_id`(30 天)。
 进度缓存:`migrate_asteria_customers_last_id`(30 天)。
 
 

+ 2 - 2
packages/Webkul/BagistoApi/tests/Unit/Migration/Magento1CustomerReaderTest.php

@@ -40,7 +40,7 @@ class Magento1CustomerReaderTest extends TestCase
             'password_hash' => md5('abcsecret12').':abc',
             'password_hash' => md5('abcsecret12').':abc',
             'is_active'     => 1,
             'is_active'     => 1,
             'group_id'      => 99,
             'group_id'      => 99,
-            'customer_source' => 20,
+            'source'        => 20,
         ]);
         ]);
         MagentoSchema::seedAddress($this->connection, [
         MagentoSchema::seedAddress($this->connection, [
             'entity_id'  => 21,
             'entity_id'  => 21,
@@ -84,7 +84,7 @@ class Magento1CustomerReaderTest extends TestCase
         $this->assertSame('1', (string) $customer['gender']);
         $this->assertSame('1', (string) $customer['gender']);
         $this->assertSame('1990-05-01 00:00:00', $customer['dob']);
         $this->assertSame('1990-05-01 00:00:00', $customer['dob']);
         $this->assertSame(md5('abcsecret12').':abc', $customer['password_hash']);
         $this->assertSame(md5('abcsecret12').':abc', $customer['password_hash']);
-        $this->assertSame('20', (string) $customer['customer_source']);
+        $this->assertSame('20', (string) $customer['source']);
 
 
         $addresses = $reader->fetchAddresses([10]);
         $addresses = $reader->fetchAddresses([10]);
         $this->assertCount(1, $addresses);
         $this->assertCount(1, $addresses);

+ 3 - 3
packages/Webkul/BagistoApi/tests/Unit/Migration/MagentoSchema.php

@@ -116,7 +116,7 @@ class MagentoSchema
             ['attribute_id' => 14, 'entity_type_id' => self::CUSTOMER_TYPE_ID, 'attribute_code' => 'default_shipping', 'backend_type' => 'int'],
             ['attribute_id' => 14, 'entity_type_id' => self::CUSTOMER_TYPE_ID, 'attribute_code' => 'default_shipping', 'backend_type' => 'int'],
             ['attribute_id' => 18, 'entity_type_id' => self::CUSTOMER_TYPE_ID, 'attribute_code' => 'gender', 'backend_type' => 'int'],
             ['attribute_id' => 18, 'entity_type_id' => self::CUSTOMER_TYPE_ID, 'attribute_code' => 'gender', 'backend_type' => 'int'],
             ['attribute_id' => 88, 'entity_type_id' => self::CUSTOMER_TYPE_ID, 'attribute_code' => 'telephone', 'backend_type' => 'varchar'],
             ['attribute_id' => 88, 'entity_type_id' => self::CUSTOMER_TYPE_ID, 'attribute_code' => 'telephone', 'backend_type' => 'varchar'],
-            ['attribute_id' => 89, 'entity_type_id' => self::CUSTOMER_TYPE_ID, 'attribute_code' => 'customer_source', 'backend_type' => 'int'],
+            ['attribute_id' => 89, 'entity_type_id' => self::CUSTOMER_TYPE_ID, 'attribute_code' => 'source', 'backend_type' => 'int'],
             ['attribute_id' => 20, 'entity_type_id' => self::ADDRESS_TYPE_ID, 'attribute_code' => 'firstname', 'backend_type' => 'varchar'],
             ['attribute_id' => 20, 'entity_type_id' => self::ADDRESS_TYPE_ID, 'attribute_code' => 'firstname', 'backend_type' => 'varchar'],
             ['attribute_id' => 21, 'entity_type_id' => self::ADDRESS_TYPE_ID, 'attribute_code' => 'lastname', 'backend_type' => 'varchar'],
             ['attribute_id' => 21, 'entity_type_id' => self::ADDRESS_TYPE_ID, 'attribute_code' => 'lastname', 'backend_type' => 'varchar'],
             ['attribute_id' => 22, 'entity_type_id' => self::ADDRESS_TYPE_ID, 'attribute_code' => 'company', 'backend_type' => 'varchar'],
             ['attribute_id' => 22, 'entity_type_id' => self::ADDRESS_TYPE_ID, 'attribute_code' => 'company', 'backend_type' => 'varchar'],
@@ -298,11 +298,11 @@ class MagentoSchema
             ]);
             ]);
         }
         }
 
 
-        if (isset($data['customer_source'])) {
+        if (isset($data['source']) || isset($data['customer_source'])) {
             DB::connection($connection)->table('customer_entity_int')->insert([
             DB::connection($connection)->table('customer_entity_int')->insert([
                 'entity_id'    => $entityId,
                 'entity_id'    => $entityId,
                 'attribute_id' => 89,
                 'attribute_id' => 89,
-                'value'        => $data['customer_source'],
+                'value'        => $data['source'] ?? $data['customer_source'],
             ]);
             ]);
         }
         }
 
 

+ 4 - 4
packages/Webkul/BagistoApi/tests/Unit/Migration/MigrateAsteriaCustomersCommandTest.php

@@ -70,7 +70,7 @@ class MigrateAsteriaCustomersCommandTest extends BagistoApiTestCase
             'group_id'         => 99,
             'group_id'         => 99,
             'default_billing'  => 21,
             'default_billing'  => 21,
             'default_shipping' => 21,
             'default_shipping' => 21,
-            'customer_source'  => 20,
+            'source'           => 20,
         ]);
         ]);
         MagentoSchema::seedAddress($this->connection, [
         MagentoSchema::seedAddress($this->connection, [
             'entity_id'  => 21,
             'entity_id'  => 21,
@@ -443,9 +443,9 @@ class MigrateAsteriaCustomersCommandTest extends BagistoApiTestCase
         MagentoSchema::seedCustomer($this->connection, [
         MagentoSchema::seedCustomer($this->connection, [
             'entity_id'       => 880000096,
             'entity_id'       => 880000096,
             'email'           => 'asteria-src@nshop.test',
             'email'           => 'asteria-src@nshop.test',
-            'firstname'       => 'Src',
-            'lastname'        => 'User',
-            'customer_source' => 22,
+            'firstname' => 'Src',
+            'lastname'  => 'User',
+            'source'    => 22,
         ]);
         ]);
 
 
         $this->artisan('customers:migrate-asteria', [
         $this->artisan('customers:migrate-asteria', [