store product import
parent
ced19dc09b
commit
8fcfc148e9
|
|
@ -104,8 +104,9 @@ class StoreProduct
|
||||||
'stock' => $stock,
|
'stock' => $stock,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$product = ProductSpu::updateOrCreate(['name' => $goods['name']],$goods);
|
$product = ProductSpu::where('name', $goods['name'])->first();
|
||||||
|
if (!$product) {
|
||||||
|
$product = ProductSpu::create($goods);
|
||||||
// 属性规格
|
// 属性规格
|
||||||
if ($rowAttrs) {
|
if ($rowAttrs) {
|
||||||
$format_specs = $this->formatAttr($rowAttrs);
|
$format_specs = $this->formatAttr($rowAttrs);
|
||||||
|
|
@ -132,12 +133,14 @@ class StoreProduct
|
||||||
array_push($specs, $spec);
|
array_push($specs, $spec);
|
||||||
}
|
}
|
||||||
$product->specs()->createMany($specs);
|
$product->specs()->createMany($specs);
|
||||||
|
|
||||||
|
// 更新 sku
|
||||||
|
ProductSku::createBySpu($product);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 清空现有的sku, 重新添加
|
// 清空现有的sku, 重新添加
|
||||||
StoreProductSku::where('store_id', $store->id)->whereIn('product_sku_id', $product->skus->pluck('id'))->delete();
|
StoreProductSku::where('product_spu_id', $product->id)->where('store_id', $store->id)->delete();
|
||||||
$product->skus()->delete();
|
|
||||||
ProductSku::createBySpu($product);
|
|
||||||
|
|
||||||
// 将sku 添加到门店
|
// 将sku 添加到门店
|
||||||
$skuList = $product->skus()->get();
|
$skuList = $product->skus()->get();
|
||||||
|
|
|
||||||
|
|
@ -18,8 +18,8 @@ class ArticleResource extends JsonResource
|
||||||
'id' => $this->id,
|
'id' => $this->id,
|
||||||
'title' => $this->title,
|
'title' => $this->title,
|
||||||
'cover' => $this->cover,
|
'cover' => $this->cover,
|
||||||
'subtitle' => $this->subtitle,
|
'subtitle' => $this->subtitle ?: '',
|
||||||
'content'=>$this->content,
|
'content'=> $this->content,
|
||||||
'points'=> $this->points,
|
'points'=> $this->points,
|
||||||
'likes' => $this->likes,
|
'likes' => $this->likes,
|
||||||
'like_status' => $this->whenLoaded('likesInfo', function () {
|
'like_status' => $this->whenLoaded('likesInfo', function () {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue