移除商品 SPU 中无效的方法
parent
4901ee6f16
commit
df8f56ef6f
|
|
@ -66,31 +66,4 @@ class ProductSpu extends Model
|
||||||
{
|
{
|
||||||
return $this->skus()->exists();
|
return $this->skus()->exists();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 确认给定的 SKU 是否有效
|
|
||||||
*
|
|
||||||
* @param \App\Models\ProductSku $sku
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
public function isValidProductSku(ProductSku $sku): bool
|
|
||||||
{
|
|
||||||
if ($this->getKey() !== $sku->spu_id) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (count($specs = (array) $sku->specs) === $this->specs->count()) {
|
|
||||||
foreach ($this->specs as $spec) {
|
|
||||||
$key = $spec->getKey();
|
|
||||||
|
|
||||||
if (! array_key_exists($key, $specs) || ! in_array($specs[$key], $spec->items)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue