store product import
parent
ced19dc09b
commit
8fcfc148e9
|
|
@ -104,40 +104,43 @@ class StoreProduct
|
|||
'stock' => $stock,
|
||||
]);
|
||||
|
||||
$product = ProductSpu::updateOrCreate(['name' => $goods['name']],$goods);
|
||||
|
||||
// 属性规格
|
||||
if ($rowAttrs) {
|
||||
$format_specs = $this->formatAttr($rowAttrs);
|
||||
$format_attrs = $this->formatAttr($rowSpecs);
|
||||
$spec_group = $this->getSpec($goodsName, $rowAttrs, $rowSpecs);
|
||||
|
||||
$attrs = [];
|
||||
foreach($spec_group->attrs as $index => $item) {
|
||||
$attr = ['name' => $item['title'], 'attrs' => []];
|
||||
foreach(explode(PHP_EOL, $item['value']) as $value) {
|
||||
array_push($attr['attrs'], ['name' => $value, 'value' => data_get($format_attrs, "$index.values.$value")]);
|
||||
$product = ProductSpu::where('name', $goods['name'])->first();
|
||||
if (!$product) {
|
||||
$product = ProductSpu::create($goods);
|
||||
// 属性规格
|
||||
if ($rowAttrs) {
|
||||
$format_specs = $this->formatAttr($rowAttrs);
|
||||
$format_attrs = $this->formatAttr($rowSpecs);
|
||||
$spec_group = $this->getSpec($goodsName, $rowAttrs, $rowSpecs);
|
||||
|
||||
$attrs = [];
|
||||
foreach($spec_group->attrs as $index => $item) {
|
||||
$attr = ['name' => $item['title'], 'attrs' => []];
|
||||
foreach(explode(PHP_EOL, $item['value']) as $value) {
|
||||
array_push($attr['attrs'], ['name' => $value, 'value' => data_get($format_attrs, "$index.values.$value")]);
|
||||
}
|
||||
array_push($attrs, $attr);
|
||||
}
|
||||
array_push($attrs, $attr);
|
||||
}
|
||||
$product->update(['attrs' => $attrs]);
|
||||
|
||||
$specs = [];
|
||||
$product->specs()->delete();
|
||||
foreach($spec_group->specs as $index => $item) {
|
||||
$spec = ['name' => $item['title'], 'items' => []];
|
||||
foreach(explode(PHP_EOL, $item['value']) as $value) {
|
||||
array_push($spec['items'], ['name' => $value, 'value' => data_get($format_specs, "$index.values.$value")]);
|
||||
$product->update(['attrs' => $attrs]);
|
||||
|
||||
$specs = [];
|
||||
$product->specs()->delete();
|
||||
foreach($spec_group->specs as $index => $item) {
|
||||
$spec = ['name' => $item['title'], 'items' => []];
|
||||
foreach(explode(PHP_EOL, $item['value']) as $value) {
|
||||
array_push($spec['items'], ['name' => $value, 'value' => data_get($format_specs, "$index.values.$value")]);
|
||||
}
|
||||
array_push($specs, $spec);
|
||||
}
|
||||
array_push($specs, $spec);
|
||||
$product->specs()->createMany($specs);
|
||||
|
||||
// 更新 sku
|
||||
ProductSku::createBySpu($product);
|
||||
}
|
||||
$product->specs()->createMany($specs);
|
||||
}
|
||||
|
||||
// 清空现有的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,8 +18,8 @@ class ArticleResource extends JsonResource
|
|||
'id' => $this->id,
|
||||
'title' => $this->title,
|
||||
'cover' => $this->cover,
|
||||
'subtitle' => $this->subtitle,
|
||||
'content'=>$this->content,
|
||||
'subtitle' => $this->subtitle ?: '',
|
||||
'content'=> $this->content,
|
||||
'points'=> $this->points,
|
||||
'likes' => $this->likes,
|
||||
'like_status' => $this->whenLoaded('likesInfo', function () {
|
||||
|
|
|
|||
Loading…
Reference in New Issue