Skip to content

Commit

Permalink
Issue bagisto#9814 fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
jitendra-webkul committed May 20, 2024
1 parent 748b8d6 commit 2e2e46a
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 106 deletions.
14 changes: 2 additions & 12 deletions UPGRADE.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ There is no dependency needed to be updated at for this upgrade.
+ core()->getConfigData('sales.taxes.default_destination_calculation.postcode')
```

2: The `repository` option has been removed from the `select` type field in the system configuration. Now, you can use `options` as a closure to populate select field options from the database. Here's an example of how to update the configuration array:
2: The `repository` option has been replaced with `options`. Now, you can use `options` as shown below to populate select field options from the database.

```diff
'key' => 'sales.taxes.categories',
Expand All @@ -103,20 +103,10 @@ There is no dependency needed to be updated at for this upgrade.
'type' => 'select',
'default' => 0,
- 'repository' => '\Webkul\Tax\Repositories\TaxCategoryRepository@getConfigOptions',
+ 'options' => function() {
+ return [
+ [
+ 'title' => 'admin::app.configuration.index.sales.taxes.categories.none',
+ 'value' => 0,
+ ],
+ ];
+ }
+ ]
+ 'options' => '\Webkul\Tax\Repositories\TaxCategoryRepository@getConfigOptions',
}
```

In this example, the `repository` option has been replaced with `options`, which is defined as a closure returning an array of options. Adjust the closure to populate the select field options as needed.

3. The Inventory Stock Options configuration has been relocated to the Order Settings configuration, and the respective path for retrieving configuration values has been updated accordingly

```diff
Expand Down
55 changes: 11 additions & 44 deletions packages/Webkul/Admin/src/Config/system.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<?php

use Webkul\Sales\Models\Order;
use Webkul\Tax\Repositories\TaxCategoryRepository;

return [
/**
Expand Down Expand Up @@ -1659,49 +1658,17 @@
'sort' => 1,
'fields' => [
[
'name' => 'shipping',
'title' => 'admin::app.configuration.index.sales.taxes.categories.shipping',
'type' => 'select',
'default' => 0,
'options' => function () {
$options = [
[
'title' => 'admin::app.configuration.index.sales.taxes.categories.none',
'value' => 0,
],
];

foreach (app(TaxCategoryRepository::class)->all() as $taxCategory) {
$options[] = [
'title' => $taxCategory->name,
'value' => $taxCategory->id,
];
}

return $options;
},
], [
'name' => 'product',
'title' => 'admin::app.configuration.index.sales.taxes.categories.product',
'type' => 'select',
'default' => 0,
'options' => function () {
$options = [
[
'title' => 'admin::app.configuration.index.sales.taxes.categories.none',
'value' => 0,
],
];

foreach (app(TaxCategoryRepository::class)->all() as $taxCategory) {
$options[] = [
'title' => $taxCategory->name,
'value' => $taxCategory->id,
];
}

return $options;
},
'name' => 'shipping',
'title' => 'admin::app.configuration.index.sales.taxes.categories.shipping',
'type' => 'select',
'default' => 0,
'options' => 'Webkul\Tax\Repositories\TaxCategoryRepository@getConfigOptions',
], [
'name' => 'product',
'title' => 'admin::app.configuration.index.sales.taxes.categories.product',
'type' => 'select',
'default' => 0,
'options' => 'Webkul\Tax\Repositories\TaxCategoryRepository@getConfigOptions',
],
],
], [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
$field = collect([
...$field,
'isVisible' => true,
])->map(function ($value, $key) {
])->map(function ($value, $key) use($coreConfigRepository) {
if ($key == 'options') {
return collect(is_callable($value) ? $value() : $value)->map(fn ($option) => [
return collect($coreConfigRepository->getOptions($value))->map(fn ($option) => [
'title' => trans($option['title']),
'value' => $option['value'],
])->toArray();
Expand Down Expand Up @@ -297,7 +297,7 @@ class="cursor-pointer !text-sm !font-semibold !text-gray-600 dark:!text-gray-300
v-if="value"
:href="`{{ route('admin.configuration.download', [request()->route('slug'), request()->route('slug2'), '']) }}/${value.split('/')[1]}`"
>
<div class="inline-flex w-full max-w-max cursor-pointer appearance-none items-center justify-between gap-x-1 mb-1 rounded-md border border-transparent p-1.5 text-center text-gray-600 transition-all marker:shadow hover:bg-gray-200 active:border-gray-300 dark:text-gray-300 dark:hover:bg-gray-800">
<div class="mb-1 inline-flex w-full max-w-max cursor-pointer appearance-none items-center justify-between gap-x-1 rounded-md border border-transparent p-1.5 text-center text-gray-600 transition-all marker:shadow hover:bg-gray-200 active:border-gray-300 dark:text-gray-300 dark:hover:bg-gray-800">
<i class="icon-down-stat text-2xl"></i>
</div>
</a>
Expand Down
66 changes: 19 additions & 47 deletions packages/Webkul/Core/src/Traits/CoreConfigField.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace Webkul\Core\Traits;

use Illuminate\Support\Str;

trait CoreConfigField
{
/**
Expand Down Expand Up @@ -47,53 +49,6 @@ public function getValidations($field)
return $field['validation'];
}

/**
* Get dependent field or value based on arguments.
*
* @param array $field
* @param string $fieldOrValue
* @return string
*/
public function getDependentFieldOrValue($field, $fieldOrValue = 'field')
{
$depends = explode(':', $field['depends']);

return $fieldOrValue === 'field'
? current($depends) : end($depends);
}

/**
* Get dependent field options.
*
* @param array $field
* @param array $dependentValues
* @return mixed
*/
public function getDependentFieldOptions($field, $dependentValues)
{
if (
empty($field['options'])
|| ! $dependentValues
) {
return '';
}

$options = [];

if (is_callable($dependentValues)) {
$dependentValues = $dependentValues();
}

foreach ($dependentValues as $key => $result) {
$options[] = [
'title' => $result,
'value' => $key,
];
}

return $options;
}

/**
* Get channel/locale indicator for form fields. So, that form fields can be detected,
* whether it is channel based or locale based or both.
Expand All @@ -117,4 +72,21 @@ public function getChannelLocaleInfo($field, $channel, $locale)

return ! empty($info) ? '['.implode(' - ', $info).']' : '';
}

/**
* Returns the select options for the field.
*
* @param array|string $options
* @return mixed
*/
public function getOptions($options)
{
if (is_array($options)) {
return $options;
}

[$class, $method] = Str::parseCallback($options);

return app($class)->$method();
}
}
22 changes: 22 additions & 0 deletions packages/Webkul/Tax/src/Repositories/TaxCategoryRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,26 @@ public function model(): string
{
return 'Webkul\Tax\Contracts\TaxCategory';
}

/**
* Get the configuration options.
*/
public function getConfigOptions(): array
{
$options = [
[
'title' => 'admin::app.configuration.index.sales.taxes.categories.none',
'value' => 0,
],
];

foreach ($this->all() as $taxCategory) {
$options[] = [
'title' => $taxCategory->name,
'value' => $taxCategory->id,
];
}

return $options;
}
}

0 comments on commit 2e2e46a

Please sign in to comment.