修复产品图片不存在 系统报错

This commit is contained in:
Edward Yang 2022-10-31 14:32:21 +08:00
parent 171b1a4b05
commit 14be551526
3 changed files with 6 additions and 12 deletions

View File

@ -12,6 +12,7 @@ class ProductResource extends JsonResource
* *
* @param Request $request * @param Request $request
* @return array * @return array
* @throws \Exception
*/ */
public function toArray($request): array public function toArray($request): array
{ {
@ -20,7 +21,7 @@ class ProductResource extends JsonResource
$data = [ $data = [
'id' => $this->id, 'id' => $this->id,
'images' => array_map(function ($image) { 'images' => array_map(function ($image) {
return thumbnail($image); return image_resize($image);
}, $this->images ?? []), }, $this->images ?? []),
'name' => $this->description->name ?? '', 'name' => $this->description->name ?? '',
'price_formatted' => currency_format($masterSku->price), 'price_formatted' => currency_format($masterSku->price),

View File

@ -266,17 +266,6 @@ function current_customer(): ?Customer
return auth()->guard(Customer::AUTH_GUARD)->user(); return auth()->guard(Customer::AUTH_GUARD)->user();
} }
/**
* 获取缩略图
*
* @param $path
* @return string
*/
function thumbnail($path): string
{
return $path;
}
/** /**
* 获取语言列表 * 获取语言列表
* *

View File

@ -29,6 +29,10 @@ class ImageService
{ {
$this->image = $image ?: self::PLACEHOLDER_IMAGE; $this->image = $image ?: self::PLACEHOLDER_IMAGE;
$this->imagePath = public_path($this->image); $this->imagePath = public_path($this->image);
if (!file_exists($this->imagePath)) {
$this->image = self::PLACEHOLDER_IMAGE;
$this->imagePath = public_path($this->image);
}
} }