parent
216bf84a2c
commit
d0aeeb522b
|
|
@ -13,6 +13,7 @@ namespace Beike\Admin\Repositories;
|
|||
|
||||
use Beike\Models\Attribute;
|
||||
use Beike\Models\AttributeValue;
|
||||
use Beike\Models\ProductAttribute;
|
||||
|
||||
class AttributeRepo
|
||||
{
|
||||
|
|
@ -107,6 +108,10 @@ class AttributeRepo
|
|||
|
||||
public static function delete($id)
|
||||
{
|
||||
$productIds = ProductAttribute::query()->where('attribute_id', $id)->pluck('product_id')->toArray();
|
||||
if ($productIds) {
|
||||
throw New \Exception(trans('admin/attribute.error_cannot_delete_product_used', ['product_ids' => implode(', ', $productIds)]));
|
||||
}
|
||||
$attribute = Attribute::query()->findOrFail($id);
|
||||
$attribute->descriptions()->delete();
|
||||
$attribute->values()->delete();
|
||||
|
|
|
|||
|
|
@ -14,6 +14,11 @@ namespace Beike\Repositories;
|
|||
use Beike\Models\Attribute;
|
||||
use Beike\Models\AttributeValue;
|
||||
use Beike\Models\Product;
|
||||
use Beike\Models\ProductAttribute;
|
||||
use Beike\Models\ProductCategory;
|
||||
use Beike\Models\ProductDescription;
|
||||
use Beike\Models\ProductRelation;
|
||||
use Beike\Models\ProductSku;
|
||||
use Beike\Shop\Http\Resources\ProductSimple;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
|
|
@ -370,6 +375,16 @@ class ProductRepo
|
|||
|
||||
public static function forceDeleteTrashed()
|
||||
{
|
||||
Product::onlyTrashed()->forceDelete();
|
||||
$products = Product::onlyTrashed();
|
||||
|
||||
$productsIds = $products->pluck('id')->toArray();
|
||||
|
||||
ProductRelation::query()->whereIn('product_id', $productsIds)->orWhere('relation_id', $productsIds)->delete();
|
||||
ProductAttribute::query()->whereIn('product_id', $productsIds)->delete();
|
||||
ProductCategory::query()->whereIn('product_id', $productsIds)->delete();
|
||||
ProductSku::query()->whereIn('product_id', $productsIds)->delete();
|
||||
ProductDescription::query()->whereIn('product_id', $productsIds)->delete();
|
||||
|
||||
$products->forceDelete();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,4 +20,5 @@ return [
|
|||
'btn_at' => 'Go now',
|
||||
'btn_later' => 'Later',
|
||||
'to_info_values' => 'Please go to the details page to edit attribute values',
|
||||
'error_cannot_delete_product_used' => 'Attribute used by products (ID: :product_ids), can not be deleted!'
|
||||
];
|
||||
|
|
|
|||
|
|
@ -12,5 +12,5 @@
|
|||
return [
|
||||
'index' => 'Attribute group',
|
||||
'create_at_groups' => 'Create attribute group',
|
||||
'error_cannot_delete_attribute_used' => 'Attribute Group used by attribute (ID: attributes), can not be deleted!'
|
||||
'error_cannot_delete_attribute_used' => 'Attribute Group used by attribute (ID: :attributes), can not be deleted!'
|
||||
];
|
||||
|
|
|
|||
|
|
@ -20,4 +20,5 @@ return [
|
|||
'btn_at' => '立即前往',
|
||||
'btn_later' => '稍后再去',
|
||||
'to_info_values' => '请前往详情页编辑属性值',
|
||||
'error_cannot_delete_product_used' => '属性不能删除,由于该属性被商品(商品ID: :product_ids)使用'
|
||||
];
|
||||
|
|
|
|||
Loading…
Reference in New Issue