Skip to content

Commit

Permalink
Merge pull request #890 from bakaphp/hotfix-module-config-type
Browse files Browse the repository at this point in the history
refact: hotfix agent integartion
  • Loading branch information
kaioken authored Feb 5, 2024
2 parents b33d61c + c3c784b commit 7e1d7ad
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 7 deletions.
3 changes: 3 additions & 0 deletions src/Domains/Connectors/Zoho/Enums/CustomFieldEnum.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,14 @@ enum CustomFieldEnum: string
case REFRESH_TOKEN = 'ZOHO_REFRESH_TOKEN';
case ZOHO_LEAD_ID = 'ZOHO_LEAD_ID';
case DEFAULT_OWNER = 'ZOHO_DEFAULT_OWNER';
case ZOHO_DEFAULT_LEAD_SOURCE = 'ZOHO_DEFAULT_LEAD_SOURCE';
case FIELDS_MAP = 'ZOHO_FIELDS_MAP';
case ZOHO_MEMBER_FIELD = 'ZOHO_MEMBER_FIELD';
case ZOHO_USER_OWNER_ID = 'ZOHO_USER_OWNER_ID';
case ZOHO_USER_OWNER_MEMBER_NUMBER = 'ZOHO_USER_OWNER_MEMBER_NUMBER';
case ZOHO_STATUS_NAME = 'ZOHO_STATUS_NAME';
case ZOHO_HAS_AGENTS_MODULE = 'ZOHO_HAS_AGENTS_MODULE';
case ZOHO_AGENT_MODULE = 'ZOHO_AGENT_MODULE';
case ZOHO_LEAD_SYNC_FILES = 'ZOHO_LEAD_SYNC_FILES';
case ZOHO_DEFAULT_LANDING_PAGE = 'ZOHO_DEFAULT_LANDING_PAGE';
}
4 changes: 4 additions & 0 deletions src/Domains/Connectors/Zoho/Workflows/ZohoAgentActivity.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ public function execute(Model $user, AppInterface $app, array $params): array
], $agentUpdateData);
$user->set('member_number_' . $company->getId(), $memberNumber);

if ($company->get(CustomFieldEnum::ZOHO_DEFAULT_LANDING_PAGE->value)) {
$user->set('landing_page', $company->get(CustomFieldEnum::ZOHO_DEFAULT_LANDING_PAGE->value));
}

return [
'member_id' => $memberNumber,
'zohoId' => $zohoId,
Expand Down
14 changes: 10 additions & 4 deletions src/Domains/Connectors/Zoho/Workflows/ZohoLeadActivity.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
use Kanvas\Connectors\Zoho\ZohoService;
use Kanvas\Guild\Agents\Models\Agent;
use Kanvas\Guild\Leads\Models\Lead;
use Kanvas\SystemModules\Repositories\SystemModulesRepository;
use Kanvas\Workflow\Contracts\WorkflowActivityInterface;
use Throwable;
use Webleit\ZohoCrmApi\Modules\Leads as ZohoLeadModule;
Expand Down Expand Up @@ -62,7 +61,7 @@ public function execute(Model $lead, AppInterface $app, array $params): array
return [
'zohoLeadId' => $zohoLeadId,
'zohoRequest' => $zohoData,
'leadId' => $lead->getId()
'leadId' => $lead->getId(),
];
}

Expand All @@ -80,8 +79,8 @@ protected function assignAgent(
}

if (! empty($memberNumber)) {
$zohoData['Member_ID'] = $memberNumber;
//$zohoData['Member'] = $memberNumber;
$zohoMemberField = $company->get(CustomFieldEnum::ZOHO_MEMBER_FIELD->value) ?? 'Member_ID';
$zohoData[$zohoMemberField] = $memberNumber;
}

$zohoService = new ZohoService($app, $company);
Expand All @@ -98,6 +97,11 @@ protected function assignAgent(
$agentInfo = null;
}

$defaultLeadSource = $company->get(CustomFieldEnum::ZOHO_DEFAULT_LEAD_SOURCE->value);
if (! empty($defaultLeadSource)) {
$zohoData['Lead_Source'] = $defaultLeadSource;
}

if ($agent && $agent->count()) {
$agent = $agent->first();
$zohoData['Owner'] = (int) $agent->Owner['id'];
Expand All @@ -122,6 +126,8 @@ protected function assignAgent(
}
}



//if value is 0 or empty, remove it
if (empty($zohoData['Owner'])) {
unset($zohoData['Owner']);
Expand Down
2 changes: 1 addition & 1 deletion src/Domains/Connectors/Zoho/ZohoService.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public function createAgent(UserInterface $user, Agent $agentInfo, ?object $zoho
'Email' => $user->email,
'Member_Number' => $agentInfo->getMemberNumber(),
'Sponsor' => ! empty($agentInfo->owner_id) ? (string) $agentInfo->owner_id : '1001',
'Owner' => ! empty($agentInfo->owner_linked_source_id) ? (int) $agentInfo->owner_linked_source_id : $this->company->get('default_owner'),
'Owner' => ! empty($agentInfo->owner_linked_source_id) ? (int) $agentInfo->owner_linked_source_id : $this->company->get(CustomFieldEnum::DEFAULT_OWNER->value),
'Account_Type' => 'Standard',
'Name' => $agentInfo->name,
'Office_Phone' => '',
Expand Down
4 changes: 2 additions & 2 deletions src/Kanvas/Notifications/Models/NotificationTypes.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,14 +95,14 @@ public function getPushTemplateName(): string
*/
public function hasEmailTemplate(): bool
{
$templateName = $this->template()->exists() ? $this->template()->get()->name : $this->template;
$templateName = $this->template()->exists() ? $this->template()->first()->name : $this->template;

return ! empty($templateName);
}

public function getTemplateName(): string
{
$templateName = $this->template()->exists() ? $this->template()->get()->name : $this->template;
$templateName = $this->template()->exists() ? $this->template()->first()->name : $this->template;

if (empty($templateName)) {
throw new ModelNotFoundException('This notification type does not have an email template');
Expand Down

0 comments on commit 7e1d7ad

Please sign in to comment.