Skip to content

Commit

Permalink
Merge pull request #75 from TheDMSGroup/ENG-673
Browse files Browse the repository at this point in the history
[ENG-673] Trust zip code over user-entered city
  • Loading branch information
heathdutton authored Dec 19, 2018
2 parents 1443910 + 3c5e980 commit 73a9f97
Show file tree
Hide file tree
Showing 14 changed files with 28 additions and 29 deletions.
2 changes: 1 addition & 1 deletion Integration/AbstractEnhancerIntegration.php
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ public function pushLead(Lead &$lead, array $config = [])
*
* @return bool
*/
abstract public function doEnhancement(Lead &$lead);
abstract public function doEnhancement(Lead $lead);

/**
* @param $lead
Expand Down
2 changes: 1 addition & 1 deletion Integration/AbstractNeustarIntegration.php
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ public function getAuthenticationType()
*
* @throws \GuzzleHttp\Exception\GuzzleException
*/
public function doEnhancement(Lead &$lead)
public function doEnhancement(Lead $lead)
{
$keys = $this->getKeys();

Expand Down
2 changes: 1 addition & 1 deletion Integration/AgeFromBirthdateIntegration.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public function appendToForm(&$builder, $data, $formArea)
*
* @return bool
*/
public function doEnhancement(Lead &$lead)
public function doEnhancement(Lead $lead)
{
$save = false;
$this->logger->info('AgeFromBirthdate:doEnhancemet');
Expand Down
2 changes: 1 addition & 1 deletion Integration/AlcazarIntegration.php
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ private function getAlcazarExtendedFields()
*
* @return bool
*/
public function doEnhancement(Lead &$lead)
public function doEnhancement(Lead $lead)
{
if (!empty($lead)) {
if ($lead->getFieldValue('alcazar_lrn') || !$lead->getPhone()) {
Expand Down
2 changes: 1 addition & 1 deletion Integration/AnuraIntegration.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ protected function getEnhancerFieldArray()
*
* @throws \GuzzleHttp\Exception\GuzzleException
*/
public function doEnhancement(Lead &$lead)
public function doEnhancement(Lead $lead)
{
$didEnhnacement = false;

Expand Down
2 changes: 1 addition & 1 deletion Integration/BlacklistIntegration.php
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ protected function getEnhancerFieldArray()
*
* @throws \GuzzleHttp\Exception\GuzzleException
*/
public function doEnhancement(Lead &$lead)
public function doEnhancement(Lead $lead)
{
$save = false;

Expand Down
29 changes: 14 additions & 15 deletions Integration/CityStateFromPostalCodeIntegration.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Doctrine\DBAL\Query\QueryBuilder;
use Mautic\LeadBundle\Entity\Lead;
use MauticPlugin\MauticEnhancerBundle\Entity\PluginEnhancerCityStatePostalCode;
use Symfony\Component\Form\Extension\Core\Type\HiddenType;

/**
* Class CityStateFromPostalCodeIntegration.
Expand Down Expand Up @@ -117,7 +118,7 @@ protected function getIntegrationModel()
*
* @return bool
*/
public function doEnhancement(Lead &$lead)
public function doEnhancement(Lead $lead)
{
$persist = false;

Expand All @@ -129,6 +130,7 @@ public function doEnhancement(Lead &$lead)
$leadCountry = $lead->getCountry();

if (empty($leadCountry)) {
/** @var mixed $ipDetails */
$ipDetails = $this->factory->getIpAddress()->getIpDetails();
$leadCountry = isset($ipDetails['country']) ? strtoupper($ipDetails['country']) : 'US';
} elseif (2 !== strlen($leadCountry)) {
Expand All @@ -140,10 +142,8 @@ public function doEnhancement(Lead &$lead)
$dash = strpos((string) $leadZipCode, '-');
$leadZipCode = $dash ? substr((string) $leadZipCode, 0, $dash) : $leadZipCode;

if (
(empty($leadCity) || empty($leadState) || empty($leadCounty))
&& !(empty($leadCountry) || empty($leadZipCode))
) {
// Override User city, state if zip code given
if (!(empty($leadCountry) || empty($leadZipCode))) {
/** @var PluginEnhancerCityStatePostalCode $cityStatePostalCode */
$cityStatePostalCode = $this->getIntegrationModel()->getRepository()->findOneBy(
[
Expand All @@ -153,13 +153,13 @@ public function doEnhancement(Lead &$lead)
);

if (null !== $cityStatePostalCode) {
if (empty($leadCity) && !empty($cityStatePostalCode->getCity())) {
if (/*empty($leadCity) &&*/ !empty($cityStatePostalCode->getCity() && $leadCity !== $cityStatePostalCode->getCity())) {
$this->logger->debug('CityStateFromPostalCode: Found city for lead '.$lead->getId());
$lead->setCity($cityStatePostalCode->getCity());
$persist = true;
}

if (empty($leadState) && !empty($cityStatePostalCode->getStateProvince())) {
if (/*empty($leadState) &&*/ !empty($cityStatePostalCode->getStateProvince()) && $leadState !== $cityStatePostalCode->getStateProvince()) {
$this->logger->debug('CityStateFromPostalCode: Found state/province for lead '.$lead->getId());
$spLong = $cityStatePostalCode->getStateProvince();
$spShort = in_array($spLong, self::$US_STATES)
Expand All @@ -169,19 +169,18 @@ public function doEnhancement(Lead &$lead)
$persist = true;
}

if (empty($leadCounty) && !empty($cityStatePostalCode->getCounty())) {
if (/*empty($leadCounty) &&*/ !empty($cityStatePostalCode->getCounty()) && $leadCounty !== $cityStatePostalCode->getCounty()) {
$this->logger->debug('CityStateFromPostalCode: Found county for lead '.$lead->getId());
$lead->addUpdatedField('county', $cityStatePostalCode->getCounty(), $leadCounty);
$persist = true;
}
}
}

if (
(empty($leadZipCode) && empty($lead->getAddress1()))
&& !(empty($leadCity) || empty($leadState) || empty($leadCountry))
} elseif (
!(empty($leadCity) || empty($leadState) || empty($leadCountry)) &&
empty($leadZipCode) &&
empty($lead->getAddress1())
) {
$stateProvince = in_array($leadState, array_keys(self::$US_STATES))
$stateProvince = array_key_exists($leadState, self::$US_STATES)
? self::$US_STATES[$leadState]
: $leadState;
/** @var PluginEnhancerCityStatePostalCode $cityStatePostalCode */
Expand Down Expand Up @@ -273,7 +272,7 @@ public function appendToForm(&$builder, $data, $formArea)
if ('features' === $formArea) {
$builder->add(
'autorun_enabled',
\Symfony\Component\Form\Extension\Core\Type\HiddenType::class,
HiddenType::class,
[
'data' => true,
]
Expand Down
2 changes: 1 addition & 1 deletion Integration/CorrectAddressIntegration.php
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ public function appendToForm(&$builder, $data, $formArea)
*
* @return bool
*/
public function doEnhancement(Lead &$lead)
public function doEnhancement(Lead $lead)
{
$result = false;
$leadAddress1 = $lead->getAddress1();
Expand Down
2 changes: 1 addition & 1 deletion Integration/FourleafIntegration.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ protected function getEnhancerFieldArray()
*
* @return bool
*/
public function doEnhancement(Lead &$lead)
public function doEnhancement(Lead $lead)
{
$persist = false;
if (!empty($lead)) {
Expand Down
2 changes: 1 addition & 1 deletion Integration/GenderFromNameIntegration.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ protected function getIntegrationModel()
*
* @return bool
*/
public function doEnhancement(Lead &$lead)
public function doEnhancement(Lead $lead)
{
$gender = $lead->getFieldValue('gender');
if (!$gender or $this->isPush) {
Expand Down
2 changes: 1 addition & 1 deletion Integration/PhoneToPartsIntegration.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ protected function getEnhancerFieldArray()
*
* @return bool
*/
public function doEnhancement(Lead &$lead)
public function doEnhancement(Lead $lead)
{
$phone = preg_replace('/\D+/', '', $lead->getPhone());

Expand Down
2 changes: 1 addition & 1 deletion Integration/RandomIntegration.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ protected function getEnhancerFieldArray()
*
* @return bool
*/
public function doEnhancement(Lead &$lead)
public function doEnhancement(Lead $lead)
{
if (!empty($lead)) {
$settings = $this->getIntegrationSettings()->getFeatureSettings();
Expand Down
2 changes: 1 addition & 1 deletion Integration/XverifyIntegration.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ protected function getEnhancerFieldArray()
*
* @return bool
*/
public function doEnhancement(Lead &$lead)
public function doEnhancement(Lead $lead)
{
$persist = false;
if (!empty($lead)) {
Expand Down
4 changes: 2 additions & 2 deletions Translations/en_US/messages.ini
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ mautic.enhancer.integration.anura.user_agent.label = "Default User Agent"
mautic.enhancer.integration.anura.user_agent.tooltip = "User agent to use when none is provided"
mautic.enhancer.integration.blacklist.endpoint.label = "Endpoint"
mautic.enhancer.integration.blacklist.endpoint.tooltip = "Default is https://api.theblacklist.click/standard/api/v1"
mautic.enhancer.integration.blacklist.age.label = "Age (mintutes)"
mautic.enhancer.integration.blacklist.age.label = "Age (minutes)"
mautic.enhancer.integration.blacklist.age.tooltip = "Maximum number of minutes a Blacklist lookup will be considdered valid, before another can be made."
mautic.enhancer.integration.blacklist.blacklist_result.label = "Blacklist Result (is blacklisted)"
mautic.enhancer.integration.blacklist.blacklist_code.label = "Blacklist Code"
Expand Down Expand Up @@ -54,7 +54,7 @@ mautic.enhancer.integration.xverify.email.label = "email"
mautic.enhancer.integration.xverify.homephone.label = "Phone - Home"
mautic.enhancer.integration.xverify.server.label = "XVERIFY_DOMAIN"
mautic.enhancer.integration.xverify.validate_email.label = "Validate Email Address?"
mautic.enhancer.integration.xverify.validate_email.tooltip = "Automatically vaidate Email Addresses?"
mautic.enhancer.integration.xverify.validate_email.tooltip = "Automatically validate Email Addresses?"
mautic.enhancer.integration.xverify.validate_phone.label = "Validate Phone Numbers?"
mautic.enhancer.integration.xverify.validate_phone.tooltip = "Automatically validate Phone Numbers?"
mautic.enhancer.integration.xverify.workphone.label = "Phone - Work"
Expand Down

0 comments on commit 73a9f97

Please sign in to comment.