This commit is contained in:
2026-03-11 13:59:51 +08:00
parent f32c49b714
commit bee9146409
+11 -3
View File
@@ -1108,6 +1108,14 @@ class WordpressSiteService
// 设置产品分类使用 product_cat 字段) // 设置产品分类使用 product_cat 字段)
$data['product_cat'] = [15, 16]; $data['product_cat'] = [15, 16];
// 处理品牌:翻译并获取/创建品牌ID
$brand = $car->crawl_brand ?: $car->product_name;
$brandEnglish = $this->translateIfNeeded($brand, '英文');
$brandId = $this->get_or_create_brand_id($site, $domain, $brandEnglish);
if ($brandId) {
$data['pa_brand'] = [$brandId];
}
// 设置主图和车辆相册(ACF字段) // 设置主图和车辆相册(ACF字段)
if (!empty($uploadedImages)) { if (!empty($uploadedImages)) {
$allImageIds = array_map(function($img) { $allImageIds = array_map(function($img) {
@@ -1134,7 +1142,9 @@ class WordpressSiteService
'source_place' => '车源地', 'source_place' => '车源地',
'price' => '价格', 'price' => '价格',
]; ];
if (str_contains($car->mileage, '万') || str_contains($car->mileage, '万公里')) {
$car->mileage = str_replace(['万', '公里', '万公里'],'',$car->mileage)*10000;
}
foreach ($fieldMap as $acfKey => $label) { foreach ($fieldMap as $acfKey => $label) {
if (!empty($car->$acfKey)) { if (!empty($car->$acfKey)) {
$value = $car->$acfKey; $value = $car->$acfKey;
@@ -1143,8 +1153,6 @@ class WordpressSiteService
$value = $this->translateColorToEnglish($value); $value = $this->translateColorToEnglish($value);
} elseif ($acfKey === 'source_place' && $this->containsChinese($value)) { } elseif ($acfKey === 'source_place' && $this->containsChinese($value)) {
$value = $this->translateIfNeeded($value, '英文'); $value = $this->translateIfNeeded($value, '英文');
} elseif ($acfKey === 'Mileage' && $acfKey) {
$value = $this->translateIfNeeded($value, '英文');
} }
$data['acf'][$acfKey] = $value; $data['acf'][$acfKey] = $value;
} }