Skip to content

Commit aa3d531

Browse files
committed
Fix Lead issue.
1 parent 13341d1 commit aa3d531

File tree

4 files changed

+60
-7
lines changed

4 files changed

+60
-7
lines changed

packages/Webkul/Admin/src/Resources/views/components/attributes/edit/lookup.blade.php

+15-5
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,21 @@ class="text-2xl text-gray-600"
6565
</div>
6666
6767
<!-- Hidden Input Entity Value -->
68-
<input
69-
type="hidden"
70-
:name="attribute['code']"
71-
v-model="selectedItem.id"
72-
/>
68+
<template v-if="attribute['code'].includes('organization_id') && ! selectedItem.id">
69+
<input
70+
type="hidden"
71+
:name="attribute['code'].replace('organization_id', 'organization_name')"
72+
v-model="selectedItem.name"
73+
/>
74+
</template>
75+
76+
<template v-else>
77+
<input
78+
type="hidden"
79+
:name="attribute['code']"
80+
v-model="selectedItem.id"
81+
/>
82+
</template>
7383
7484
<!-- Popup Box -->
7585
<div

packages/Webkul/Admin/src/Resources/views/leads/create.blade.php

+6-2
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,10 @@ class="primary-button"
6666
6767
<div class="flex w-full gap-2 border-b border-gray-200 dark:border-gray-800">
6868
<!-- Tabs -->
69-
<template v-for="tab in tabs" :key="tab.id">
69+
<template
70+
v-for="tab in tabs"
71+
:key="tab.id"
72+
>
7073
{!! view_render_event('admin.leads.create.tabs.before') !!}
7174
7275
<a
@@ -79,7 +82,8 @@ class="primary-button"
7982
]"
8083
@click="scrollToSection(tab.id)"
8184
:text="tab.label"
82-
></a>
85+
>
86+
</a>
8387
8488
{!! view_render_event('admin.leads.create.tabs.after') !!}
8589
</template>

packages/Webkul/Contact/src/Repositories/PersonRepository.php

+35
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use Illuminate\Container\Container;
66
use Webkul\Attribute\Repositories\AttributeRepository;
77
use Webkul\Attribute\Repositories\AttributeValueRepository;
8+
use Webkul\Contact\Repositories\OrganizationRepository;
89
use Webkul\Contact\Contracts\Person;
910
use Webkul\Core\Eloquent\Repository;
1011

@@ -32,6 +33,7 @@ class PersonRepository extends Repository
3233
public function __construct(
3334
protected AttributeRepository $attributeRepository,
3435
protected AttributeValueRepository $attributeValueRepository,
36+
protected OrganizationRepository $organizationRepository,
3537
Container $container
3638
) {
3739
parent::__construct($container);
@@ -54,6 +56,14 @@ public function model()
5456
*/
5557
public function create(array $data)
5658
{
59+
if (isset($data['organization_name'])) {
60+
$organization = self::createOrganization($data);
61+
62+
$data['organization_id'] = $organization->id;
63+
64+
unset($data['organization_name']);
65+
}
66+
5767
if (isset($data['user_id'])) {
5868
$data['user_id'] = $data['user_id'] ?: null;
5969
}
@@ -76,6 +86,14 @@ public function update(array $data, $id, $attributes = [])
7686
{
7787
$data['user_id'] = empty($data['user_id']) ? null : $data['user_id'];
7888

89+
if (isset($data['organization_name'])) {
90+
$organization = self::createOrganization($data);
91+
92+
$data['organization_id'] = $organization->id;
93+
94+
unset($data['organization_name']);
95+
}
96+
7997
$person = parent::update($data, $id);
8098

8199
/**
@@ -118,4 +136,21 @@ public function getCustomerCount($startDate, $endDate)
118136
->get()
119137
->count();
120138
}
139+
140+
/**
141+
* Create a organization.
142+
*/
143+
public function createOrganization(array $data)
144+
{
145+
$userId = empty($data['user_id']) ? null : $data['user_id'];
146+
147+
return $this->organizationRepository->create(
148+
array_merge($data, [
149+
'name' => $data['organization_name'],
150+
'entity_type' => 'organization',
151+
'address' => [],
152+
'user_id' => $userId,
153+
])
154+
);
155+
}
121156
}

packages/Webkul/Lead/src/Repositories/LeadRepository.php

+4
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,10 @@ public function create(array $data)
122122
]));
123123
}
124124

125+
$data['person']['id'] = $person->id;
126+
127+
$data['person']['organization_id'] = $person->organization_id;
128+
125129
$lead = parent::create(array_merge([
126130
'person_id' => $person->id,
127131
'lead_pipeline_id' => 1,

0 commit comments

Comments
 (0)