Skip to content

Commit

Permalink
feat: refactor configuration keys for improved structure and clarity
Browse files Browse the repository at this point in the history
  • Loading branch information
amit-webkul committed Jan 28, 2025
1 parent 5562621 commit 017ca6b
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 35 deletions.
20 changes: 10 additions & 10 deletions packages/Webkul/Admin/src/Config/core_config.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
'icon' => 'icon-configuration',
'sort' => 1,
], [
'key' => 'general.settings.header_offer',
'key' => 'general.settings.footer',
'name' => 'Powered by Section Configurations',
'info' => 'We can configure the powered by section here',
'sort' => 1,
Expand Down Expand Up @@ -113,37 +113,37 @@
'default' => 'Quotes',
'validation' => 'max:20',
], [
'name' => 'mail',
'name' => 'mail.mail',
'title' => 'Mail',
'type' => 'text',
'default' => 'Mail',
'validation' => 'max:20',
], [
'name' => 'mail_inbox',
'name' => 'mail.inbox',
'title' => 'Inbox',
'type' => 'text',
'default' => 'Inbox',
'validation' => 'max:20',
], [
'name' => 'mail_draft',
'name' => 'mail.draft',
'title' => 'Draft',
'type' => 'text',
'default' => 'Draft',
'validation' => 'max:20',
], [
'name' => 'mail_outbox',
'name' => 'mail.outbox',
'title' => 'Outbox',
'type' => 'text',
'default' => 'Outbox',
'validation' => 'max:20',
], [
'name' => 'mail_sent',
'name' => 'mail.sent',
'title' => 'Sent',
'type' => 'text',
'default' => 'Sent',
'validation' => 'max:20',
], [
'name' => 'mail_trash',
'name' => 'mail.trash',
'title' => 'Trash',
'type' => 'text',
'default' => 'Trash',
Expand All @@ -155,19 +155,19 @@
'default' => 'Activities',
'validation' => 'max:20',
], [
'name' => 'contacts',
'name' => 'contacts.contacts',
'title' => 'Contacts',
'type' => 'text',
'default' => 'Contacts',
'validation' => 'max:20',
], [
'name' => 'contact_persons',
'name' => 'contacts.persons',
'title' => 'Persons',
'type' => 'text',
'default' => 'Persons',
'validation' => 'max:20',
], [
'name' => 'contact_organizations',
'name' => 'contacts.organizations',
'title' => 'Organizations',
'type' => 'text',
'default' => 'Organizations',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class="absolute top-0 hidden flex-col bg-gray-100 ltr:left-[200px] rtl:right-[19
class="flex gap-2.5 p-2 items-center cursor-pointer hover:rounded-lg {{ $subMenuItem->isActive() == 'active' ? 'bg-brandColor rounded-lg' : ' hover:bg-gray-100 hover:dark:bg-gray-950' }} peer"
>
<p class="text-gray-600 dark:text-gray-300 font-medium whitespace-nowrap {{ $subMenuItem->isActive() ? 'text-white' : ''}}">
{{ $subMenuItem->getName() }}
{{ core()->getConfigData('general.settings.menu.'.$subMenuItem->getKey()) ?? $subMenuItem->getName() }}
</p>
</a>
</div>
Expand Down
81 changes: 57 additions & 24 deletions packages/Webkul/Core/src/Repositories/CoreConfigRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,45 +101,78 @@ public function create(array $data): void
{
unset($data['_token']);

$preparedData = [];

foreach ($data as $method => $fieldData) {
$recursiveData = $this->recursiveArray($fieldData, $method);

foreach ($recursiveData as $fieldName => $value) {
if (
gettype($value) == 'array'
&& ! isset($value['delete'])
is_array($value)
&& isset($value['delete'])
) {
$value = implode(',', $value);
}
$coreConfigValues = $this->model->where('code', $fieldName)->get();

if ($coreConfigValues->isNotEmpty()) {
foreach ($coreConfigValues as $coreConfig) {
if (! empty($coreConfig['value'])) {
Storage::delete($coreConfig['value']);
}

$coreConfigValue = $this->model
->where('code', $fieldName)
->get();
parent::delete($coreConfig['id']);
}
}

if (request()->hasFile($fieldName)) {
$value = request()->file($fieldName)->store('configuration');
continue;
}
}

if (! count($coreConfigValue)) {
parent::create([
'code' => $fieldName,
'value' => $value,
]);
} else {
foreach ($coreConfigValue as $coreConfig) {
if (request()->hasFile($fieldName)) {
Storage::delete($coreConfig['value']);
foreach ($recursiveData as $fieldName => $value) {
if (is_array($value)) {
foreach ($value as $key => $val) {
$fieldNameWithKey = $fieldName.'.'.$key;

$coreConfigValues = $this->model->where('code', $fieldNameWithKey)->get();

if (request()->hasFile($fieldNameWithKey)) {
$val = request()->file($fieldNameWithKey)->store('configuration');
}

if (isset($value['delete'])) {
parent::delete($coreConfig['id']);
if ($coreConfigValues->isNotEmpty()) {
foreach ($coreConfigValues as $coreConfig) {
if (request()->hasFile($fieldNameWithKey)) {
Storage::delete($coreConfig['value']);
}

parent::update(['code' => $fieldNameWithKey, 'value' => $val], $coreConfig->id);
}
} else {
parent::update([
'code' => $fieldName,
'value' => $value,
], $coreConfig->id);
parent::create(['code' => $fieldNameWithKey, 'value' => $val]);
}
}
} else {
if (request()->hasFile($fieldName)) {
$value = request()->file($fieldName)->store('configuration');
}

$preparedData[] = [
'code' => $fieldName,
'value' => $value,
];
}
}
}

if (! empty($preparedData)) {
foreach ($preparedData as $dataItem) {
$coreConfigValues = $this->model->where('code', $dataItem['code'])->get();

if ($coreConfigValues->isNotEmpty()) {
foreach ($coreConfigValues as $coreConfig) {
parent::update($dataItem, $coreConfig->id);
}
} else {
parent::create($dataItem);
}
}
}
Expand Down

0 comments on commit 017ca6b

Please sign in to comment.