商品图片(只是spu图片和sku图片)
This commit is contained in:
parent
e1949b330f
commit
78302f4591
|
|
@ -10,7 +10,7 @@ class Product extends Base
|
|||
use HasFactory;
|
||||
use SoftDeletes;
|
||||
|
||||
protected $fillable = ['image', 'video', 'position', 'active', 'variables'];
|
||||
protected $fillable = ['images', 'video', 'position', 'active', 'variables'];
|
||||
protected $attributes = [
|
||||
'image' => ''
|
||||
];
|
||||
|
|
@ -18,6 +18,7 @@ class Product extends Base
|
|||
'active' => 'boolean',
|
||||
'images' => 'array',
|
||||
'variables' => 'array',
|
||||
'images' => 'array',
|
||||
];
|
||||
|
||||
public function categories()
|
||||
|
|
|
|||
|
|
@ -8,10 +8,11 @@ class ProductSku extends Base
|
|||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $fillable = ['product_id', 'variants', 'position', 'image', 'model', 'sku', 'price', 'origin_price', 'cost_price', 'quantity', 'is_default'];
|
||||
protected $fillable = ['product_id', 'variants', 'position', 'images', 'model', 'sku', 'price', 'origin_price', 'cost_price', 'quantity', 'is_default'];
|
||||
|
||||
protected $casts = [
|
||||
'variants' => 'array',
|
||||
'images' => 'array',
|
||||
];
|
||||
|
||||
public function product()
|
||||
|
|
|
|||
|
|
@ -141,5 +141,10 @@ class CustomerRepo
|
|||
|
||||
return $customer->wishlists()->with('product.description')->paginate(20);
|
||||
}
|
||||
|
||||
public static function inWishlist($product, $customer)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@
|
|||
|
||||
namespace Beike\Shop\Http\Resources;
|
||||
|
||||
use Beike\Repositories\CustomerRepo;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class ProductDetail extends JsonResource
|
||||
|
|
@ -24,10 +25,13 @@ class ProductDetail extends JsonResource
|
|||
'id' => $this->id,
|
||||
'name' => $this->description->name ?? '',
|
||||
'description' => $this->description->description ?? '',
|
||||
'image' => image_resize($this->image),
|
||||
'images' => array_map(function ($image) {
|
||||
return image_resize($image);
|
||||
}, $this->images ?? []),
|
||||
'category_id' => $this->category_id ?? null,
|
||||
'variables' => $this->decodeVariables($this->variables),
|
||||
'skus' => SkuDetail::collection($this->skus)->jsonSerialize(),
|
||||
'in_wishlist' => CustomerRepo::inWishlist($this, current_customer()),
|
||||
];
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ class ProductList extends JsonResource
|
|||
'url' => shop_route('products.show', ['product' => $this]),
|
||||
'price' => $this->price,
|
||||
'origin_price' => $this->origin_price,
|
||||
'image' => image_resize($this->image),
|
||||
'images' => image_resize($this->images[0] ?? ''),
|
||||
'price_format' => currency_format($this->price),
|
||||
'category_id' => $this->category_id ?? null,
|
||||
];
|
||||
|
|
|
|||
|
|
@ -21,7 +21,9 @@ class SkuDetail extends JsonResource
|
|||
'id' => $this->id,
|
||||
'variants' => $this->variants,
|
||||
'position' => $this->position,
|
||||
'image' => image_resize('catalog' . $this->image, 600, 600),
|
||||
'image' => array_map(function ($image) {
|
||||
return image_resize($image, 600, 600);
|
||||
}, $this->images ?? []),
|
||||
'model' => $this->model,
|
||||
'sku' => $this->sku,
|
||||
'price' => $this->price,
|
||||
|
|
|
|||
|
|
@ -0,0 +1,42 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class CreateProductImages extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('products', function (Blueprint $table) {
|
||||
$table->dropColumn('image');
|
||||
$table->json('images')->nullable();
|
||||
});
|
||||
Schema::table('product_skus', function (Blueprint $table) {
|
||||
$table->dropColumn('image');
|
||||
$table->json('images')->nullable();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('products', function (Blueprint $table) {
|
||||
$table->dropColumn('images');
|
||||
$table->string('image')->default('');
|
||||
});
|
||||
Schema::table('product_skus', function (Blueprint $table) {
|
||||
$table->dropColumn('images');
|
||||
$table->string('image')->default('');
|
||||
});
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue