优化:增加计量单位并且在商品组件和商品详情中显示。支持多语言

This commit is contained in:
wuhui_zzw 2023-09-20 14:49:44 +08:00
parent 2e36e35e17
commit 19df41c8d4
9 changed files with 46 additions and 30 deletions

View File

@ -8,5 +8,5 @@ class ProductDescription extends Base
{
use HasFactory;
protected $fillable = ['locale', 'name', 'content', 'meta_title', 'meta_description', 'meta_keywords'];
protected $fillable = ['locale', 'name', 'content', 'meta_title', 'meta_description', 'meta_keywords', 'unit'];
}

View File

@ -26,7 +26,9 @@ class CartDetail extends JsonResource
};
$skuCode = $sku->sku;
$description = $product->description;
$productName = $description->name;
$unit = $description->unit ?? '';
$subTotal = $price * $this->quantity;
$image = $sku->image ?: $product->image;
@ -37,6 +39,8 @@ class CartDetail extends JsonResource
'product_sku' => $skuCode,
'name' => $productName,
'name_format' => sub_string($productName),
'unit' => $unit,
'unit_format' => $unit,
'image' => $image,
'image_url' => image_resize($image),
'quantity' => $this->quantity,

View File

@ -34,6 +34,7 @@ class ProductDetail extends JsonResource
return [
'id' => $this->id,
'name' => $this->description->name ?? '',
'unit' => $this->description->unit ?? '',
'description' => $this->description->content ?? '',
'meta_title' => $this->description->meta_title ?? '',
'meta_keywords' => $this->description->meta_keywords ?? '',

View File

@ -31,6 +31,7 @@ class ProductSimple extends JsonResource
}
$name = $this->description->name ?? '';
$unit = $this->description->unit ?? '';
$images = $this->images != NULL ? $this->images : [];
$data = [
@ -38,6 +39,8 @@ class ProductSimple extends JsonResource
'sku_id' => $masterSku->id,
'name' => $name,
'name_format' => $name,
'unit' => $unit,
'unit_format' => $unit,
'url' => $this->url,
'price' => $masterSku->price,
'origin_price' => $masterSku->origin_price,

View File

@ -136,7 +136,9 @@
</div>
</x-admin::form.row>
{{--<x-admin-form-switch-status name="active" :title="__('common.status')" :value="old('active', $product->active ?? 1)" v-model="editing.isVariable" />--}}
{{--计量单位--}}
<x-admin-form-input-locale :width="600" name="descriptions.*.unit" title="{{ __('product.unit_of_measurement') }}" :value="$descriptions" :required="true" />
{{--状态--}}
<x-admin::form.row title="{{ __('common.status') }}">
<div class="mb-1 mt-2">
<div class="form-check form-check-inline">
@ -149,11 +151,6 @@
</div>
</div>
</x-admin::form.row>
@hook('admin.product.edit.extra')
<div>

View File

@ -29,5 +29,6 @@ return [
'inactive' => 'Inactive',
'has_been_inactive' => 'The product has been inactive',
'minimum_order' => 'Min Order',
'minimum_order_error' => 'The purchase quantity must be greater than or equal to :num'
'minimum_order_error' => 'The purchase quantity must be greater than or equal to :num',
'unit_of_measurement' => 'Unit of measurement'
];

View File

@ -30,5 +30,6 @@ return [
'inactive' => '下架',
'has_been_inactive' => '该商品已下架',
'minimum_order' => '起订量',
'minimum_order_error' => '采购数量必须大于等于:num'
'minimum_order_error' => '采购数量必须大于等于:num',
'unit_of_measurement' => '计量单位'
];

View File

@ -203,7 +203,7 @@
<div class="stock-and-sku mb-4">
@hookwrapper('product.detail.quantity')
<div class="d-flex">
<span class="title text-muted">{{ __('product.quantity') }}:</span>
<span class="title text-muted">{{ __('product.quantity') }}</span>
<div :class="product.quantity > 0 ? 'text-success' : 'text-secondary'">
<template v-if="product.quantity > 0">@{{ product.quantity }}</template>
<template v-else>@{{ product.quantity }}</template>
@ -214,7 +214,7 @@
@if ($product['brand_id'])
@hookwrapper('product.detail.brand')
<div class="d-flex">
<span class="title text-muted">{{ __('product.brand') }}:</span>
<span class="title text-muted">{{ __('product.brand') }}</span>
<a href="{{ shop_route('brands.show', $product['brand_id']) }}">{{ $product['brand_name'] }}</a>
</div>
@endhookwrapper
@ -222,17 +222,25 @@
@hookwrapper('product.detail.sku')
<div class="d-flex" v-if="product.sku">
<span class="title text-muted">SKU:</span>@{{ product.sku }}
<span class="title text-muted">SKU</span>@{{ product.sku }}
</div>
@endhookwrapper
@hookwrapper('product.detail.model')
<div class="d-flex" v-if="product.model"><span class="title text-muted">{{ __('shop/products.model') }}:</span> @{{ product.model }}</div>
<div class="d-flex" v-if="product.model"><span class="title text-muted">{{ __('shop/products.model') }}</span> @{{ product.model }}</div>
@endhookwrapper
<div v-if="minimum_order > 0" class="d-flex" >
<span class="title text-muted">{{__('product.minimum_order')}}:</span> @{{ minimum_order }}
<span class="title text-muted" style="width: auto!important;">{{__('product.minimum_order')}}</span> @{{ minimum_order }}
</div>
@if(!empty($product['unit']))
<div class="d-flex">
<span class="title text-muted" style="width: auto!important;">{{__('product.unit_of_measurement')}}</span> {{ $product['unit'] }}
</div>
@endif
</div>
@if (0)
<div class="rating-wrap d-flex">
@ -873,13 +881,6 @@
params.products_country_id = _this.country_id;
params.change_logistics_id = _this.change_logistics_id;
console.log(_this.minimum_order);
return false;
// 提交内容
bk.addCart(params, null, () => {
if (isIframe) {

View File

@ -66,17 +66,25 @@
<span>-</span>
<span class="price-new">{{ $product['price_format'] }}</span>
@endif
<span style="color:#aaa">/pieces</span>
@if(!empty($product['unit_format']))
<span style="color:#aaa">/{{ $product['unit_format'] }}</span>
@endif
</div>
<!--yt修改-->
<div class="product-price">
@if ($product['price_setting'] === 'num')
<span class="price-new">{{$product['numprices'] != [] ? $product['numprices'][0]['num'] : 1}} pieces</span>
@else
<span class="price-new">{{$product['minimum_order'] ?? 0}} pieces</span>
@endif
<span style="color:#aaa;margin-left:4px">({{__('admin/product.minimum_order')}})</span>
</div>
@if ((int)$product['minimum_order'] > 0 || ($product['numprices'] != [] ? $product['numprices'][0]['num'] : 0) > 0)
<div class="product-price">
@if ($product['price_setting'] === 'num')
<span class="price-new">{{$product['numprices'] != [] ? $product['numprices'][0]['num'] : 1}} {{ $product['unit_format'] ?? '' }}</span>
@else
<span class="price-new">{{$product['minimum_order'] ?? 0}} {{ $product['unit_format'] ?? '' }}</span>
@endif
<span style="color:#aaa;margin-left:4px">({{__('admin/product.minimum_order')}})</span>
</div>
@endif
@if (request('style_list') == 'list')
<div class="button-wrap mt-3">