/** * {@inheritDoc} */ public function getUpdatedFields() { $this->__initializer__ && $this->__initializer__->__invoke($this, 'getUpdatedFields', array()); return parent::getUpdatedFields(); }
/** * {@inheritdoc} * * @param Lead $entity * @param bool $unlock */ public function saveEntity($entity, $unlock = true) { $companyFieldMatches = []; $fields = $entity->getFields(); $updatedFields = $entity->getUpdatedFields(); $company = null; if (isset($updatedFields['company'])) { $companyFieldMatches['company'] = $updatedFields['company']; } //check to see if we can glean information from ip address if (!$entity->imported && count($ips = $entity->getIpAddresses())) { $details = $ips->first()->getIpDetails(); if (!empty($details['city']) && empty($fields['core']['city']['value'])) { $entity->addUpdatedField('city', $details['city']); $companyFieldMatches['city'] = $details['city']; } if (!empty($details['region']) && empty($fields['core']['state']['value'])) { $entity->addUpdatedField('state', $details['region']); $companyFieldMatches['state'] = $details['region']; } if (!empty($details['country']) && empty($fields['core']['country']['value'])) { $entity->addUpdatedField('country', $details['country']); $companyFieldMatches['country'] = $details['country']; } if (!empty($details['zipcode']) && empty($fields['core']['zipcode']['value'])) { $entity->addUpdatedField('zipcode', $details['zipcode']); } } if (!empty($companyFieldMatches)) { list($company, $leadAdded) = IdentifyCompanyHelper::identifyLeadsCompany($companyFieldMatches, $entity, $this->companyModel); if ($leadAdded) { $entity->addCompanyChangeLogEntry('form', 'Identify Company', 'Lead added to the company, ' . $company['companyname'], $company['id']); } unset($updatedFields['company']); } parent::saveEntity($entity, $unlock); if (!empty($company)) { // Save after the lead in for new leads created through the API and maybe other places $this->companyModel->addLeadToCompany($company['id'], $entity, true); } }