mecachisenros / woocommerce_civicrm

GNU Affero General Public License v3.0
14 stars 16 forks source link

Missing state data #5

Closed michaelrichardmurphy closed 7 years ago

michaelrichardmurphy commented 8 years ago

First, thanks for making this code available. It's been very helpful.

The one thing I see missing is that the customer's state doesn't look like it gets copied to the CiviCRM record when it's created/updated. Any chance of getting that added to future versions?

rajeshrhino commented 7 years ago

@michaelrichardmurphy Glad the plugin is useful for you.

Regarding State/County: When we developed the plugin initially we looked at the state/county to be copied into CiviCRM address, but the drawback is State/County in Woocommerce is a text field whereas State/County is a dropdown list. It will be hard to map the the state name typed into Woocommerce's State/County field to a value in State/County in CiviCRM. We can lookup for the state/county name in CiviCRM and get the associated value, but this will not be a consistent approach.

Let us know your thoughts.

veda-consulting commented 7 years ago

@michaelrichardmurphy closing for now as this is an issue with different data sets.

cdhassell commented 7 years ago

As of 4.7.15 civicrm has a StateProvince API which looks like it should help here. It could be used something like:

$query = array( 'sequential' => 1, "abbreviation" => $state_province_str, "country_id" => $country_id ); $result = civicrm_api3( 'StateProvince', 'get', $query );

veda-consulting commented 7 years ago

The issue isn't on the civicrm side, its Woocommerce allowing free text State/Province. The only way our extension could fix this would be to change that behaviour i.e. force woocmmerce to use the state province list. To me this feels like an enhancement rather then a bug fix and we'd need to get some feedback from the community before we implemented.

cdhassell commented 7 years ago

That is odd, because on my site woocommerce provides a state dropdown list. See the attached screenshot. Does this vary depending on how WC is configured? For this site I have the option set for the US as the only country available. But when that is turned off, it has a country dropdown list to select. When the US is selected then the state dropdown is automatically populated with the US states. Maybe it offers free text for states/provinces of other countries? I've never tried that out. address

veda-consulting commented 7 years ago

Thats interesting, might be something to do with versions or the country configuration. If anyone knows they can feedback on this ticket.

cdhassell commented 7 years ago

The current code is a problem because whenever the new address from WC is slightly different than an existing address in Civi (capitalization differences, or "Road" abbreviated to "RD" etc), then the WC address is saved to the Civi contact but without the state/province. The result is that a good address (with the state/province) is overwritten by a bad address (missing the state/province).

In the API Explorer for address creation, you can feed a string to state_province_id and Civi will figure it out. The Explorer provides this example: $result = civicrm_api3('Address', 'create', array( 'sequential' => 1, 'contact_id' => "user_contact_id", 'state_province_id' => "Pennsylvania", )); So why can't the state string from WC be fed directly to Civi in the address create API? Or did you test doing that and it didn't work?