store product import
parent
ced19dc09b
commit
8fcfc148e9
|
|
@ -104,40 +104,43 @@ 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) {
|
// 属性规格
|
||||||
$format_specs = $this->formatAttr($rowAttrs);
|
if ($rowAttrs) {
|
||||||
$format_attrs = $this->formatAttr($rowSpecs);
|
$format_specs = $this->formatAttr($rowAttrs);
|
||||||
$spec_group = $this->getSpec($goodsName, $rowAttrs, $rowSpecs);
|
$format_attrs = $this->formatAttr($rowSpecs);
|
||||||
|
$spec_group = $this->getSpec($goodsName, $rowAttrs, $rowSpecs);
|
||||||
$attrs = [];
|
|
||||||
foreach($spec_group->attrs as $index => $item) {
|
$attrs = [];
|
||||||
$attr = ['name' => $item['title'], 'attrs' => []];
|
foreach($spec_group->attrs as $index => $item) {
|
||||||
foreach(explode(PHP_EOL, $item['value']) as $value) {
|
$attr = ['name' => $item['title'], 'attrs' => []];
|
||||||
array_push($attr['attrs'], ['name' => $value, 'value' => data_get($format_attrs, "$index.values.$value")]);
|
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]);
|
||||||
}
|
|
||||||
$product->update(['attrs' => $attrs]);
|
$specs = [];
|
||||||
|
$product->specs()->delete();
|
||||||
$specs = [];
|
foreach($spec_group->specs as $index => $item) {
|
||||||
$product->specs()->delete();
|
$spec = ['name' => $item['title'], 'items' => []];
|
||||||
foreach($spec_group->specs as $index => $item) {
|
foreach(explode(PHP_EOL, $item['value']) as $value) {
|
||||||
$spec = ['name' => $item['title'], 'items' => []];
|
array_push($spec['items'], ['name' => $value, 'value' => data_get($format_specs, "$index.values.$value")]);
|
||||||
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, 重新添加
|
// 清空现有的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