categoryId === null) { return false; } DB::transaction(function () use ($data) { $productType = DB::table('product_categories')->where('id', $data->categoryId)->value('type') ?? 'other'; DB::table('products')->updateOrInsert( ['legacy_id' => $data->legacyId], [ 'uuid' => DB::table('products')->where('legacy_id', $data->legacyId)->value('uuid') ?? (string) Str::uuid(), 'product_type' => $productType, 'product_categories_id' => $data->categoryId, 'name' => $data->name, 'slug' => $data->slug, 'short_description' => $data->shortDescription, 'description' => $data->description, 'stock' => $data->stock, 'is_unlimited' => $data->isUnlimited, 'setup_fee' => $data->setupFee, 'is_active' => $data->isActive, 'sort_order' => $data->sortOrder, 'created_at' => $data->createdAt, 'updated_at' => $data->updatedAt, ] ); $productId = DB::table('products')->where('legacy_id', $data->legacyId)->value('id'); foreach ($data->pricings as $pricing) { DB::table('product_pricings')->updateOrInsert( ['product_id' => $productId, 'billing_cycle' => $pricing['billing_cycle']], ['price' => $pricing['price'], 'currency' => 'VND'] ); } }); return true; } }