| 1 |
<?php |
| 2 |
/** |
| 3 |
* Country resolution for newly created listings. |
| 4 |
* |
| 5 |
* The parsed listing arrives from the SaaS with the feed's own country under |
| 6 |
* meta.property_country: the Lambda maps the RESO `Country` field into that |
| 7 |
* key and translates ISO codes to full names (Centris's "CA" → "Canada"). |
| 8 |
* The WpResidence projection historically hardcoded "United States" over it |
| 9 |
* for every new listing, which mislabelled Canadian imports. |
| 10 |
* |
| 11 |
* Step by step: |
| 12 |
* 1. Read meta.property_country from the parsed property. |
| 13 |
* 2. If the feed sent a non-empty country, keep it. |
| 14 |
* 3. Otherwise return the historical default, "United States", so US feeds |
| 15 |
* that omit the field behave exactly as before. |
| 16 |
* |
| 17 |
* Kept WordPress-free so the rule is unit-testable |
| 18 |
* (tests/PropertyCountryTest.php) without loading the theme adapters. |
| 19 |
* |
| 20 |
* @package Mlsimport |
| 21 |
* @subpackage Mlsimport/includes |
| 22 |
*/ |
| 23 |
|
| 24 |
if ( ! defined( 'ABSPATH' ) ) { |
| 25 |
exit; |
| 26 |
} |
| 27 |
|
| 28 |
/** |
| 29 |
* Resolve the country name to store for a listing. |
| 30 |
* |
| 31 |
* @param array $property Parsed incoming property (SaaS structure). |
| 32 |
* @return string Full country name for the theme's property_country meta. |
| 33 |
*/ |
| 34 |
function mlsimport_property_country( $property ) { |
| 35 |
$country = $property['meta']['property_country'] ?? ''; |
| 36 |
if ( is_string( $country ) && '' !== $country ) { |
| 37 |
return $country; |
| 38 |
} |
| 39 |
|
| 40 |
return 'United States'; |
| 41 |
} |
| 42 |
|