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