6
0
Fork 0

移除商品 SPU 中无效的方法

release
李静 2021-12-10 10:45:46 +08:00
parent 4901ee6f16
commit df8f56ef6f
1 changed files with 0 additions and 27 deletions

View File

@ -66,31 +66,4 @@ class ProductSpu extends Model
{
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;
}
}