!75 编辑商品时重量为空保存报错

* 代码规范化
* Fix the issue of saving error when editing product weight is empty.
* 高级筛选哪些属性显示在筛选栏可在后台系统设置里设置
This commit is contained in:
mengwb 2023-04-07 08:42:56 +00:00 committed by Edward Yang
parent 11626a73af
commit e1e3ee9568
6 changed files with 55 additions and 2 deletions

View File

@ -30,15 +30,20 @@ class SettingController extends Controller
{
$themes = ThemeRepo::getAllThemes();
$tax_address = [
$taxAddress = [
['value' => 'shipping', 'label' => trans('admin/setting.shipping_address')],
['value' => 'payment', 'label' => trans('admin/setting.payment_address')],
];
$multiFilter = system_setting('base.multi_filter');
if ($attributeIds = $multiFilter['attribute'] ?? []) {
$multiFilter['attribute'] = AttributeRepo::getByIds($attributeIds);
}
$data = [
'countries' => CountryRepo::listEnabled(),
'currencies' => CurrencyRepo::listEnabled(),
'tax_address' => $tax_address,
'multi_filter' => $multiFilter,
'tax_address' => $taxAddress,
'customer_groups' => CustomerGroupDetail::collection(CustomerGroupRepo::list())->jsonSerialize(),
'themes' => $themes,
];

View File

@ -27,6 +27,7 @@ class ProductService
DB::beginTransaction();
$data['brand_id'] = (int) $data['brand_id'];
$data['weight'] = (float) $data['weight'];
$data['variables'] = json_decode($data['variables']);
$product->fill($data);
$product->updated_at = now();

View File

@ -206,6 +206,11 @@ class ProductRepo
->whereNotNull('pa.attribute_id')
->distinct()
->reorder('pa.attribute_id');
if ($attributesIds = system_setting('base.multi_filter', [])['attribute'] ?? []) {
$builder->whereIn('pa.attribute_id', $attributesIds);
}
$productAttributes = $builder->get()->toArray();
$attributeMap = array_column(Attribute::query()->with('description')->orderBy('sort_order')->get()->toArray(), null, 'id');

View File

@ -113,6 +113,42 @@
</div>
<div class="tab-pane fade" id="tab-attribute">
<x-admin::form.row title="__('admin/setting.multi_filter')">
<div class="module-edit-group wp-600">
<div class="autocomplete-group-wrapper">
<el-autocomplete
class="inline-input"
v-model="attributes.keyword"
value-key="name"
size="small"
:fetch-suggestions="(keyword, cb) => {attributesQuerySearch(keyword, cb, 'products')}"
placeholder="{{ __('admin/builder.modules_keywords_search') }}"
@select="(e) => {handleSelect(e, 'product_attributes')}"
></el-autocomplete>
<div class="item-group-wrapper" v-loading="attributes.loading">
<template v-if="attributes.multi_filter.attribute.length">
<div v-for="(item, index) in attributes.multi_filter.attribute" :key="index" class="item">
<div>
<i class="el-icon-s-unfold"></i>
<span>@{{ item.name }}</span>
</div>
<i class="el-icon-delete right" @click="attributesRemoveProduct(index)"></i>
<input type="text" :name="'multi_filter[attribute]['+ index +']'" v-model="item.id" class="form-control d-none">
</div>
</template>
<template v-else>
{{ __('admin/setting.please_select') }}
<input type="text" name="multi_filter" value="" class="form-control d-none">
</template>
</div>
</div>
</div>
<div class="help-text font-size-12 lh-base">{{ __('admin/builder.multi_filter_helper') }}</div>
</x-admin::form.row>
</div>
<div class="tab-pane fade" id="tab-express-company">
@hook('admin.setting.express.before')
<x-admin::form.row title="{{ __('order.express_company') }}">

View File

@ -71,4 +71,7 @@ return [
'head_code' => 'Insert code',
'head_code_info' => 'The code in the input box will be inserted into the head of the front-end page, which can be used to count the code or add special plug-ins, etc',
'rate_api_key' => 'Exchange rate API KEY',
'multi_filter' => 'Multi Filter',
'please_select' => 'Please select',
'multi_filter_helper' => 'Please select the attributes to be displayed in the Multi Filter module.',
];

View File

@ -69,4 +69,7 @@ return [
'head_code' => '插入代码',
'head_code_info' => '会将输入框中的代码插入到前端页面 head 中,可用于统计代码或者添加特殊插件等',
'rate_api_key' => '汇率 API KEY',
'multi_filter' => '高级筛选',
'please_select' => '请添加',
'multi_filter_helper' => '请选择需要在筛选模块显示的属性',
];